#pragma comment(lib, "xxx.lib") 在 Linux 下等效吗?

发布于 2024-08-09 17:14:29 字数 179 浏览 4 评论 0 原文

我有一个名为 libunp.a 的静态库文件,我知道我可以使用 gcc -lunp xx 链接到该库。

我可以使用 #pragma comment(lib,"xxx.lib") 告诉 Microsoft C/C++ 编译器包含该库;我怎样才能在Linux/GCC下做到这一点?

I have a static library file called libunp.a, I do know I could use gcc -lunp xx to link to the library.

I could use #pragma comment(lib,"xxx.lib") to tell the Microsoft C/C++ compiler to include the library; how could I do it under Linux/GCC?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甜妞爱困 2024-08-16 17:14:29

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.

路还长,别太狂 2024-08-16 17:14:29

应在链接步骤中指定库。这样的信息简直
不属于翻译单元。翻译单元可以被预处理,
即使没有链接阶段也可以编译和组装。

仅仅因为 #pragma comment(lib,"xxx.lib") 位于源文件中并不意味着编译器会使用它。事实上,它作为注释进入,随后由链接器使用。与 *nix 没有太大区别。

Libraries should be specified during the linking step. Such information simply
doesn't belong inside a translation unit. A translation unit can be preprocessed,
compiled and assembled even without a linking stage.

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.

铜锣湾横着走 2024-08-16 17:14:29

使用此 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文