Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ project compiles as static library but not dynamic (Visual Studio)

I'm a little new to c++ in visual studio, and I'm trying to compile a massive C++ project with Visual Studio. I've gone through and added all source and header files to my project and also updated all of the include paths in the project properties.

If I have the type of project set to "Static Library (.Lib)" the project will compile without error and I'll have a nice fatty .lib file.

If I change the project over to a "Dynamic Library (.dll)" The project no longer compiles and fails on linking errors.

Here's an example of one:

Error   27  error LNK2001: unresolved external symbol "char const * __cdecl Project::toString(enum Project::compMode)" (?toString@Project@@$$FYAPBDW4compMode@1@@Z) H:\repo.project\user\tool\component.obj tool

Any help or background on what might be happening here?

like image 278
Nick Avatar asked Sep 09 '25 23:09

Nick


1 Answers

Check if you defined the following member function

char const* Project::toString(Project::compMode)

When you compile as a static library an unresolved symbol is not an error, because it can be resolved later when you link with other code.

You may have forgotten to add some .cpp file to your project.

like image 117
vitaut Avatar answered Sep 12 '25 12:09

vitaut