Static library production, compilation:
gcc -c -o main.o main.c
gcc -c -o sub.o sub.c
gcc -c -o sub2.o sub2.c
CRS libsub.a sub.o sub2.o Ar ( may be used to generate a plurality of static library .o )
gcc -o test main.o libsub.a (.a if not in the current directory, you need to specify its absolute or relative path)
Making dynamic libraries, compilers:
gcc -c -o main.o main.c
gcc -c -fPIC -o sub.o sub.c
gcc -c -fPIC -o sub2.o sub2.c
-shared -o libsub.so sub.o sub2.o GCC ( may be used to generate a plurality of dynamic libraries .o )
gcc -o test main.o -lsub -L /libsub.so/ directory /
Dynamic libraries run:
① first libusb.so into / lib directory on the PC or the board, and then you can run the test program.
② If you do not want to libusb.so into / lib, can be placed on a directory such as / a, and then carried out as follows:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/a
./test
reference:
ar I used Linux command - to create static library .a file
Analysis of Linux static library and dynamic library
Linux shared compiler parameters of objects fPIC