Suppose I have a file main.cpp
which uses sin()
function which is defined in libmath
. Also suppose that we have both libmath.a and lib
Use this function:
g++ -o main main.cpp /path_to/libmath.a
You'll need to pass the -static to the linker, but only for particular libraries you want. e.g.:
g++ -o main main.cpp -Wl,-Bstatic -lmath -Wl,-Bdynamic
If your linker supports -l:<filename>
you may use:
g++ -o main main.cpp -l:libmath.a