Francis
Francis

Reputation: 1151

Build a program with GLFW3 on Linux

I know this question has been asked many times before but I have been trying to get this working for days and none of the current answers solve my problem. I'd appreciate not being linked to this post: How to build & install GLFW 3 and use it in a Linux project Most of the answers I have seen redirect there but I have gone through it thoroughly and am still having problems.

I am running Linux Mint 17.1.

I have downloaded and built GLFW 3.1.1:

*Downloaded source; extracted; terminal to extract directory*
cmake .
make install

I have also downloaded the example program at http://www.glfw.org/docs/3.0/quick.html#quick_example

I am using the following build commands:

g++ -std=c++11 -c HelloGLFW.cpp
g++ HelloGLFW.o -o main.exec -lGL -lGLU -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -lXi

The program compiles fine but when I try to link it I get these errors:

//usr/local/lib/libglfw3.a(x11_init.c.o): In function `initExtensions':
x11_init.c:(.text+0x1aeb): undefined reference to `XineramaQueryExtension'
x11_init.c:(.text+0x1b05): undefined reference to `XineramaIsActive'
//usr/local/lib/libglfw3.a(x11_init.c.o): In function `_glfwCreateCursor':
x11_init.c:(.text+0x21f9): undefined reference to `XcursorImageCreate'
x11_init.c:(.text+0x22d0): undefined reference to `XcursorImageLoadCursor'
x11_init.c:(.text+0x22e0): undefined reference to `XcursorImageDestroy'
//usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetMonitors':
x11_monitor.c:(.text+0x6e9): undefined reference to `XineramaQueryScreens'
collect2: error: ld returned 1 exit status

I have also gone through the instructions on the GLFW website but they seem to be quite lacking for Linux. I have gotten it working on Linux before but that was a year ago and I can't replicate it.

Can someone please let me know all the steps required to build a program with GLFW3 on Linux (including all dependencies required)?

Upvotes: 1

Views: 1950

Answers (1)

Francis
Francis

Reputation: 1151

When glfw3 was installed using cmake a file glfw3.pc was created along with it. This is a pkg-config file and lists what libraries are required for linking.

For me this file was located in /usr/local/lib/pkgconfig

The command I used to successfully build the program with was:

g++ HelloGLFW.cpp -lglfw3 -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor -lGL -lpthread

The GLFW site does list details at http://www.glfw.org/docs/latest/build.html#build_link_pkgconfig but it's a bit unclear what to look for if you aren't that familiar with Linux systems.

Specificity the instructions list this command for compiling with the static glfw3 library:

cc `pkg-config --cflags glfw3` -o myprog myprog.c `pkg-config --static --libs glfw3`

and with the dynamic glfw3 library:

cc `pkg-config --cflags glfw3` -o myprog myprog.c `pkg-config --libs glfw3`

Upvotes: 3

Related Questions