GCC:列出一个静态链接的库
GCC: list a statically linked libraries
这就是问题所在。基本上,我的问题是,我试图用选项-fsanitize=address -static-libasan
为ARM编译一个应用程序(调试错误指针等很酷(。这可以直接编译为可执行文件,但不适用于从对象文件编译。Ofc I发现静态库是libasan.a
;无论如何,当我试图链接对象文件中的所有内容时,它会说«pthread»中有一堆未定义的引用,以及一些我甚至没能找到其lib所有者的函数。
所以,我只想用-fsanitize=address -static-libasan
编译一个文件,看看哪些库是静态链接的,这样我以后就可以从对象文件中进行链接了。
可执行文件不存储从中提取对象文件的任何静态库的踪迹。不过,大多数情况下,这些库是在链接时明确指定的。编译器只引入了几个标准静态库。对于gcc,您可以看到各种信息,包括使用-v
选项传递给链接器的实际命令行(似乎有些实现希望使用--verbose
,而对于链接器-Wl,--verbose
(。该输出应该显示所有隐式链接的库,如-lgcc
和-lstdc++
。
请注意,您应该使用特定于语言的前端和编译时相同的编译器标志进行链接。您的问题描述听起来像是在编译时将-pthread
与g++
一起使用,但您试图在没有-pthread
标志的情况下使用gcc
进行链接(有一些不同的线程相关标志;从描述中无法判断使用了哪一个(。
为了处理侮辱,以下是在我的计算机上使用-v
选项时的输出示例:
ThreadGard:stackoverflow kuehl$ cat hello.cpp
#include <iostream>
int main()
{
std::cout << "hello, worldn";
return 0;
}
ThreadGard:stackoverflow kuehl$ g++ -v -static hello.cpp
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/opt/gcc-4.9.2/libexec/gcc/x86_64-apple-darwin13.4.0/4.9.2/lto-wrapper
Target: x86_64-apple-darwin13.4.0
Configured with: ../gcc-4.9.2/configure --prefix=/opt/gcc-4.9.2 --with-gmp=/opt/gcc-infrastructure --with-mpfr=/opt/gcc-infrastructure --enable-decimal-float=bid --enable-lto --enable-languages=c,c++
Thread model: posix
gcc version 4.9.2 (GCC)
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.9.4' '-v' '-static' '-mtune=core2'
/opt/gcc-4.9.2/libexec/gcc/x86_64-apple-darwin13.4.0/4.9.2/cc1plus -quiet -v -D__STATIC__ hello.cpp -quiet -dumpbase hello.cpp -mmacosx-version-min=10.9.4 -mtune=core2 -auxbase hello -version -o /var/folders/b_/64plfvs936v5ylx36qwc8rg00000gp/T//ccrt7fXS.s
GNU C++ (GCC) version 4.9.2 (x86_64-apple-darwin13.4.0)
compiled by GNU C version 4.9.2, GMP version 5.0.5, MPFR version 3.1.1, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/../../../../x86_64-apple-darwin13.4.0/include"
#include "..." search starts here:
#include <...> search starts here:
/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/../../../../include/c++/4.9.2
/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/../../../../include/c++/4.9.2/x86_64-apple-darwin13.4.0
/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/../../../../include/c++/4.9.2/backward
/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/include
/usr/local/include
/opt/gcc-4.9.2/include
/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/include-fixed
/usr/include
/System/Library/Frameworks
/Library/Frameworks
End of search list.
GNU C++ (GCC) version 4.9.2 (x86_64-apple-darwin13.4.0)
compiled by GNU C version 4.9.2, GMP version 5.0.5, MPFR version 3.1.1, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: fea0def5b69cf8ae349b2f1faf4b1d23
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.9.4' '-v' '-static' '-mtune=core2'
as -arch x86_64 -force_cpusubtype_ALL -static -o /var/folders/b_/64plfvs936v5ylx36qwc8rg00000gp/T//ccPF77oR.o /var/folders/b_/64plfvs936v5ylx36qwc8rg00000gp/T//ccrt7fXS.s
COMPILER_PATH=/opt/gcc-4.9.2/libexec/gcc/x86_64-apple-darwin13.4.0/4.9.2/:/opt/gcc-4.9.2/libexec/gcc/x86_64-apple-darwin13.4.0/4.9.2/:/opt/gcc-4.9.2/libexec/gcc/x86_64-apple-darwin13.4.0/:/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/:/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/
LIBRARY_PATH=/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/:/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/../../../:/usr/lib/
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.9.4' '-v' '-static' '-mtune=core2'
/opt/gcc-4.9.2/libexec/gcc/x86_64-apple-darwin13.4.0/4.9.2/collect2 -static -arch x86_64 -macosx_version_min 10.9.4 -weak_reference_mismatches non-weak -o a.out -lcrt0.o -L/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2 -L/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/../../.. /var/folders/b_/64plfvs936v5ylx36qwc8rg00000gp/T//ccPF77oR.o /opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/../../../libstdc++.a -no_compact_unwind -no_pie -lgcc_eh -lgcc -v
collect2 version 4.9.2
/usr/bin/ld -static -arch x86_64 -macosx_version_min 10.9.4 -weak_reference_mismatches non-weak -o a.out -lcrt0.o -L/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2 -L/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/../../.. /var/folders/b_/64plfvs936v5ylx36qwc8rg00000gp/T//ccPF77oR.o /opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/../../../libstdc++.a -no_compact_unwind -no_pie -lgcc_eh -lgcc -v
@(#)PROGRAM:ld PROJECT:ld64-241.9
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7m armv7em
Library search paths:
/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2
/opt/gcc-4.9.2/lib
/usr/lib
/usr/local/lib
Framework search paths:
/Library/Frameworks/
/System/Library/Frameworks/
ld: library not found for -lcrt0.o
collect2: error: ld returned 1 exit status
并没有安装所有的静态库使其真正链接。然而,这是除此之外的重点,因为输出清楚地列出了链接器调用:
/usr/bin/ld-static-arch x86_64-macosx_version _min 10.9.4-weak_reference_mismatches non-w弱-o a.out-lcrt0.o-L/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2-L/opt/gcc-4.9.2/lib/gcc/x66_64-applie-darwin13.40/4.9.2/../../var/folders/b/64plfvs936v5ylx36qwc8rg00000gp/T//ccPF77oR.o/opt/gccc-4.9.2/libr/gcc/x86_64-apple-darwin13.4.0/4.9.2/../../libstdc++.a-no_compact_unwind-no_pie-lgcc_eh-lgcc-v
(添加了一些强调以使读者更容易阅读-这似乎是必要的(
- C++从另一个类访问公共静态向量的正确方法是什么
- 静态结构和一个定义规则
- 分离一个静态常量 std::thread?
- 在作为静态成员包含在另一个类中的类的构造函数中使用 cout
- 从另一个静态常量数组初始化静态常量数组(只需少量计算)
- 给定一个C++嵌套的私有结构类型,是否有从文件范围静态函数访问它的策略
- 在一个解决方案中针对第三方静态库 (Creo) 的不同版本(版本)进行构建
- 如果两个静态库使用相同的另一个静态库,如何避免"LNK2005 Already Defined error"?
- C++,每个循环初始化一个新的静态变量
- 从另一个标头中的标头调用静态方法
- 在 Visual Studio 中构建一个没有 C/C++ 运行时的静态库
- 如何正确实例化静态字段 tat 是另一个类对象
- C++ - 非静态 void* 成员,指向具有相同地址但不同值的不同对象的另一个非静态成员
- 使用 CMake 与其他静态库链接的静态库 - 一个有效,一个无效。为什么?
- 如何启用使用另一个类的静态方法的模板函数的自动推导,从而消除冗长的调用方代码
- 我可以使用 constexpr 函数声明一个静态数组吗?
- 静态常量与常量局部变量,哪一个性能更好
- 有没有办法声明一个公共静态常量,该常量将使用 constexpr 在源文件中定义(有什么区别)?
- 如果我有五个 Win32 静态控件,如何使用特定的前景色设置其中一个?
- win32 c++ 我想在静态标签的文本之后直接插入一个 EDIT 控件