#pragma comment(lib, "xxx.lib") 在 Linux 下等效吗?
我有一个名为 libunp.a
的静态库文件,我知道我可以使用 gcc -lunp xx
链接到该库。
我可以使用 #pragma comment(lib,"xxx.lib") 告诉 Microsoft C/C++ 编译器包含该库;我怎样才能在Linux/GCC下做到这一点?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
GCC 手册关于编译指示的页面中似乎没有提及任何等效的编译指示。
我看到 GCC 不支持源代码中的链接的原因之一是有时 正确的链接取决于链接顺序;这需要您确保无论编译顺序如何,链接顺序都会正确发生。我想,如果您要做那么多工作,您也可以在命令行(或其他方式)上传递链接器参数。
There doesn't seem to be any mention of any equivalent pragmas in the GCC manual's page on pragmas.
One reason I saw for GCC not supporting linking in source code was that sometimes, correct linking depends on link order; and this would require you to make sure that the linking order happens correctly no matter the order of compilation. If you're going to go to that much work, you may as well just pass the linker arguments on the command line (or otherwise), I suppose.
仅仅因为
#pragma comment(lib,"xxx.lib")
位于源文件中并不意味着编译器会使用它。事实上,它作为注释进入,随后由链接器使用。与 *nix 没有太大区别。Simply because
#pragma comment(lib,"xxx.lib")
is in the source file does not mean the compiler consumes it. In fact, it goes in as a comment and is subsequently used by the linker. Not much different than *nix.使用此 GCC 标志可为未知编译指示生成错误。它会很快告诉你编译器是否理解它。
-Werror=未知-pragmas
Use this GCC flag to generate an error for unknown pragmas. It will quickly tell you if the compiler understands it.
-Werror=unknown-pragmas