Linking GLFW Dependencies in Code::Blocks

I'm having issues figuring out what libraries I need to link to run this program:

1
2
3
4
5
6
7
8
#include<cstdlib>
#include<GLFW/glfw3.h>

int main(){
    glfwInit();
    glfwTerminate();
    return EXIT_SUCCESS;
}


In linker settings I have glfw3 and GL, in that order.

When trying to build and run the program, I get the following output from the build log:

/usr/bin/ld: /usr/local/lib/libglfw3.a(x11_window.c.o): undefined reference to symbol 'XConvertSelection'
/usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
2 error(s), 0 warning(s) (0 minute(s), 0 second(s))


I'm using Code::Blocks SVN 10321 and Ubuntu 15.04
Last edited on
> undefined reference to symbol 'XConvertSelection'
you need to link against X11
-lX11


> In linker settings I have glfw3 and GL, in that order.
if you are using dynamic libraries the order is irrelevant
if you are using static libraries the order is a PIA
I'll recommend you to use pkg-config to resolve all the dependencies correctly


Edit: didn't notice your code before. I can build perfectly fine with just -lglfw
Last edited on
How can I link it dynamically?

I got GLFW using the following commands:
1
2
3
4
5
6
7
8
9
cd ~/Downloads
wget https://github.com/glfw/glfw/releases/download/3.1.1/glfw-3.1.1.zip
unzip glfw-3.1.1.zip
cd glfw-3.1.1
sudo apt-get install cmake
sudo apt-get build-dep glfw3
cmake .
make
sudo make install


I don't know if I did this right or not.

I tried adding X11 and now I have a new error:
undefined reference to symbol 'XF86VidModeQueryExtension'


After that I added Xxf86vm and got this:
undefined reference to symbol 'pthread_key_delete@@GLIBC_2.2.5'


So I added pthread, then got this:
/usr/local/lib/libglfw3.a(x11_init.c.o): In function `initExtensions':
x11_init.c:(.text+0x1a26): undefined reference to `XRRQueryExtension'
x11_init.c:(.text+0x1a7d): undefined reference to `XRRQueryVersion'
x11_init.c:(.text+0x1afa): undefined reference to `XRRGetScreenResources'
x11_init.c:(.text+0x1b2d): undefined reference to `XRRGetCrtcGammaSize'
x11_init.c:(.text+0x1b61): undefined reference to `XRRFreeScreenResources'
x11_init.c:(.text+0x1b93): undefined reference to `XineramaQueryExtension'
x11_init.c:(.text+0x1bad): undefined reference to `XineramaIsActive'
x11_init.c:(.text+0x1c5e): undefined reference to `XIQueryVersion'
/usr/local/lib/libglfw3.a(x11_init.c.o): In function `_glfwCreateCursor':
x11_init.c:(.text+0x22ee): undefined reference to `XcursorImageCreate'
x11_init.c:(.text+0x23c5): undefined reference to `XcursorImageLoadCursor'
x11_init.c:(.text+0x23d5): undefined reference to `XcursorImageDestroy'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwSetVideoMode':
x11_monitor.c:(.text+0x331): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0x360): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0x38c): undefined reference to `XRRGetOutputInfo'
x11_monitor.c:(.text+0x4b9): undefined reference to `XRRSetCrtcConfig'
x11_monitor.c:(.text+0x4c9): undefined reference to `XRRFreeOutputInfo'
x11_monitor.c:(.text+0x4d5): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x4e1): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwRestoreVideoMode':
x11_monitor.c:(.text+0x594): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0x5c0): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0x630): undefined reference to `XRRSetCrtcConfig'
x11_monitor.c:(.text+0x640): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x64c): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetMonitors':
x11_monitor.c:(.text+0x6e5): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0x710): undefined reference to `XRRGetOutputPrimary'
x11_monitor.c:(.text+0x743): undefined reference to `XineramaQueryScreens'
x11_monitor.c:(.text+0x788): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0x7cd): undefined reference to `XRRGetOutputInfo'
x11_monitor.c:(.text+0x7ea): undefined reference to `XRRFreeOutputInfo'
x11_monitor.c:(.text+0x9fc): undefined reference to `XRRFreeOutputInfo'
x11_monitor.c:(.text+0xa82): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0xaa2): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetMonitorPos':
x11_monitor.c:(.text+0xc31): undefined reference to `XRRGetScreenResourcesCurrent'
x11_monitor.c:(.text+0xc5d): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0xc95): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0xca1): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetVideoModes':
x11_monitor.c:(.text+0xd1f): undefined reference to `XRRGetScreenResourcesCurrent'
x11_monitor.c:(.text+0xd4b): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0xd74): undefined reference to `XRRGetOutputInfo'
x11_monitor.c:(.text+0xeb2): undefined reference to `XRRFreeOutputInfo'
x11_monitor.c:(.text+0xebe): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0xeca): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetVideoMode':
x11_monitor.c:(.text+0xf7a): undefined reference to `XRRGetScreenResourcesCurrent'
x11_monitor.c:(.text+0xfa6): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0xffe): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x100a): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetGammaRamp':
x11_monitor.c:(.text+0x1146): undefined reference to `XRRGetCrtcGammaSize'
x11_monitor.c:(.text+0x1170): undefined reference to `XRRGetCrtcGamma'
x11_monitor.c:(.text+0x11fc): undefined reference to `XRRFreeGamma'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformSetGammaRamp':
x11_monitor.c:(.text+0x1303): undefined reference to `XRRAllocGamma'
Process terminated with status 1 (0 minute(s), 0 second(s))
50 error(s), 0 warning(s) (0 minute(s), 0 second(s))


Not sure what else needs linking from there.
> How can I link it dynamically?
first you need to build the dynamic libraries
http://www.glfw.org/docs/latest/compile.html#compile_options_shared
cmake -DBUILD_SHARED_LIBS=ON .
iirc the linking would default to shared libraries, if you want static need to pass the -static flag.
you'll also may write the full path of the library, .so is dynamic, .a is static.


About linking, read http://www.glfw.org/docs/latest/build.html#build_link
Again, I'll suggest you to use pkg-config
http://www.glfw.org/docs/latest/build.html#build_link_pkgconfig
Ok so appears to work if I just use -lglfw, but not if I use -lglfw3. With just -glfw, I don't need anything else linked. Would -lglfw have the same functionality as -lglfw3?
I'll suppose that glfw refers to version 2
jhere's a list of differences http://www.glfw.org/docs/3.0/moving.html
Topic archived. No new replies allowed.