如何隐式链接库? [英] How to implicitly link libraries?

查看:143
本文介绍了如何隐式链接库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为A.a的库,它的.hpp文件叫做A.hpp。当程序需要使用这个库时,它们#includeA.hpp,并像这样链接到它:g ++ test1.cpp A.a -o test1。我希望能够像这个g ++ test1.cpp -o test1一样编译它,而不需要在那里明确地键入A.a,就像我不需要明确地将我的程序与iostream链接。我可以如何实现这一点?

I have a library called A.a, and its .hpp file called A.hpp. When programs need to use this library, they #include "A.hpp", and get linked to it like this: g++ test1.cpp A.a -o test1. I'd like to be able to only compile it like this g++ test1.cpp -o test1, without explicitly typing A.a in there, just like I don't need to explicitly link my program with iostream. How can I achieve this?

推荐答案

它可以在Visual C ++上完成(编译器可以在对象文件中嵌入一些链接器选项,请求链接一个图书馆是可能的)。

It can be done on Visual C++ (the compiler can embed some linker options in object files, requests to link a library being one of those that are possible).

海湾合作委员会(据我所知,铛)没有这样的功能。您必须在命令行上提供这些库;没有办法绕过它(构建工具在技术上并不是一种解决方法;它们也将库放到他们用来运行链接器的命令行中)。

Gcc (and, to my knowledge, clang) do not have such a feature. You have to provide the libraries on the command line; there is no way around it (build tools are not technically a way around it; they also put the libraries onto the command lines they use to run the linker).

这篇关于如何隐式链接库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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