Linux/gcc - 我应该如何编译我的程序以使用安装在我的主目录中的库?
我从未在无法以 root 身份访问安装库的计算机上进行编程,因此我不确定应该如何使用未安装在通常位置的库。
通常,当我拥有管理员权限时,我会执行通常的操作:
./configure
make
make install
安装库。然后我会执行常见的 #include
并进行编译(实际上这是在我的 makefile 中完成的):
gcc -c file1.c
gcc -c file2.c
...
gcc file1.o file2.o ... -o executable -llibrary
我应该如何处理安装在我的主文件夹中的库?假设我安装它:
./configure --prefix=$HOME
make
make install
现在我有诸如 $HOME/include
、$HOME/lib
和 $HOME/share
等目录。 ..我应该如何包含库、编译和链接二进制文件?
I never programmed in a computer without access to install libraries as root so I'm not really sure of what should I do to use libraries that I do not install in the usual places.
Usually, when I have admin priviledges I'd do the usual:
./configure
make
make install
to install the library. Then I'd do the common #include <library>
and compile with (actually this is done in my makefile):
gcc -c file1.c
gcc -c file2.c
...
gcc file1.o file2.o ... -o executable -llibrary
How should I deal with a library that was installed in my home folder? Suppose I install it with:
./configure --prefix=$HOME
make
make install
And now I have directories like $HOME/include
, $HOME/lib
and $HOME/share
, etc... how should I include the lib, compile and link the binaries?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需添加
到链接器的命令行即可指示它在该目录中查找库。
gcc 的目录选项在此处进行了解释< /a>
Just add
to the linker's command line to instruct it to look in that directory for libraries.
The directory options for gcc are explained here