5

I have a solution with 2 projects cira_lib and md5_test. One project (cira_lib) is a central library that compiles to a DLL. The other project (md5_test) is an exe with a dependency on cira_lib. When I build md5_test it builds cira_lib first, so I know the project dependencies are being followed. However when VC++ comes to linking md5_test it comes back with a linker error:

1>  win32_cira.vcxproj -> C:\Users\ale-xps\Documents\Visual Studio 2010\Projects\win32_cira\Release\cira_lib.dll
2>------ Rebuild All started: Project: md5_test, Configuration: Release Win32 ------
2>  MD5Test.cpp
2>MD5Test.obj : error LNK2001: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl getTimeChkSum(void)" (?getTimeChkSum@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
2>C:\Users\ale-xps\Documents\Visual Studio 2010\Projects\win32_cira\Release\md5_test.exe : fatal error LNK1120: 1 unresolved externals

The "unresolved external symbol" that you see is a function in one of the class files "Utils.cpp" in the cira_lib project. So it seems to me that Visual Studio needs me me to perform some additional steps in order to see the Object files from cira_lib? I thought that by making a "dependency" all that would be automatically taken care for me?

I want md5_test to dynamically link against cira_lib... but I think Microsoft requires you to at least link against a stub .LIB file at link time even if you're performing dynamic linking, is that correct?

So do I need to add cira_lib's Release directory to md5_test's "Library Directories" and add cira_lib.lib to md5_test's "Linker Input" ?

The header file that I'm exporting is the following

 __declspec( dllexport ) string getTimeChkSum( );

and the implementation file is

__declspec(dllexport)
string  getTimeChkSum( )
{...}

Even after adding these directives and rebuilding all, my exe project still can't see these symbols..

svick
  • 236,525
  • 50
  • 385
  • 514
alessandro ferrucci
  • 1,261
  • 2
  • 24
  • 48
  • 1
    "Rebuild all". Why don't we see cira_lib getting built? – Hans Passant Sep 06 '10 at 17:56
  • Sorry I did not include that snippet, but it does indeed rebuild cira_lib – alessandro ferrucci Sep 06 '10 at 19:14
  • Answer here: http://stackoverflow.com/questions/2704576/did-visual-studio-2010-break-project-dependencies-between-c-projects and here: http://stackoverflow.com/questions/3795567/visual-studio-2010-not-autolinking-static-libraries-from-projects-that-are-depend – Martin Ba Oct 07 '11 at 06:42

1 Answers1

2

Only symbols that you specifically mark for export are available to executables linking against your DLL.

You should check the MSDN documentation

Seb Rose
  • 3,628
  • 18
  • 29
  • I have changed my header file to __declspec( dllexport ) string getTimeChkSum( ); , implementation file to __declspec(dllexport) //check sum created from a time in milliseconds string getTimeChkSum( ){...} I rebuilt all, and I still get the same error message.. 2>MD5Test.obj : error LNK2001: unresolved external symbol "class std::basic_string,class std::allocator > __cdecl getTimeChkSum(void)" 2>C:\Users\ale-xps\Documents\Visual Studio 2010\Projects\win32_cira\Release\md5_test.exe : fatal error LNK1120: 1 unresolved externals – alessandro ferrucci Sep 06 '10 at 19:12
  • Also note, I don't know if I need to do anything special, my cira_lib project was created through "empty project", not one of the other "fancier" project types. – alessandro ferrucci Sep 06 '10 at 19:15
  • 1
    I have specifically added cira_lib's Release directory and cira_lib.lib to the linker's input settings and the linker error for md5_test went away... – alessandro ferrucci Sep 06 '10 at 19:46
  • You should not need to explicitly add the cira_lib path to get it building properly. Without seeing your project (vcproj) and solution (sln) files it's difficult to know quite what went wrong. – Seb Rose Sep 07 '10 at 07:36