I have a problem with linking libraries correctly to my projects using gmake and premake5 (On Linux, elementaryOS). I'm using premake to generate the makefiles. I have 3 projects in my workspace: glfw (the library I want to be linked to), Celer (The library I wanted to start working on, it should be linked with glfw) and Sandbox (my testing app). The linking between Sandbox and Celer works without any problems, but when I try to link Celer and glfw, undefined refrences occur and I just can't figure out why.
==== Building glfw (debug) ====
==== Building Celer (debug) ====
==== Building Sandbox (debug) ====
Linking Sandbox
../../bin/linux-Debug-x86_64/Celer/libCeler.a(Window.o): In function `Celer::Window::Window()':
/home/daniel/Documents/Development/C++/celer-engine/src/celer/Graphics/Window.cpp:6: undefined reference to `glfwInit'
/home/daniel/Documents/Development/C++/celer-engine/src/celer/Graphics/Window.cpp:11: undefined reference to `glfwDefaultWindowHints'
/home/daniel/Documents/Development/C++/celer-engine/src/celer/Graphics/Window.cpp:12: undefined reference to `glfwCreateWindow'
/home/daniel/Documents/Development/C++/celer-engine/src/celer/Graphics/Window.cpp:19: undefined reference to `glfwSwapInterval'
../../bin/linux-Debug-x86_64/Celer/libCeler.a(Window.o): In function `Celer::Window::update()':
/home/daniel/Documents/Development/C++/celer-engine/src/celer/Graphics/Window.cpp:29: undefined reference to `glfwSwapBuffers'
collect2: error: ld returned 1 exit status
Makefile:78: recipe for target '../../bin/linux-Debug-x86_64/Sandbox/Sandbox' failed
make[1]: *** [../../bin/linux-Debug-x86_64/Sandbox/Sandbox] Error 1
Makefile:45: recipe for target 'Sandbox' failed
make: *** [Sandbox] Error 2
I know there are probably thousands of questions related to linking, but I've now spent so much time researching and I still can't get the problem.
I've setted up a GitHub repository with all of the premake and make files: GitHub repository
This is what make executes:
echo "==== Building glfw (debug) ===="
make --no-print-directory -C lib/glfw -f Makefile config=debug
:
echo "==== Building Celer (debug) ===="
make --no-print-directory -C src/celer -f Makefile config=debug
:
echo "==== Building Sandbox (debug) ===="
make --no-print-directory -C test/sandbox -f Makefile config=debug
echo Linking Sandbox
g++ -o "../../bin/linux-Debug-x86_64/Sandbox/Sandbox" ../../build/linux-Debug-x86_64/Sandbox/Sandbox.o -L/usr/lib64 -m64 ../../bin/linux-Debug-x86_64/Celer/libCeler.a
:
Ah, I didn't catch that you using static libraries. As Thomas Sablik said, static libraries do not include their dependencies, you need to carry those over yourself. So you need to change your Sandbox project from...
links { "Celer" }
To something more like...
links {
"glfw",
"Xrandr",
"Xi",
"GLU",
"GL",
"X11",
"dl",
"pthread",
"stdc++fs",
"Celer"
}