c++linkervisual-studio-6

how to avoid "already defined error" in C++


I am gettings these type of errors in a MFC VS6 project while linking the application:

msvcrt.lib(MSVCRT.dll) : error LNK2005: _atoi already defined in LIBC.lib(atox.obj)

I know what it means (a function exists in 2 different libraries); to solve it I should have to exclude one of the 2 libraries (msvcrt.lib or libc.lib).

But if I do this there are all kinds of unresolved external errors. So I would like to keep using both libraries.

Is there any way to tell the linker that I want to use the _atoi function in libc.lib and not in msvcrt.lib (or the other way around)?

Any help or direction would be great.


Solution

  • There seems to be an option which you can use to ignore errors like this: in projectsettings > link > check 'Force file output'. This will generate the program even if there are linkerrors.

    The Build output gives something like this:

    msvcrt.lib(MSVCRT.dll) : warning LNK4006: _atoi already defined in LIBC.lib(atox.obj); second definition ignored

    Of course you will need to use this option with care as it can generate an application which won't work in some cases, but here it probably doesn't do any harm (I hope).

    Thank you for the other replies, but that didn't seem to be an option in my particular case.