Ignore comment #pragma (lib, ...)?

I am trying to link to previously generated .obj files (using latest MSVC).

When these .objs have been created, reference the source code:

#pragma comment(lib, ...)

      

So the linker tries to link itself to the static libraries that are referenced in the source. Is there a way to instruct the linker to ignore these libraries so I can specify my own?

for example if the source chunk did the following:

#pragma comment(lib, foo.lib)

      

At the point of linking, I would like the linker to ignore "foo.lib" and instead refer to "bar.lib".

+1


a source to share


1 answer


Why not change the source (directives #pragma

)?

From comment

MSDN Page:

Lib

Places a library search record in an object file. This type of comment must be followed by a commentstring parameter containing the name (and possibly the path) of the library you want the linker to search for. The library name follows the default library entries in the object file; the linker looks for this library in the same way as if you called it on the command line, provided the library is not listed with / nodefaultlib. You can place multiple library entries in the same source file; each entry appears in the object file in the same order in which it appears in the source file.

If the default library order and added library are important, compiling with the / Zl switch will prevent the default library name from being placed in the object module. The second comment pragma can be used to insert the default library name after the added library. Libraries listed in these pragmas will appear in the object module in the same order as in the source code.



You can also use the option NODEFALTLIB

to stop linking foo.lib

and specify bar.lib

how you would other lib files (i.e. via the Linker property panel).

Otherwise, rename bar.lib

to foo.lib

(cheeky solution).

+1


a source







All Articles