Reputation: 177
I want to create a static library of all my files so that i could give my mylib.a file to others to execute on their system. I use opencv library in my code. I used the following command to compile my code.
g++ index.cpp -o display1 -Wl,-Bdynamic pkg-config --cflags --libs opencv -lglut -lGL -lGLU -Wl,-Bstatic mylib.a
But it is giving the following error.
/usr/bin/ld: cannot find -lgcc_s
collect2: ld returned 1 exit status
Upvotes: 2
Views: 1184
Reputation: 76386
I believe the Kerrek SB is right in the comment. The command should be
g++ index.cpp -o display1 mylib.a $(pkg-config --cflags --libs opencv) -lglut -lGL -lGLU
Explanation:
-Wl,-Bdynamic
and -Wl,-Bstatic
flags are useless. The linker automatically picks static or dynamic library depending on what it finds. If you give it path to a library (as you do with mylib.a
) it can't choose and will link the library you provided. If you give it an -l
X flag, it will look for lib
X.so
or lib
X.a
and link whichever it finds, but most Linux installations won't have static variants of system libraries, so there is nothing to choose from either.-Wl,-Bdynamic
and -Wl,-Bstatic
are wrong. -Wl,-Bstatic
prohibits linking of shared libraries. That has the side-effect of selecting static libgcc, which implicitly comes last on the linker command line. And you don't seem to have that installed. Most Linux systems don't.mylib.a
contains functions that need opencv or opengl, so it must be listed before those -l
flags.Upvotes: 4