Ref 1 cmd line to generate *.so on stackoverflow
Ref 2 stackflow post ld --verbose -llibxxx
testsomain is smaller when not compiled with testso.c
Ref 2 stackflow post ld --verbose -llibxxx
testsomain is smaller when not compiled with testso.c
[q.yang@fedora20 Trash]$ gcc testsomain.c -o testsomain -L./ -ltestso
It's bigger when compiled with testso.c. It's one of the benefit of using dynamic library.
[q.yang@fedora20 Trash]$ gcc testsomain.c testso.c -o testsomain
testsomain.c
#include#include "testso.h" int main(void) { printf("Testing calling function in *.so \n"); Ext_PrintHello(); }
testso.c
#includevoid Ext_PrintHello(void) { printf("%s Invoked from external module.\n",__func__); }
testso.h
//#error "this file has been included here" void Ext_PrintHello(void);
Compile to generate dynamic library:
Note: MUST use -fPIC option PositionIndependantCode(PIC)
*.so file name must be libxxnamexx.so, cannot be xxnamexx.so
Note: MUST use -fPIC option PositionIndependantCode(PIC)
*.so file name must be libxxnamexx.so, cannot be xxnamexx.so
[q.yang@fedora20 Trash]$ gcc -shared -fPIC -o libtestso.so testso.c
Compile main program to load dynamic library *.so
[q.yang@fedora20 Trash]$ gcc testsomain.c -o testsomain -L./ -ltestso
Set load library search path
[q.yang@fedora20 Trash]$ LD_LIBRARY_PATH=./ [q.yang@fedora20 Trash]$ export LD_LIBRARY_PATH
Run program
[q.yang@fedora20 Trash]$ ./testsomain Testing calling function in *.so Ext_PrintHello Invoked from external module.
Checking so file dependencies $ldd and file info $file. (Running for i686 or ARM)
duser@10.1.1.8:~/Trash$ file libtestso.so libtestso.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, BuildID[sha1]=0xf54c8aad49c8dfd0220885eab40fe703c0e5495b, not stripped duser@10.1.1.8:~/Trash$ ldd libtestso.so libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb754b000) /lib/ld-linux.so.2 (0xb770f000)
No comments:
Post a Comment