angelpan1014

 

20121025

hello.c  hello.h  libhello.so  main.c  static_lib_demo
ocs8:/home/panpan/C++>gcc -o hello main.c -L. -lhello
/tmp/ccoy9enl.o: In function `main':
main.c:(.text+0xa): undefined reference to `hello'
collect2: ld returned 1 exit status
ocs8:/home/panpan/C++>gcc -o hello main.c -L. -lhello
/tmp/ccMVhNga.o: In function `main':
main.c:(.text+0xa): undefined reference to `hello'
collect2: ld returned 1 exit status
ocs8:/home/panpan/C++>gcc -o hello main.c -L. -lhello
/tmp/ccavjobK.o: In function `main':
main.c:(.text+0xa): undefined reference to `hello'
collect2: ld returned 1 exit status
ocs8:/home/panpan/C++>gcc -o hello main.c -L. -lhello
/tmp/ccKeqBUA.o: In function `main':
main.c:(.text+0xa): undefined reference to `hello'
collect2: ld returned 1 exit status

 

2.ocs8:/home/panpan/C++>gcc -shared -fPIC hello.o -o libhello.so
/usr/lib64/gcc/x86_64-suse-linux/4.1.2/http://www.cnblogs.com/http://www.cnblogs.com/x86_64-suse-linux/bin/ld: hello.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
hello.o: could not read symbols: Bad value
collect2: ld returned 1 exit status

 

3.ocs8:/home/panpan/C++>ls
hello.cpp  hello.h  hello.o  libhello.so  main.cpp
ocs8:/home/panpan/C++>g++ main.cpp libhello.so -o hello
/tmp/ccucBvtj.o: In function `main':
main.cpp:(.text+0xa): undefined reference to `hello(char const*)'
collect2: ld returned 1 exit status
ocs8:/home/panpan/C++>g++ -o hello main.cpp -L. -lhello
/tmp/ccCHqELE.o: In function `main':
main.cpp:(.text+0xa): undefined reference to `hello(char const*)'
collect2: ld returned 1 exit status

posted on 2012-10-25 10:29  angelpan1014  阅读(196)  评论(0编辑  收藏  举报

导航