Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get LNK4098 conflicts with use of other libs - when trying to compile C++ in MSVS2010 Express?

My program will not successfully compile in /MT (MultiThreaded) mode. It Compiles in /MD (MultiThreaded DLL). I want to be able to use both libcurl and boost in an application I will distribute with an installer.

Compiling in: MSVS2010

This is code to replicate my problem:

#include "stdafx.h"
#include "boost/regex.hpp"
#include "curl/curl.h"

int _tmain(int argc, _TCHAR* argv[])
{
    CURL *curl;  
    curl = curl_easy_init();  
    return 0;
}

This is the warning I get if in /MD mode:

LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; 
use /NODEFAULTLIB:library

If I try compiling in /MT mode I get:

1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _calloc already defined in 

LIBCMT.lib(calloc.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _realloc already defined in LIBCMT.lib(realloc.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _free already defined in LIBCMT.lib(free.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _malloc already defined in LIBCMT.lib(malloc.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _strtoul already defined in LIBCMT.lib(strtol.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _memmove already defined in LIBCMT.lib(memmove.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _tolower already defined in LIBCMT.lib(tolower.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _strtol already defined in LIBCMT.lib(strtol.obj)
...
: fatal error LNK1169: one or more multiply defined symbols found

I want to compile in /MT mode so that others can run my finished program with out having MSVS installed or needing to download anything additional. I can include and dll or lib files needed by my app in the installer.

I could disable loading the 'MSVCRTD' default library, but then compiling the with boost fails.

These are my preprocessor definitions:

WIN32
_DEBUG
_CONSOLE
BUILDING_LIBCURL
HTTP_ONLY

These are my additional dependencies:

libcurl.lib
ws2_32.lib
winmm.lib
wldap32.lib

Does anyone know what I am doing wrong?

Thanks, William

like image 918
William Whispell Avatar asked Apr 30 '11 03:04

William Whispell


1 Answers

Try setting nodefaultlib:libcmt.lib in linker options in VC.

like image 150
Eric Z Avatar answered Nov 14 '22 22:11

Eric Z