忽略#pragma comment(lib,...)? [英] Ignore #pragma comment(lib, ...)?

查看:85
本文介绍了忽略#pragma comment(lib,...)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行以前生成的.obj文件的链接(使用MSVC的最新版本).

I'm attempting to perform a link of previously generated .obj files (using the latest version of MSVC).

创建这些.obj时,指定的源代码:

When those .obj's were created, the source code specified:

#pragma comment(lib, ...)

因此,链接器正在尝试链接到源中指定的静态库.有没有一种方法可以指示链接程序忽略这些库,因此我可以指定自己的库?

As such, the linker is attempting to link against static libraries specified in the source. Is there a way to instruct the linker to ignore these libraries, so I can specify my own?

例如,如果某个来源进行了以下操作:

e.g., if a piece of source did the following:

#pragma comment(lib, foo.lib)

在链接时,我希望链接器忽略'foo.lib',而链接到'bar.lib'.

At link time, I'd like the linker to ignore 'foo.lib', and instead link against 'bar.lib'.

推荐答案

为什么不更改源代码( #pragma 指令)?

Why not change the source (the #pragma directives)?

来自 评论 MSDN页面:

From comment MSDN page:

lib

在目标文件中放置一个库搜索记录.此注释类型必须带有一个注释字符串参数,其中包含要链接器搜索的库的名称(可能还有路径).库名称遵循目标文件中默认的库搜索记录;如果未使用/nodefaultlib指定该库,则链接程序将像在命令行上命名该库一样搜索该库.您可以在同一个源文件中放置多个库搜索记录.每个记录以与在源文件中遇到的顺序相同的顺序出现在目标文件中.

Places a library-search record in the object file. This comment type must be accompanied by a commentstring parameter containing the name (and possibly the path) of the library that you want the linker to search. The library name follows the default library-search records in the object file; the linker searches for this library just as if you had named it on the command line provided that the library is not specified with /nodefaultlib. You can place multiple library-search records in the same source file; each record appears in the object file in the same order in which it is encountered in the source file.

如果默认库和添加的库的顺序很重要,则使用/Zl开关进行编译将阻止将默认库名称放置在对象模块中.然后,可以使用第二个注释杂注在添加的库之后插入默认库的名称.带有这些实用程序列出的库将以与在源代码中找到的顺序相同的顺序出现在对象模块中.

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

您还可以使用 NODEFALTLIB 链接器选项可阻止链接 foo.lib ,并像指定其他lib文件一样指定 bar.lib (例如,通过链接器属性"窗格).

You can also use the NODEFALTLIB linker option to stop foo.lib from being linked, and specify bar.lib as you would other lib files (i.e. via the Linker Properties pane).

否则,将 bar.lib 重命名为 foo.lib (一个厚脸皮的解决方案).

Otherwise, rename bar.lib to foo.lib (a cheeky solution).

这篇关于忽略#pragma comment(lib,...)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