How to use /NODEFAULTLIBS option in compilation?
Asked Answered
N

1

9

I have a solution explorer contains 2 projects. For one project I have enabled /clr with /mdd. For parent project I have /mtd and no clr support. When I compile this I get two linker errors including the below one:

Link warning link 4098:Default lib can conflict with other lib use /NODEFAULTLIBS library

So my question is how to use /NODEFAULTLIBS in compilation.

Thanks in advance.

Neoprene answered 3/6, 2009 at 12:35 Comment(0)
H
10

First you need to work out which library is causing the conflict, if you can. Does the link warning tell you anything?

Then you need to open the property pages for this project, and go to Linker -> Command Line. In the 'Additional Options' area, type:

/NODEFAULTLIB:xxx.lib

where xxx.lib is the conflicting library. However, if you couldn't work out which library it is, try just:

/NODEFAULTLIB

Honeyman answered 4/6, 2009 at 8:54 Comment(4)
Could you discuss about the impact of using such options in you answer? I've tried to use "/NODEFAULTLIB" and there is now a lot of function that the linker doesn't find.Polynuclear
You have to figure out the library that is affected, although is not easy but is recommended. Using "/NODEFAULTLIB" is ambiguous and covers all default libraries and if you're depending on someway, you are sure to get a lot of linker issues.Immovable
Think of a bare /NODEFAULTLIB as the nuclear option. There are almost always dependencies on the default CRT library, and maybe many others (MFC, ATL, etc.), which must be called out by name in the list of libraries to search when you select /NODEFAULTLIB. It's an option that is there when you need it, which should be very rare. Though I've used it a few times, I have regretted doing so almost every time, and usually ended up backing off.Demetrius
I think, /MT(d) causes the compiler to add /DEFAULTLIB:"LIBCMT" to the .obj (and /MD -> "MSVCRT"), which you can find within the .obj after compilation (using text editor). Have a look at the MS doc to understand the order the linker uses to search for libraries / in libraries.Spicebush

© 2022 - 2024 — McMap. All rights reserved.