views:

2529

answers:

4

I'm getting a whole bunch of linker errors in Visual studios for methods I'm not even calling directly. I'm a java developer by day, but I have a project I need to do in C++, intended to run on windows machines. Hence, I'm stuck messing about with Visual Studio.

Bascally, I have an os project that I added an accessor method to. I compiled that project as a .lib file (compiles and links fine).

I then have my own project that uses that lib. I've included the library under Project->Properties -> Linker -> Input, and set the appropriate directory in the General -> Additional Lib Directories. I've included the header in the appropriate file, and I'm simply calling the constructor of one of the classes...not even calling the method that I created yet.

The code compiles, but I get the following mountain of linker errors -- mostly LNK2019 and LNK2001 errors. I've tried recompiling under different settings (lib, exe, etc.), and the linker errors only seem to multiply. When I switch back to the previous settings, the number of errors remain at their peak. Any ideas how to fix this?

Build Log

Build started: Project: SpamCapture, Configuration: Debug|Win32

Command Lines

Creating temporary file "c:\SpamCapture\SpamCapture\SpamCapture\Debug\RSP0000103081740.rsp" with contents [ /VERBOSE:LIB /OUT:"C:\SpamCapture\SpamCapture\SpamCapture\Debug\SpamCapture.exe" /INCREMENTAL /LIBPATH:"C:\SpamCapture\Config\Debug\" /MANIFEST /MANIFESTFILE:"Debug\SpamCapture.exe.intermediate.manifest" /NODEFAULTLIB:"libcmtd.lib" /NODEFAULTLIB:"nafxcwd.lib" /DEBUG /PDB:"c:\SpamCapture\SpamCapture\SpamCapture\Debug\SpamCapture.pdb" /SUBSYSTEM:CONSOLE /MACHINE:X86 KeyCapture_Config.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

".\Debug\Interaction.obj"

".\Debug\InteractionSet.obj"

".\Debug\LogReader.obj"

".\Debug\SpamCapture.obj"

".\Debug\stdafx.obj"

".\Debug\SpamCapture.res"

".\Debug\SpamCapture.exe.embed.manifest.res" ] Creating command line "link.exe @c:\SpamCapture\SpamCapture\SpamCapture\Debug\RSP0000103081740.rsp /NOLOGO /ERRORREPORT:PROMPT"

Output Window

Linking... LINK : warning LNK4067: ambiguous entry point; selected 'mainCRTStartup' Searching libraries Searching C:\SpamCapture\Config\Debug\KeyCapture_Config.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\lib\kernel32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\user32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\gdi32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\winspool.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\comdlg32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\advapi32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\shell32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\ole32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\oleaut32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\lib\uuid.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\odbc32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\odbccp32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\lib\msvcprtd.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\lib\MSVCRTD.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\lib\OLDNAMES.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\lib\mfc80ud.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\lib\mfcs80ud.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\msimg32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\comctl32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\shlwapi.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\lib\atlsd.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\wininet.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\ws2_32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\mswsock.lib: Searching C:\SpamCapture\Config\Debug\KeyCapture_Config.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\lib\kernel32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\user32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\gdi32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\winspool.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\comdlg32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\advapi32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\shell32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\ole32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\oleaut32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\lib\uuid.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\odbc32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\odbccp32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\lib\msvcprtd.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\lib\MSVCRTD.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\lib\OLDNAMES.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\lib\mfc80ud.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\lib\mfcs80ud.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\msimg32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\comctl32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\shlwapi.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\lib\atlsd.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\wininet.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\ws2_32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\mswsock.lib: Searching C:\SpamCapture\Config\Debug\KeyCapture_Config.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\lib\kernel32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\user32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\gdi32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\winspool.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\comdlg32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\advapi32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\shell32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\ole32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\oleaut32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\lib\uuid.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\odbc32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib\odbccp32.lib: Searching C:\Program Files\Microsoft Visual Studio 8\VC\lib\msvcprtd.lib: Finished searching libraries

Linker Errors start here:

