对于 MacOS 上的 G++,如何添加默认包含目录 /usr/local/include 和默认库搜索路径 /usr/local/lib?
For G++ on MacOS how to add default include dir /usr/local/include and default library search path /usr/local/lib?
我已经用自制软件安装了 libfmt。可以在 /usr/local/lib/libfmt.dylib
和 /usr/local/include/fmt
中找到文件。从形式上讲,它们是指向 /usr/local/Cellar/...
.
的链接
G++ 默认不搜索 /usr/local/include/ 和 /usr/local/lib/。我不想在项目级别添加它们。
❯❯❯ g++-9 -print-search-dirs
install: /usr/local/Cellar/gcc/9.3.0_1/lib/gcc/9/gcc/x86_64-apple-darwin18/9.3.0/
programs: =/usr/local/Cellar/gcc/9.3.0_1/libexec/gcc/x86_64-apple-darwin18/9.3.0/:/usr/local/Cellar/gcc/9.3.0_1/libexec/gcc/x86_64-apple-darwin18/9.3.0/:/usr/local/Cellar/gcc/9.3.0_1/libexec/gcc/x86_64-apple-darwin18/:/usr/local/Cellar/gcc/9.3.0_1/lib/gcc/9/gcc/x86_64-apple-darwin18/9.3.0/:/usr/local/Cellar/gcc/9.3.0_1/lib/gcc/9/gcc/x86_64-apple-darwin18/:/usr/local/Cellar/gcc/9.3.0_1/lib/gcc/9/gcc/x86_64-apple-darwin18/9.3.0/../../../../../../x86_64-apple-darwin18/bin/x86_64-apple-darwin18/9.3.0/:/usr/local/Cellar/gcc/9.3.0_1/lib/gcc/9/gcc/x86_64-apple-darwin18/9.3.0/../../../../../../x86_64-apple-darwin18/bin/
libraries: =/usr/local/Cellar/gcc/9.3.0_1/lib/gcc/9/gcc/x86_64-apple-darwin18/9.3.0/:/usr/local/Cellar/gcc/9.3.0_1/lib/gcc/9/gcc/x86_64-apple-darwin18/9.3.0/../../../../../../x86_64-apple-darwin18/lib/x86_64-apple-darwin18/9.3.0/:/usr/local/Cellar/gcc/9.3.0_1/lib/gcc/9/gcc/x86_64-apple-darwin18/9.3.0/../../../../../../x86_64-apple-darwin18/lib/:/usr/local/Cellar/gcc/9.3.0_1/lib/gcc/9/gcc/x86_64-apple-darwin18/9.3.0/../../../x86_64-apple-darwin18/9.3.0/:/usr/local/Cellar/gcc/9.3.0_1/lib/gcc/9/gcc/x86_64-apple-darwin18/9.3.0/../../../
您可以通过在 shell 中设置相关的环境变量来做到这一点,例如:
export CPATH=...
export LIBRARY_PATH=...
完整文档here
我已经用自制软件安装了 libfmt。可以在 /usr/local/lib/libfmt.dylib
和 /usr/local/include/fmt
中找到文件。从形式上讲,它们是指向 /usr/local/Cellar/...
.
G++ 默认不搜索 /usr/local/include/ 和 /usr/local/lib/。我不想在项目级别添加它们。
❯❯❯ g++-9 -print-search-dirs
install: /usr/local/Cellar/gcc/9.3.0_1/lib/gcc/9/gcc/x86_64-apple-darwin18/9.3.0/
programs: =/usr/local/Cellar/gcc/9.3.0_1/libexec/gcc/x86_64-apple-darwin18/9.3.0/:/usr/local/Cellar/gcc/9.3.0_1/libexec/gcc/x86_64-apple-darwin18/9.3.0/:/usr/local/Cellar/gcc/9.3.0_1/libexec/gcc/x86_64-apple-darwin18/:/usr/local/Cellar/gcc/9.3.0_1/lib/gcc/9/gcc/x86_64-apple-darwin18/9.3.0/:/usr/local/Cellar/gcc/9.3.0_1/lib/gcc/9/gcc/x86_64-apple-darwin18/:/usr/local/Cellar/gcc/9.3.0_1/lib/gcc/9/gcc/x86_64-apple-darwin18/9.3.0/../../../../../../x86_64-apple-darwin18/bin/x86_64-apple-darwin18/9.3.0/:/usr/local/Cellar/gcc/9.3.0_1/lib/gcc/9/gcc/x86_64-apple-darwin18/9.3.0/../../../../../../x86_64-apple-darwin18/bin/
libraries: =/usr/local/Cellar/gcc/9.3.0_1/lib/gcc/9/gcc/x86_64-apple-darwin18/9.3.0/:/usr/local/Cellar/gcc/9.3.0_1/lib/gcc/9/gcc/x86_64-apple-darwin18/9.3.0/../../../../../../x86_64-apple-darwin18/lib/x86_64-apple-darwin18/9.3.0/:/usr/local/Cellar/gcc/9.3.0_1/lib/gcc/9/gcc/x86_64-apple-darwin18/9.3.0/../../../../../../x86_64-apple-darwin18/lib/:/usr/local/Cellar/gcc/9.3.0_1/lib/gcc/9/gcc/x86_64-apple-darwin18/9.3.0/../../../x86_64-apple-darwin18/9.3.0/:/usr/local/Cellar/gcc/9.3.0_1/lib/gcc/9/gcc/x86_64-apple-darwin18/9.3.0/../../../
您可以通过在 shell 中设置相关的环境变量来做到这一点,例如:
export CPATH=...
export LIBRARY_PATH=...
完整文档here