Search code examples
c++compilationlinkerglfwpremake

Linking local installation of GLFW


I want to link against a project installed, rather than OS installed, version of GLFW to make my project more portable. I am trying to use both premake and gcc directly but they both fail.

The glfw directory is in project/libraries/glfw-3.2.1

I tried to build glfw by doing:

cd project/libraries/glfw-3.2.1
mkdir bin
cd bin
cmake ..
make all

however I do not see any binary on that directory although I did find the file libglfw3.a

So I tried to build it manually as follows:

g++ main.cpp -I libraries/glfw-3.2.1/include/ -L libraries/glfw-3.2.1/bin/src/libglfw3.a

However that fails to link as none of the glfw objects are found. i.e I get errors like:

/usr/bin/ld: main.cpp:(.text+0x27): undefined reference to `glfwWindowHint'

Solution

  • try this

    g++ main.cpp -I libraries/glfw-3.2.1/include -L libraries/glfw-3.2.1/bin/src -lglfw3
    

    Using -L you are telling the compiler where the library lies but you should use -l to link it