如何在 g++ 中包含库的路径 [英] How do I include a path to libraries in g++
问题描述
我试图在我的 makefile 中包含额外库的路径,但我不知道如何让编译器使用该路径.到目前为止,我有:
I am trying to include the path to extra libraries in my makefile, but I can't figure out how to get the compiler to use that path. so far I have:
g++ -g -Wall testing.cpp fileparameters.cpp main.cpp -o test
并且我想包含到
/data[...]/lib
因为 testing.cpp 包含来自该库的文件.另外,我使用的是 linux 机器.
because testing.cpp includes files from that library. Also, I'm on a linux machine.
不是库的路径.只是包含的文件.我的错.
Not a path to a library. Just to files that were included. My bad.
推荐答案
要指定搜索(二进制)库的目录,只需使用 -L
:
To specify a directory to search for (binary) libraries, you just use -L
:
-L/data[...]/lib
要指定实际的库名称,请使用 -l
:
To specify the actual library name, you use -l
:
-lfoo # (links libfoo.a or libfoo.so)
要指定一个目录来搜索 include 文件(与库不同!)你使用 -I
:
To specify a directory to search for include files (different from libraries!) you use -I
:
-I/data[...]/lib
所以我认为你想要的是
g++ -g -Wall -I/data[...]/lib testing.cpp fileparameters.cpp main.cpp -o test
这些编译器标志(以及其他)也可以在 GNU GCC 命令选项手册中找到:
These compiler flags (amongst others) can also be found at the GNU GCC Command Options manual:
这篇关于如何在 g++ 中包含库的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!