FATAL link ERROR LNK1169 and LNK2005 is a COMMON ERROR ...
RE: FlightGear build problems ... during the link, got items like :-
FlightGear error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
FlightGear error LNK2005: __errno already defined in LIBCMT.lib(dosmap.obj)
... more of the same type ...
FlightGear fatal error LNK1169: one or more multiply defined symbols found
FlightGear warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
FlightGear is made up of SEVERAL STATIC LIBRARY projects, PLIB, zlib (comes with), SimGear, and then, FlightGear itself, ... This error occurs when one, or more, of these projects has been compiled, and linked, using a DIFFERENT 'Runtime Library' ...
As the warning LNK4098 states "defaultlib 'MSVCRT' conflicts with use of other libs", namely 'LIBCMT' given in LNK2005 error ... 'already defined' ... leading to LNK1169 ... multiple defined ... 'MSVCRT' is the default single-threaded library, and 'LIBCMT' is the multi-threaded library ...
It MAY be possible to do as the warning SUGGESTS, namely to use /NODEFAULTLIB:MSVCRT ... you can NOT use just /NODEFAULTLIB, since this EXCLUDES ALL default libraries, and as you saw you get hundreds of link errors ... you can TRY excluding the single default library, BUT I HAVE NEVER GOT THIS TO WORK!
The best course of action is to GO BACK through each of the projects in turn and CHECK which 'Runtime Library' is being used for each ... this can be tedious and boring, I know ;=)) you have to load MSVC with each project in turn, missing none ...
In MSVC6, choose menu item [ Project ], select [ Settings... ], and in
the 'Project Settings' dialog, select the C/C++ tab, and choose 'Category:'
'Code Generation' ... you will see you can choose the 'Runtime Library' from a
dropdown list -
- Single-Threaded * (this is the default)
- Multithreaded DLL
- Debug Single-Threaded
- Debug Multithreaded
- Debug Multithreaded DLL
In MSVC7.1, choose menu item [ Project ], select [ project Properties
... ], and in the 'project Property Pages' dialog, expand the C/C++ folder, and
select 'Code Generation' in the left column ... in the right, you will see you
can choose the 'Runtime Library' from a dropdown list -
- Multi-threaded (/MT)
- Multi-threaded Debug (/MTd)
- Multi-threaded DLL (/MD)
- Multi-threaded DLL Debug (/MDd)
- Single-threaded (/ML)
- Single-threaded Debug (/MLd)
- <Inherit from project defaults>
Although we, in WIN32, do NOT commonly use the multi-threaded version of FlightGear, it requires installing another pthreads DLL, and more! ... I ALWAYS, repeat always, FOR ALL PROJECTS, all!, choose 'Multithreaded' ... Of course, that is 'Multi-threaded Debug (/MTd)' for the DEBUG configuration, and 'Multi-threaded (/MT)' for the RELEASE configuration ...
Note that for the PLIB projects, this requires that you select EACH INDIVIDUAL sub-project, 'fnt', 'js', 'net', 'psl', 'puAux', etc, separately. That is, each listed, except the 'plib' item, which is only a library reference ... and CHECK each one in turn ...
This is not so important for projects that are included as Dynamic Link Libraries (DLL), since only the headers of functions are included in the link, and the main code is only loaded at runtime ... like OpenAL (sound library), but I still always try to be CONSISTENT throughout ...
As stated, this is one of the MOST COMMON errors, since it requires a LOT OF TEDIOUS MANUAL CLICKING AND CHECKING ;=)) to be done BEFORE starting the compile and link of each ...
When ALL projects are using the SAME runtime, this problem will evaporate ...
Hope this helps ... good luck ... happy sim flying ...
Saturday, 19 November 2005.
PS: 22 November, 2005 - It seems I should STRESS using the SAME 'runtime' ... that does NOT mean just choosing a 'generic idea' like 'Multithreaded' ... there are two(2) forms of 'Multithreaded' ... /MT[d] and /MD[d] ... THESE ARE NOT THE SAME! ...
The single, only reason for this CONFLICT - LNK2005, leading to LNK1169, and invoking the warning LNK4098 - is that some project, or individual file, in a project, INCLUDED IN THE LINK, is COMPILED and LINKED not using the SAME runtime!!!
As an EXAMPLE, I recompiled the SINGLE file in PLIB, fnt.cxx, using 'Multithreaded DLL (/MD)', whereas the main project, and other dependant project were compiled using 'Multithreaded (/MT)', and I get a problem, when LINKING FG -
MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
.\Release/FlightGear.exe : fatal error LNK1169: one or more multiply defined symbols found
So it is NOT just a question of 'multithreaded' or not, but choosing 'Multithreaded DLL (/MD)' ALSO creates this problem, if elsewhere you have chosen 'Multithreaded (/MT)' ... YOU MUST USE THE SAME RUNTIME THROUGHOUT - I changed the properties of fnt.cxx back to /MT, compile and link PLIB, then for the link of FG, and I get success -
------ Build started: Project: FlightGear, Configuration: Release Win32
Build log was saved at "file://c:\Fg099\FlightGear\source\Release\BuildLog.htm"
FlightGear - 0 error(s), 0 warning(s)
---------------------- Done ----------------------
Build: 1 succeeded, 0 failed, 0 skipped
Simple CONSISTENCY ;=))