views:

37

answers:

1

Hi, 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..

Thank you very much,

Alessandro Ferrucci

+1  A: 

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

You should check the MSDN documentation

Seb Rose
I have changed my header file to __declspec( dllexport ) string getTimeChkSum( ); , implementation file to __declspec(dllexport)//check sum created from a time in millisecondsstring getTimeChkSum( ){...} I rebuilt all, and I still get the same error message.. 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)" 2>C:\Users\ale-xps\Documents\Visual Studio 2010\Projects\win32_cira\Release\md5_test.exe : fatal error LNK1120: 1 unresolved externals
alessandro ferrucci
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
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
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