KeyCapture_Config.lib(KeyCapture_ConfigDlg.obj) : error LNK2001: unresolved external symbol "public: virtual int __thiscall CWnd::Create(char const *,char const *,unsigned long,struct tagRECT const &,class CWnd *,unsigned int,struct CCreateContext *)" (?Create@CWnd@@UAEHPBD0KABUtagRECT@@PAV1@IPAUCCreateContext@@@Z)

... a bunch more like this

KeyCapture_Config.lib(KeyCapture_ConfigDlg.obj) : error LNK2019: unresolved external symbol "public: struct HICON__ * thiscall CWinApp::LoadIconA(unsigned int)const " (?LoadIconA@CWinApp@@QBEPAUHICON@@I@Z) referenced in function "public: __thiscall CKeyCapture_ConfigDlg::CKeyCapture_ConfigDlg(class CWnd *)" (??0CKeyCapture_ConfigDlg@@QAE@PAVCWnd@@@Z)

...a bunch more like this

(?DoDataExchange@SetupDialog@@MAEXPAVCDataExchange@@@Z) C:\SpamCapture\SpamCapture\SpamCapture\Debug\SpamCapture.exe : fatal error LNK1120: 34 unresolved externals

Results

Build log was saved at "file://c:\SpamCapture\SpamCapture\SpamCapture\Debug\BuildLog.htm" SpamCapture - 44 error(s), 1 warning(s)

+1  A: 

The link error seem to be complaining about the lack of a lot of MFC functions, and you link lines includes: /NODEFAULTLIB:"nafxcwd.lib" which would exclude MFC. Is the lib you are linking against built with MFC?

Other things to check are that you are compiling the app and the lib with the same character set (ie. both multibyte or both unicode).

When you are building a lib there is no link step, so an arbitrary collection of objects can be thrown into a lib without any regard for what else they might need.

Rob Walker
Actually, I set libcmtd.lib and nafxcwd.lib to ignore, as I was receiving a number of LNK2005 errors for those. See: error LNK2005: "public: virtual void __thiscall CWnd::PreSubclassWindow(void)" (?PreSubclassWindow@CWnd@@UAEXXZ) already defined in mfc80ud.lib(MFC80UD.DLL)
Gopherkhan
It is always helpful to understand what is the source of the link request for nafxcwd then. Why does the app think it needs to link it in -- as Scott says it sounds like the components are built will different CRT or MFC settings.
Rob Walker
A: 

It looks like your project is linking with the Debug Multithreaded runtime. Is this your intention? If so there may be inconsistencies with the KeyCapture_Config library that you seem to be using.

Is KeyCapture_Config a 3rd party library? If so did you build it from source or was the lib/dll provided for you?

It may just take some investigation on which C/C++ runtimes are being built against. You can reference the Microsoft KB Article that might help shed some light on the possible runtime build discrepancies.

Scott Saad
The actual Project I'm integrating with can be found here:http://dynamicnetservices.com/~will/academic/textinput/keycapture/Runtime Library is set to Multi-threaded Debug DLL (/MDd). Should I be doing this somewhere else?
Gopherkhan
thanks for the article link
Gopherkhan
A: 

I think that Rob Walker has nailed the problem. If the documentation for KeyCapture_Config.lib says no linkage to MFC, check the source for directives that require linkage to MFC. Something like this:

#pragma comment(lib, "nafxcwd.lib")

would cause a dependency on MFC, and the KeyCapture_Config.lib doc may be out of date.

rschuler
+5  A: 

The library KeyCapture_Config.lib is using MFC GUI classes (CWnd, CWinApp, etc), but the application you're linking it into is a console application (see the /SUBSYSTEM:CONSOLE option in your linker command line). This won't work. You should create a new MFC GUI application project and add the library to that project.

Edit: I've just checked the link in your comment: http://dynamicnetservices.com/~will/academic/textinput/keycapture/ and it seems that KeyCapture_Config is actually an MFC dialog application that uses the KeyCapture DLL. It may be possible to use KeyCapture in a console application by linking directly against KeyCapture.lib.

ChrisN