mkdir .libs
#-----------------------------------------------------------------------------------
# In the following process, we compile both the object files for the shared/static library using
#-----------------------------------------------------------------------------------
gcc -I. -I. -DHAVE_CONFIG_H -O2 -pipe -c uuid.c -fPIC -DPIC -o .libs/uuid.o
gcc -I. -I. -DHAVE_CONFIG_H -O2 -pipe -c uuid.c -o uuid.o >/dev/null 2>&1
gcc -I. -I. -DHAVE_CONFIG_H -O2 -pipe -c uuid_md5.c -fPIC -DPIC -o .libs/uuid_md5.o
gcc -I. -I. -DHAVE_CONFIG_H -O2 -pipe -c uuid_md5.c -o uuid_md5.o >/dev/null 2>&1
gcc -I. -I. -DHAVE_CONFIG_H -O2 -pipe -c uuid_sha1.c -fPIC -DPIC -o .libs/uuid_sha1.o
gcc -I. -I. -DHAVE_CONFIG_H -O2 -pipe -c uuid_sha1.c -o uuid_sha1.o >/dev/null 2>&1
gcc -I. -I. -DHAVE_CONFIG_H -O2 -pipe -c uuid_prng.c -fPIC -DPIC -o .libs/uuid_prng.o
gcc -I. -I. -DHAVE_CONFIG_H -O2 -pipe -c uuid_prng.c -o uuid_prng.o >/dev/null 2>&1
gcc -I. -I. -DHAVE_CONFIG_H -O2 -pipe -c uuid_mac.c -fPIC -DPIC -o .libs/uuid_mac.o
gcc -I. -I. -DHAVE_CONFIG_H -O2 -pipe -c uuid_mac.c -o uuid_mac.o >/dev/null 2>&1
gcc -I. -I. -DHAVE_CONFIG_H -O2 -pipe -c uuid_time.c -fPIC -DPIC -o .libs/uuid_time.o
gcc -I. -I. -DHAVE_CONFIG_H -O2 -pipe -c uuid_time.c -o uuid_time.o >/dev/null 2>&1
gcc -I. -I. -DHAVE_CONFIG_H -O2 -pipe -c uuid_ui64.c -fPIC -DPIC -o .libs/uuid_ui64.o
gcc -I. -I. -DHAVE_CONFIG_H -O2 -pipe -c uuid_ui64.c -o uuid_ui64.o >/dev/null 2>&1
gcc -I. -I. -DHAVE_CONFIG_H -O2 -pipe -c uuid_ui128.c -fPIC -DPIC -o .libs/uuid_ui128.o
gcc -I. -I. -DHAVE_CONFIG_H -O2 -pipe -c uuid_ui128.c -o uuid_ui128.o >/dev/null 2>&1
gcc -I. -I. -DHAVE_CONFIG_H -O2 -pipe -c uuid_str.c -fPIC -DPIC -o .libs/uuid_str.o
gcc -I. -I. -DHAVE_CONFIG_H -O2 -pipe -c uuid_str.c -o uuid_str.o >/dev/null 2>&1
# compile the shared library
gcc -shared .libs/uuid.o .libs/uuid_md5.o .libs/uuid_sha1.o .libs/uuid_prng.o .libs/uuid_mac.o .libs/uuid_time.o .libs/uuid_ui64.o .libs/uuid_ui128.o .libs/uuid_str.o -Wl,-soname -Wl,libuuid.so.16 -o .libs/libuuid.so.16.0.21
# do the shared libray linkage
(cd .libs && rm -f libuuid.so.16 && ln -s libuuid.so.16.0.21 libuuid.so.16)
(cd .libs && rm -f libuuid.so && ln -s libuuid.so.16.0.21 libuuid.so)
# do the static library linkage, using ar
ar cru .libs/libuuid.a uuid.o uuid_md5.o uuid_sha1.o uuid_prng.o uuid_mac.o uuid_time.o uuid_ui64.o uuid_ui128.o uuid_str.o
# using ranlib
ranlib .libs/libuuid.a
creating libuuid.la
# creating the libuuid.la for libtool library file using
(cd .libs && rm -f libuuid.la && ln -s ../libuuid.la libuuid.la)
gcc -I. -I. -DHAVE_CONFIG_H -O2 -pipe -c uuid_cli.c
# build the uuid application program
gcc -o .libs/uuid uuid_cli.o ./.libs/libuuid.so -lnsl -Wl,--rpath -Wl,/tmp/uuidtmp/lib
creating uuid
Q. the option "-pipe" of gcc means?
Q. -Wl,--rpath -Wl,/tmp/uuidtmp/lib means?
pass the option to the linker, the comma sign will replace with space while passing into the linker (ld)
Q. When we compile an object file. What is the difference if we direct compile the library of just link the library? for example
# gcc a.o b.o libxyz.a -o hello
# gcc a.o b.o -lxyz -o heelo ==> the command format is wrong
==> You must let the linked library parameter -lxyz behind the output executable file (-o hello)
What is the difference in the above 2 items? (Basically they all can work)
The ld need to place the linked library behind the output executing file, like the following command
This is an important trick/tip :( (I am failed many times in this point... )
# gcc a.o b.o -o heelo -lxyz
沒有留言:
張貼留言