CS205 is a c/cpp course of SUSTech. The instructor is Shiqi Yu
- Let's build a shared library
- Remember to use arguments "-shared" and "-fPIC" when building it
- Now we should see "libfunction.so" in the directory
g++ -shared -fPIC -o libfunction.so function.cpp-
Now we can use "printHello" function with the ".h" header file and the ".so" shared library
-
Let's compile main again:
g++ -o main -L. main.cpp -lfunction
-
Use "-L." to tell it to find libraries in current directory
-
USe "-lfunction" to tell it to use "libfunction.so".
-
After the "main" has been compiled, try to run it
./main- Using export command to set environment variable "LD_LIBRARY_PATH"
- AND then run "main" again
export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
echo $LD_LIBRARY_PATH