Jump to content

[Solved] Plugin refuses to link to F4SE static library (C++)


Recommended Posts

Posted (edited)

Just getting into modding and F4SE, and after a couple hours of searching for how to get started I found this plugin example.
Spent some more hours getting it to build everything, but now I'm completely stuck on the f4se_example_plugin project refusing to link to the f4se_1_10_163 library, and instead just gives linker errors.

f4se_1_10_163.lib has been added to the Additional Dependencies list as with any other static library.

1>main.obj : error LNK2019: unresolved external symbol "void * __cdecl Heap_Allocate(unsigned __int64)" (?Heap_Allocate@@YAPEAX_K@Z) referenced in function "public: static void * __cdecl NativeFunctionBase::operator new(unsigned __int64)" (??2NativeFunctionBase@@SAPEAX_K@Z)
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl Heap_Free(void *)" (?Heap_Free@@YAXPEAX@Z) referenced in function "public: static void __cdecl NativeFunctionBase::operator delete(void *)" (??3NativeFunctionBase@@SAXPEAX@Z)
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl Console_Print(char const *,...)" (?Console_Print@@YAXPEBDZZ) referenced in function "void __cdecl Example_Plugin_Functions::Test(struct StaticFunctionTag *)" (?Test@Example_Plugin_Functions@@YAXPEAUStaticFunctionTag@@@Z)
1>main.obj : error LNK2019: unresolved external symbol "public: __cdecl StringCache::Ref::Ref(void)" (??0Ref@StringCache@@QEAA@XZ) referenced in function "public: __cdecl NativeFunctionBase::NativeFunctionBase(void)" (??0NativeFunctionBase@@QEAA@XZ)
1>main.obj : error LNK2019: unresolved external symbol "public: void __cdecl VMValue::SetNone(void)" (?SetNone@VMValue@@QEAAXXZ) referenced in function "public: virtual bool __cdecl NativeFunction0<struct StaticFunctionTag,void>::Run(class VMValue *,class VirtualMachine *,unsigned long,class VMValue *,class VMState *)" (?Run@?$NativeFunction0@UStaticFunctionTag@@X@@UEAA_NPEAVVMValue@@PEAVVirtualMachine@@K0PEAVVMState@@@Z)
1>main.obj : error LNK2019: unresolved external symbol "void * __cdecl UnpackHandle(class VMValue *,unsigned long)" (?UnpackHandle@@YAPEAXPEAVVMValue@@K@Z) referenced in function "void __cdecl UnpackValue<struct StaticFunctionTag>(struct StaticFunctionTag * *,class VMValue *)" (??$UnpackValue@UStaticFunctionTag@@@@YAXPEAPEAUStaticFunctionTag@@PEAVVMValue@@@Z)
1>main.obj : error LNK2019: unresolved external symbol "unsigned __int64 __cdecl GetTypeID<void>(class VirtualMachine *)" (??$GetTypeID@X@@YA_KPEAVVirtualMachine@@@Z) referenced in function "public: void __cdecl NativeFunction0<struct StaticFunctionTag,void>::InitParams(class VirtualMachine *)" (?InitParams@?$NativeFunction0@UStaticFunctionTag@@X@@QEAAXPEAVVirtualMachine@@@Z)

I have a fair bit of experience with C++ and why linker errors occur, but I'm stumped as to why it still won't link

If anybody has any idea on why this happens, or if there's a newer example project/setup guide that'll be greatly appreciated. Thanks.

 

Edit:
The f4se project was set to a dynamic library, but still created a static lib file. 
For future reference, make sure the configuration type is set to build a static library

Edited by SkeletonArgore
Link to comment
Share on other sites

Are you sure the f4se project has been compiled for static and not dynamic library? The linker gives errors of all function calls in main.cpp so the issue is probably somewhere in the projects. F4SE project is .dll by default. What other projects are present in the solution? Forced Include file is ../common/IPrefix.h (for convenience)? Do you use a Precompiled header?

Link to comment
Share on other sites

Posted (edited)
10 hours ago, SkeletonArgore said:

If anybody has any idea on why this happens, or if there's a newer example project/setup guide that'll be greatly appreciated. Thanks.

 

If you take a look to the folder with f4se_1_10_163.lib you can found also f4se_1_10_163.dll, that might give you a hint - it is for dynamic linking. 

Next step - take a look how f4se_1_10_163.dll is used at runtime. If you take a look to installation package, you found that f4se_1_10_163.dll is placed to the root folder of Fallout 4 game. Also, looking to the exporting functions table you found a single function only - StartF4SE. This might give you a hint - it is not about plugins, but about how F4SE is starting. By the way, f4se_1_10_163.lib has only single exporting function - StartF4SE. Surprised? %)

 

So you are looking to the wrong place. f4se_1_10_163.lib is not for your plugins. 

 

 

In order to build your plugin you can include necessary C++ files to your project. In your particular scenario the files are:

for Heap_Allocate, Heap_Free and Console_Print: GameAPI.cpp

for StringCache::Ref::Ref : GameTypes.cpp

for VMValue::SetNone: PapyrusValue.cpp

for UnpackHandle and GetTypeID: PapyrusArgs.cpp

 

You can take a look to my plugins (best example). Perhaps, they would give you a better start.

 

Edited by DlinnyLag
Link to comment
Share on other sites

On 5/16/2024 at 12:34 AM, LarannKiar said:

Are you sure the f4se project has been compiled for static and not dynamic library? ... F4SE project is .dll by default

Yeah... The F4SE project was set to a dynamic library. 
In hindsight this should've been the first thing I checked, having done this stuff who knows how many times

In any case that did it, Thanks!

Now I just need to make a premake config for it all

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...