Search code examples
c++static-linkinglinker-errors

g++ fails to link libraries while creating a shared object


I am trying to create a static library for my engine. The command (in a makefile) is:

g++ -c -fPIC window.cc -lGL -lGLEW -lSDL2 -std=c++14 -I../include/ && g++ -static window.o -lSDL2 -lGL -lGLEW -o ../distribute/so/window.so

So, the first command compiles successful, but the other one outputs this:

/usr/bin/ld: cannot find -lGL
/usr/bin/ld: cannot find -lGLEW
collect2: error: ld returned 1 exit status

But I definitely need those arguments. Can we fix it?


Solution

  • You need to know the exact paths of the library files to be linked with. The directories that contain them should be added to your link line with -L.