Question

I've made a static library project and I added it to the solution that has a project which uses the library.

I included the class I needed from it in the main project like I would with another static library but it throws these errors:

error LNK2019: unresolved external symbol "public: __thiscall NetworkingLib::Base::Base(void)" (??0Base@NetworkingLib@@QAE@XZ) referenced in function _SDL_main
error LNK2019: unresolved external symbol "public: void __thiscall NetworkingLib::Base::Connect(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?Connect@Base@NetworkingLib@@QAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z) referenced in function _SDL_main

I have no idea what is going wrong. I checked with another project that uses a library in the same way and I can't find any differences. Any help detecting the problem?

The class NetworkingLib::Base has a method I want to use. So what I did in the main project is:

#include "../NetworkLibrary/Base.h"

NetworkingLib::Base *m_pNetworkObj;
m_pNetworkObj = new NetworkingLib::Base();
m_pNetworkObj->Connect("localhost", "80");

I don't think there's anything wrong with this so the problem must be elsewhere.

Was it helpful?

Solution

It's not enough to have the static library in the same solution. You have to pass it to the linker of the project that uses it.

In Visual Studio, the best way to do this is by adding a "Project Reference". This sets up the dependency so that the projects build in the correct order, and also picks the version of the static library matching the consuming project, be that Debug vs Release, x86 vs x64, etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top