【发布时间】:2018-07-16 01:52:54
【问题描述】:
我正在尝试修改 pthread_create。具体来说,在 create_thread 中,我想删除 CLONE_FILES 标志。我也有函数需要正常的 pthread_create。所以我复制了 pthread_create 和 create_thread 的代码,将它们重命名为 pthread_create_no_clone_files 和 create_thread_no_clone_files。在 create_thread_no_clone_files 中,我删除了 CLONE_FILES 标志。然后我编译它们,得到一个新的 libpthread.a。以下是nm libpthread.a | grep pthread_create的输出
0000000000002190 W pthread_create
0000000000002190 T __pthread_create_2_1
00000000000026a0 T pthread_create_no_clone_files
U __pthread_create
U __pthread_create
所以我在这里有我的pthread_create_no_clone_files。但是当我尝试使用g++ pthread_test.c -static libpthread.a -o pthread_test 构建我的测试程序时,我遇到了以下链接错误
pthread_test.c:(.text+0x82): undefined reference to `pthread_create_no_clone_files(unsigned long*, pthread_attr_t const*, void* (*)(void*), void*)'
pthread_create_no_clone_files 在我的程序中前向声明。我觉得我需要在 libpthread 的某处声明我的函数pthread_create_no_clone_files,但我的知识告诉我,如果我的静态库中有入口,那么我应该能够链接它。我的理解有什么问题?
我也欢迎其他更好的方法来创建不带 CLONE_FILES 标志的 pthread。谢谢。
【问题讨论】:
标签: gcc pthreads gnu static-linking