c lang 环境变量的文档在哪里?
Where is the documentation of c lang env variables?
TLDR 我试图阅读 clang llvm 文档以找到传递库路径的方法,但没有成功。然后我搜索并找到了解决方案。我很好奇在哪里可以找到我的解决方案的文档。
详情及原因
我试图在我的 catalina 上 运行 ruby 的捆绑包,但我遇到了这个错误:
ld: library not found for -lssl
我使用 brew install openssl
重新安装了 openssl,然后 brew link openssl
我收到了以下响应:
Warning: Refusing to link macOS provided/shadowed software: openssl@1.1
If you need to have openssl@1.1 first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc
For compilers to find openssl@1.1 you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"
For pkg-config to find openssl@1.1 you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"
虽然我很欣赏 brew 为使其正常工作所做的努力,但没有一个是有效的。我将链接器问题缩小到这个范围以查看发生了什么:
clang -dynamic -bundle -o asdf -L/usr/local/Cellar/mysql/8.0.19/lib -lmysqlclient -lssl -lcrypt -v
最后using LIBRARY_PATH
我通过了环境变量
export LIBRARY_PATH=/usr/local/opt/openssl@1.1/lib/
您能够建立 clang
链接:
clang -dynamic -bundle -o asdf -L/usr/local/Cellar/mysql/8.0.19/lib -lmysqlclient -lssl -lcrypt -v
通过设置失败时成功:
export LIBRARY_PATH=/usr/local/opt/openssl@1.1/lib/
在clang
命令的环境中。
这证明 clang
受到 LIBRARY_PATH
环境的影响
变量以与 GCC 编译器相同的方式。
LIBRARY_PATH
未在 man clang
的 ENVIRONMENT
部分提及,
或者实际上根本没有,所以这种类似 GCC 的行为可以严格地被视为不是强制性的。
然而,遗漏似乎很可能是手册中的疏忽,
因为 clang
通常努力成为 gcc
的低调替代品。如果
我们 运行 一个 Linux clang
详细模式的链接:
$ export LIBRARY_PATH=/wheres/wally; clang -v main.o -L. -lfoo -lbar
clang version 10.0.0-4ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;@m64
Selected multilib: .;@m64
"/usr/bin/ld" -z relro --hash-style=gnu --build-id --eh-frame-hdr \
-m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out \
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crt1.o \
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o \
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o \
-L. -L/usr/bin/../lib/gcc/x86_64-linux-gnu/9 \
-L/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu \
-L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu \
-L/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../.. \
-L/usr/lib/llvm-10/bin/../lib -L/lib -L/usr/lib \
-L/wheres/wally \ # < There's wally!
main.o -lfoo -lbar -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc \
--as-needed -lgcc_s --no-as-needed \
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtend.o \
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o
我们观察到 clang
将 -L${LIBRARY_PATH}
的扩展插入到
ld
命令行在所有其他 -Ldir
选项之后。如果我们
追踪 LIBRARY_PATH
in the clang
source tree,
我们将看到实现它的代码。
在 man gcc
的 ENVIRONMENT
部分,
LIBRARY_PATH
记录在案:
LIBRARY_PATH
The value of LIBRARY_PATH is a colon-separated list of directories, much like PATH .
When configured as a native compiler, GCC tries the directories thus specified when
searching for special linker files, if it can't find them using GCC_EXEC_PREFIX .
Linking using GCC also uses these directories when searching for ordinary libraries
for the -l option (but directories specified with -L come first).
并且在 GCC online documentation: 3.21 Environment Variables Affecting GCC
中逐字出现
clang
对LIBRARY_PATH
的作用符合我强调的那句话
值得一提的是,虽然为此目的使用 LIBRARY_PATH
可能已经
你出了问题,它在常规的链接练习中不受青睐,因为它是
当你研究一个输出时,它很可能是一只看不见的手
链接:它的效果仅在详细模式下显示(通过 gcc
或 clang
)。这
安装人员的建议:
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
如您所愿。我不明白为什么它对你不起作用。
TLDR 我试图阅读 clang llvm 文档以找到传递库路径的方法,但没有成功。然后我搜索并找到了解决方案。我很好奇在哪里可以找到我的解决方案的文档。
详情及原因
我试图在我的 catalina 上 运行 ruby 的捆绑包,但我遇到了这个错误:
ld: library not found for -lssl
我使用 brew install openssl
重新安装了 openssl,然后 brew link openssl
我收到了以下响应:
Warning: Refusing to link macOS provided/shadowed software: openssl@1.1
If you need to have openssl@1.1 first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc
For compilers to find openssl@1.1 you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"
For pkg-config to find openssl@1.1 you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"
虽然我很欣赏 brew 为使其正常工作所做的努力,但没有一个是有效的。我将链接器问题缩小到这个范围以查看发生了什么:
clang -dynamic -bundle -o asdf -L/usr/local/Cellar/mysql/8.0.19/lib -lmysqlclient -lssl -lcrypt -v
最后using LIBRARY_PATH
我通过了环境变量
export LIBRARY_PATH=/usr/local/opt/openssl@1.1/lib/
您能够建立 clang
链接:
clang -dynamic -bundle -o asdf -L/usr/local/Cellar/mysql/8.0.19/lib -lmysqlclient -lssl -lcrypt -v
通过设置失败时成功:
export LIBRARY_PATH=/usr/local/opt/openssl@1.1/lib/
在clang
命令的环境中。
这证明 clang
受到 LIBRARY_PATH
环境的影响
变量以与 GCC 编译器相同的方式。
LIBRARY_PATH
未在 man clang
的 ENVIRONMENT
部分提及,
或者实际上根本没有,所以这种类似 GCC 的行为可以严格地被视为不是强制性的。
然而,遗漏似乎很可能是手册中的疏忽,
因为 clang
通常努力成为 gcc
的低调替代品。如果
我们 运行 一个 Linux clang
详细模式的链接:
$ export LIBRARY_PATH=/wheres/wally; clang -v main.o -L. -lfoo -lbar
clang version 10.0.0-4ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;@m64
Selected multilib: .;@m64
"/usr/bin/ld" -z relro --hash-style=gnu --build-id --eh-frame-hdr \
-m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out \
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crt1.o \
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o \
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o \
-L. -L/usr/bin/../lib/gcc/x86_64-linux-gnu/9 \
-L/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu \
-L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu \
-L/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../.. \
-L/usr/lib/llvm-10/bin/../lib -L/lib -L/usr/lib \
-L/wheres/wally \ # < There's wally!
main.o -lfoo -lbar -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc \
--as-needed -lgcc_s --no-as-needed \
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtend.o \
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o
我们观察到 clang
将 -L${LIBRARY_PATH}
的扩展插入到
ld
命令行在所有其他 -Ldir
选项之后。如果我们
追踪 LIBRARY_PATH
in the clang
source tree,
我们将看到实现它的代码。
在 man gcc
的 ENVIRONMENT
部分,
LIBRARY_PATH
记录在案:
LIBRARY_PATH
The value of LIBRARY_PATH is a colon-separated list of directories, much like PATH . When configured as a native compiler, GCC tries the directories thus specified when searching for special linker files, if it can't find them using GCC_EXEC_PREFIX . Linking using GCC also uses these directories when searching for ordinary libraries for the -l option (but directories specified with -L come first).
并且在 GCC online documentation: 3.21 Environment Variables Affecting GCC
中逐字出现clang
对LIBRARY_PATH
的作用符合我强调的那句话
值得一提的是,虽然为此目的使用 LIBRARY_PATH
可能已经
你出了问题,它在常规的链接练习中不受青睐,因为它是
当你研究一个输出时,它很可能是一只看不见的手
链接:它的效果仅在详细模式下显示(通过 gcc
或 clang
)。这
安装人员的建议:
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
如您所愿。我不明白为什么它对你不起作用。