views:

511

answers:

4

This is a Windows Console application (actually a service) that a previous guy built 4 years ago and is installed and running. I now need to make some changes but can't even build the current version! Here is the build output:

--------------------Configuration: MyApp - Win32 Debug--------------------
Compiling resources...
Compiling...
Main.cpp
winsock.cpp
Linking...
LINK : warning LNK4098: defaultlib "LIBCMTD" conflicts with use of other libs; use /NODEFAULTLIB:library
Main.obj : error LNK2001: unresolved external symbol _socket_dontblock
Debug/MyApp.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

MyApp.exe - 2 error(s), 1 warning(s)
--------------------------------------------------------------------------

If I use /NODEFAULTLIB then I get loads of errors. The code does not actually use _socket_noblock but I can't find anything on it on the 'net. Presumably it is used by some library I am linking to but I don't know what library it is in.

--- Alistair.

+1  A: 

You can use "Dependency Walker" - a free tool to find the dependencies of your application, to figure out how your application is linking to libcmtd. Edit: You can't, of course, use that on the new version which fails to link (see comments), but you can use it on the old version, or on known libraries that the new version links with.

However, as the real problem was unrelated to anything I suggested, perhaps the question should be closed.

It looks like you are linking to different versions of the CRT - possibly because you are using old built libraries together with a new compiler and version of the CRT.

MadKeithV
Uhh... how do you use dependency walker on an application which fails to LINK?
atzz
1. On the old version of the application that did work.2. On the individual dependencies of the new version, if necessary.But your point is valid, I did have the new version in mind when I wrote it, which is rather dumb as it *didn't* link.
MadKeithV
+1  A: 

Sorry, this turns out to be an internal problem. A combination of a maverick coder 4 years ago and a rusty no-nothing (me!) now.

The code does not use _socket_noblock but it does use socket_noblock and I just need to link to one of our own libraries.

+3  A: 

LNK4098 may not be a problem. For example, it can occur if you link against a release version of some library which uses static runtime linkage and causes LIBCMT (note the absense of "D" suffix) to be added to default libraries. Your application, being built in Debug config, uses LIBCMT**D**, thus the conflict. It may be actually safe, provided that you are not exchanging anything runtime-dependant with that library.

As for _socket_noblock, you can use some search utility (such as grep or find) to search for this string in .obj and .lib files. This way you will know which library references the symbol, which may be a starting point for discovering what dependencies that library has.

atzz
A: 

defaultlib "LIBCMTD" conflicts with use of other libs is a warning that indicates that your program uses a different version of the run time library that one or more of your libraries. Use the same runtime across the program and libraries, to make the warning go away.

(project settings) (c++ tab) category (Code Generation) (use runtime library)

EvilTeach