- 论坛徽章:
- 0
|
回复 #1 andyxie407 的帖子
我遇到了一样的问题。也是链接的时候找不到。在静态库里能找到这个函数。再请问一下动态库里的函数能用什么命令查找吗?
@s2 ~/testprogram $ nm -os /usr/lib/libpthread.a>liblist.c
@s2 ~/testprogram $ grep "pthread_atfork" liblist.c
__pthread_atfork in pthread_atfork.o
pthread_atfork in pthread_atfork.o
/usr/lib/libpthread.a:pthread_atfork.o: w __dso_handle
/usr/lib/libpthread.a:pthread_atfork.o:00000000 T __pthread_atfork
/usr/lib/libpthread.a:pthread_atfork.o: U __register_atfork
/usr/lib/libpthread.a:pthread_atfork.o:00000000 T pthread_atfork
@s2 ~/testprogram $
@s2 ~/testprogram $
- wei.liang@s2 ~/testprogram $ cat pthread_atfork_test.c
- #include <stdio.h>
- #include <unistd.h>
- #include <pthread.h>
- pthread_mutex_t lock1 = PTHREAD_MUTEX_INITIALIZER;
- pthread_mutex_t lock2 = PTHREAD_MUTEX_INITIALIZER;
- void prepare(void)
- {
- printf("prepare lock...\n");
- pthread_mutex_lock(&lock1);
- pthread_mutex_lock(&lock2);
- }
- void parent(void)
- {
- printf("parent unlock...\n");
- pthread_mutex_unlock(&lock1);
- pthread_mutex_unlock(&lock2);
- }
- void child(void)
- {
- printf("child unlock...\n");
- pthread_mutex_unlock(&lock1);
- pthread_mutex_unlock(&lock2);
- }
- void thr_fn(void *arg)
- {
- printf("thread started...\n");
- pause();
- return;
- }
- int main(void)
- {
- int err;
- int pid;
- pthread_t tid;
- #if defined(BSD)||defined(MACOS)
- printf("pthread_atfork not support!\n");
- #else
- err = pthread_atfork(prepare,parent,child);
- if (err != 0){
- printf("can't install fork handles!\n");
- return -1;
- }
- err = pthread_create(&tid,NULL,thr_fn,NULL);
- if (err != 0){
- printf("can't create new thread!\n");
- return -1;
- }
- sleep(2);
- printf("parent about to fork...\n");
- pid = fork();
- if (pid < 0){
- printf("fork failed.\n");
- return -1;
- }else if (pid == 0){
- printf("child return fork!\n");
- }else{
- printf("parent return fork!\n");
- }
- #endif
- return 0;
- }
- wei.liang@s2 ~/testprogram $
- wei.liang@s2 ~/testprogram $
- wei.liang@s2 ~/testprogram $ gcc -Wall -lpthread pthread_atfork_test.c
- pthread_atfork_test.c: In function 'main':
- pthread_atfork_test.c:48: warning: passing argument 3 of 'pthread_create' from incompatible pointer type
- /tmp/ccM75C6J.o: In function `main':
- pthread_atfork_test.c:(.text+0xc6): undefined reference to `pthread_atfork'
- collect2: ld returned 1 exit status
- @s2 ~/testprogram $ uname -a
- Linux s2 2.6.25-gentoo-r7 #1 SMP Sun Jul 27 15:19:28 CST 2008 i686 Intel(R) Pentium(R) Dual CPU E2180 @ 2.00GHz GenuineIntel GNU/Linux
- @s2 ~/testprogram $ gcc -v
- Using built-in specs.
- Target: i686-pc-linux-gnu
- Configured with: /var/tmp/portage/sys-devel/gcc-4.1.2/work/gcc-4.1.2/configure --prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/4.1.2 --includedir=/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include --datadir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.2 --mandir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.2/man --infodir=/usr/share/gcc-data/i686-pc-linux-gnu/4.1.2/info --with-gxx-include-dir=/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4 --host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --disable-altivec --enable-nls --without-included-gettext --with-system-zlib --disable-checking --disable-werror --enable-secureplt --disable-libunwind-exceptions --disable-multilib --enable-libmudflap --disable-libssp --disable-libgcj --with-arch=i686 --enable-languages=c,c++,treelang,fortran --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu
- Thread model: posix
- gcc version 4.1.2 (Gentoo 4.1.2 p1.1)
复制代码
[ 本帖最后由 wliang511 于 2008-10-23 14:41 编辑 ] |
|