Clang++ 3.5.0 -rdynamic
Clang++ 3.5.0 -rdynamic
我正在编译 c++ 代码,我正在尝试添加 -rdynamic 选项,以便我可以打印出有意义的堆栈跟踪来调试我的 c++ 程序,但 clang 抛出一条警告,说"编译期间未使用的参数:'-rdynamic'"。
作为测试,在我的系统上,我尝试编写一个简单的 c++ 程序并使用 -rdynamic 编译它,它没有问题,但对于这个项目,它似乎没有。
任何建议都非常受欢迎
当您只是编译源代码而不是链接源代码时,您可能会使用 -rdynamic
标志。它是链接器的标志,因此仅在链接时需要它。某些版本的 clang 可能无法识别它,在这种情况下,您可以指示 clang 将正确的选项传递给链接器,通常是:
-Wl,--export-dynamic
因此,例如
clang++ -rdynamic test.cpp
或
clang++ -Wl,--export-dynamic test.cpp
但是如果你是单独编译和链接的,只在链接阶段使用它:
clang++ -c test.cpp
clang++ -Wl,--export-dynamic test.o
(或作为最后一步:clang++ -rdynamic test.o
)
nos's
答案是正确的,对我有很大帮助><。一个小提示,--Wl,--export-dynamic
应该-Wl,--export-dynamic
还有一些方法可以确保-rdynamic
工作.
使用readelf -s
查看 ELF 符号:
例如
$ cat t.c
#include <stdio.h>
void bar() {}
void baz() {}
void foo() {}
int main() { foo(); printf("test"); return 0; }
$ clang -O0 -o test t.c
$ readelf -s test >test.elf
Symbol table '.dynsym' contains 7 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTab
2: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.17 (2)
3: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
4: 0000000000000000 0 FUNC GLOBAL DEFAULT UND abort@GLIBC_2.17 (2)
5: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable
6: 0000000000000000 0 FUNC GLOBAL DEFAULT UND printf@GLIBC_2.17 (2)
$ clang -rdynamic -O0 -o test1 t.c
$ readelf -s test1 >test1.elf
Symbol table '.dynsym' contains 24 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTab
2: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.17 (2)
3: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
4: 0000000000000000 0 FUNC GLOBAL DEFAULT UND abort@GLIBC_2.17 (2)
5: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable
6: 0000000000000000 0 FUNC GLOBAL DEFAULT UND printf@GLIBC_2.17 (2)
7: 0000000000420038 0 NOTYPE GLOBAL DEFAULT 25 _bss_end__
8: 00000000004009a0 68 FUNC GLOBAL DEFAULT 14 main
9: 0000000000420030 0 NOTYPE GLOBAL DEFAULT 25 __bss_start__
10: 0000000000420030 0 NOTYPE GLOBAL DEFAULT 25 __bss_start
11: 0000000000400994 4 FUNC GLOBAL DEFAULT 14 bar
12: 0000000000400a7c 4 OBJECT GLOBAL DEFAULT 16 _IO_stdin_used
13: 0000000000420038 0 NOTYPE GLOBAL DEFAULT 25 _end
14: 0000000000420038 0 NOTYPE GLOBAL DEFAULT 25 __end__
15: 0000000000420020 0 NOTYPE GLOBAL DEFAULT 24 __data_start
16: 0000000000420030 0 NOTYPE GLOBAL DEFAULT 24 _edata
17: 0000000000400a68 4 FUNC GLOBAL DEFAULT 14 __libc_csu_fini
18: 000000000040099c 4 FUNC GLOBAL DEFAULT 14 foo
19: 00000000004009e8 128 FUNC GLOBAL DEFAULT 14 __libc_csu_init
20: 00000000004008a0 0 FUNC GLOBAL DEFAULT 14 _start
21: 0000000000420020 0 NOTYPE WEAK DEFAULT 24 data_start
22: 0000000000400998 4 FUNC GLOBAL DEFAULT 14 baz
23: 0000000000420038 0 NOTYPE GLOBAL DEFAULT 25 __bss_end__
您将看到.dynsym
中的所有符号,而不仅仅是使用的符号.
还有一些关于strip
-rdynamic
标志影响的有趣测试:
GCC 调试符号(-g 标志)与链接器的 -rdynamic 选项
相关文章:
- 奇怪的结构&GCC&clang(void*返回类型)
- 数据成员SFINAE的C++17测试:gcc vs clang
- 当我编译webrtc服务器时,Windows上只支持clang-cl
- 为什么在Windows上的VS 2019和Clang 9中"size_t"在没有标题的情况下工作
- 我可以将一个用clang c++11编译的对象与另一个用c++17编译的对象链接起来吗
- Clang bug?使用指针作为模板参数
- clang整洁10忽略了我的NOLINT命令
- 如何防止clang格式在流运算符调用之间添加换行符<<
- 在clang++预处理器中确定gcc工具链版本
- 为什么 Clang 不允许"and"作为函数名称?
- 带有 -stdlib=libc++ 的 clang++ 9.0.1 找不到<optional>
- clang格式:宏的缩进
- CLANG 编译器 说:变量"PTR"可能未初始化
- clang格式:禁用排序包含
- 为什么lambda在clang上崩溃而不是在gcc上崩溃
- gcc和clang在表达式是否为常量求值的问题上存在分歧
- 循环展开 - G++ 与 Clang++
- 如何使用Clang/GCC在Mac上为C/C++设置VSCode
- 一位朋友将模板函数缩写为clang和gcc
- Clang++ 3.5.0 -rdynamic