我如何在G+&#x2B中包含通往库的路径。

发布于 2025-02-08 04:46:05 字数 297 浏览 0 评论 0原文

我正在尝试将额外库的路径包括在我的makefile中,但是我不知道如何让编译器使用该路径。到目前为止,

g++ -g -Wall testing.cpp fileparameters.cpp main.cpp -o test

我想包括通往的路径

/data[...]/lib

,因为testing.cpp包括该库中的文件。另外,我在Linux机器上。

编辑:不是通往库的路径。仅来自该库中的标题文件。我的坏。

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

and I want to include the path to

/data[...]/lib

because testing.cpp includes files from that library. Also, I'm on a Linux machine.

EDIT: Not a path to a library. Just to header files from that library that were included. My bad.

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

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

发布评论

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

评论(3

雪花飘飘的天空 2025-02-15 04:46:05

要指定一个目录以搜索(二进制)库,您只需使用-L

-L/data[...]/lib

要指定实际库名称,您就可以使用-L

-lfoo  # (links libfoo.a or libfoo.so)

为搜索指定目录对于 include 文件(与库不同!),您使用-i

-I/data[...]/lib

所以我认为您想要的是类似

g++ -g -Wall -I/data[...]/lib testing.cpp fileparameters.cpp main.cpp -o test

这些编译器标志的东西(其他)也可以在GNU GCC命令选项手册:

To specify a directory to search for (binary) libraries, you just use -L:

-L/data[...]/lib

To specify the actual library name, you use -l:

-lfoo  # (links libfoo.a or libfoo.so)

To specify a directory to search for include files (different from libraries!) you use -I:

-I/data[...]/lib

So I think what you want is something like

g++ -g -Wall -I/data[...]/lib testing.cpp fileparameters.cpp main.cpp -o test

These compiler flags (amongst others) can also be found at the GNU GCC Command Options manual:

恋竹姑娘 2025-02-15 04:46:05

在您的makefile或cmakelists.txt中,您可以设置CMAKE_CXX_FLAGS如下:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/path/to/your/folder")

In your MakeFile or CMakeLists.txt you can set CMAKE_CXX_FLAGS as below:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/path/to/your/folder")
完美的未来在梦里 2025-02-15 04:46:05

另外,您可以设置环境变量。
假设您正在使用bash,然后在〜/.bashrc

C_INCLUDE_PATH="/data/.../lib/:$C_INCLUDE_PATH" ## for C compiler
CPLUS_INCLUDE_PATH="/data/.../lib/:$CPLUS_INCLUDE_PATH" ## for Cpp compiler
export C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH

使用source〜/.bashrc编写和源。
你应该很好。

Alternatively you could setup environment variables.
Suppose you are using bash, then in ~/.bashrc, write

C_INCLUDE_PATH="/data/.../lib/:$C_INCLUDE_PATH" ## for C compiler
CPLUS_INCLUDE_PATH="/data/.../lib/:$CPLUS_INCLUDE_PATH" ## for Cpp compiler
export C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH

and source it with source ~/.bashrc.
You should be good to go.

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