c++static-linking

How to configure my libraries and dependencies to compile my App as static


I am Programming an App with visual studio 2022, in c++, x64 with libraries installed with help of vcpkg. They are dynamic link libraries.

I want to use my App as static, to run it in another PC without need to install frameworks, or make an installer, or other dependencies, just one .exe and that´s it. Maybe is called "Portable"?

My AI asistent says that I should first change to Release, and change Code generation option to "/MT"

I do it and I started to experiment Linking problems, of course because my libraries are configured as dynamic. But...

Is that exactly the problem that I have in this message?, or do I have more? I can really not understand the Message.

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2001 unresolved external symbol "__declspec(dllimport) public: class std::locale __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::getloc(void)const " (__imp_?getloc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QEBA?AVlocale@2@XZ)    WxWidgets_Structured    C:\Users\Juan\source\repos\WxWidgets_Structured\ConfigManager.obj   1   
Error   LNK1120 1 unresolved externals  WxWidgets_Structured    C:\Users\Juan\source\repos\WxWidgets_Structured\x64\Release\WxWidgets_Structured.exe    1   

Solution

  • As soon as you want to use something that you get through a DLL you cannot build a statically built program. Full stop.

    Possible ways: