1
\$\begingroup\$

Currently I'm using this tutorial to get started with opengl.So when I try to compile the example program :

#include <GLFW/glfw3.h>
#include <thread>

int main()
{
    glfwInit();
    std::this_thread::sleep_for(std::chrono::seconds(1));
    glfwTerminate();
}

using

g++ test.cpp -o test -lglfw3

to ensure that all is good with glfw I get this

In file included from /usr/include/c++/4.8/thread:35:0, from test.cpp:2: /usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options. #error This file requires compiler and library support for the \ ^ test.cpp: In function ‘int main()’: test.cpp:7:10: error: ‘std::this_thread’ has not been declared std::this_thread::sleep_for(std::chrono::seconds(1)); ^ test.cpp:7:38: error: ‘std::chrono’ has not been declared std::this_thread::sleep_for(std::chrono::seconds(1));

So then I guessed I could use the flag that g++ suggested and compile it using

g++ -std=c++11 test.cpp -o test -lglfw3

But then things get weirder and g++ comes with this error(I will post only a part of it since it's a huge output overall but you will probably get the idea) :

x11_window.c:(.text+0x2d9): undefined reference to XSaveContext' x11_window.c:(.text+0x324): undefined reference to XChangeWindowAttributes' x11_window.c:(.text+0x3be): undefined reference to XSetWMProtocols' x11_window.c:(.text+0x417): undefined reference toXChangeProperty' x11_window.c:(.text+0x41c): undefined reference to XAllocWMHints' x11_window.c:(.text+0x48e): undefined reference toXSetWMHints' x11_window.c:(.text+0x49d): undefined reference to XFree' x11_window.c:(.text+0x4a2): undefined reference toXAllocSizeHints' x11_window.c:(.text+0x5ed): undefined reference to XSetWMNormalHints' x11_window.c:(.text+0x5fc): undefined reference toXFree' x11_window.c:(.text+0x613): undefined reference to XAllocClassHint' x11_window.c:(.text+0x66c): undefined reference to XSetClassHint' x11_window.c:(.text+0x67b): undefined reference to XFree' x11_window.c:(.text+0x6dc): undefined reference to XISelectEvents' x11_window.c:(.text+0x71e): undefined reference to XRRSelectInput' //usr/local/lib/libglfw3.a(x11_window.c.o): In functionhideCursor': x11_window.c:(.text+0x7bd): undefined reference to XUngrabPointer' x11_window.c:(.text+0x7fb): undefined reference to XDefineCursor' //usr/local/lib/libglfw3.a(x11_window.c.o): In function captureCursor': x11_window.c:(.text+0x880): undefined reference toXGrabPointer' //usr/local/lib/libglfw3.a(x11_window.c.o): In function `showCursor':

How could I fix this type of problem cause it really hurts my motivation to get into opengl. And please if you have in mind any better-hassle free guide for setting a proper opengl environment for deving with glfw and glew in linux/ubuntu , care to mention it.

UPDATE 1: http://pastebin.com/CPEwmbUZ <--- The whole output is here if anyone cares.

\$\endgroup\$
1
\$\begingroup\$

Error undefined reference means that linker can't find function's definition. Probably, you should link X11 library to your program by console parameter -lX11. So, it should be g++ -std=c++11 test.cpp -o test -lglfw3 -lX11. I think you should link OpenGL library too (by -lGL).

\$\endgroup\$
  • \$\begingroup\$ Well I used this command : g++ -std=c++11 test.cpp -o test -lglfw3 -lX11 -lGL and I'm getting this, shorter , error : /usr/bin/ld: //usr/local/lib/libglfw3.a(x11_init.c.o): undefined reference to symbol 'XF86VidModeQueryExtension' //usr/lib/x86_64-linux-gnu/libXxf86vm.so.1: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status \$\endgroup\$ – user3385993 Nov 27 '14 at 11:20
  • \$\begingroup\$ try to add -lXxf86vm -L/user/lib/x86_64-linux-gnu/ to command. This should fix errors. \$\endgroup\$ – Kostya Regent Nov 27 '14 at 14:13
  • 1
    \$\begingroup\$ g++ -std=c++11 test.cpp -o test -lglfw3 -lX11 -lGL -lXxf86vm -L/user/lib/x86_64-linux-gnu/ Gives this error : /usr/bin/ld: //usr/local/lib/libglfw3.a(glx_context.c.o): undefined reference to symbol 'pthread_key_delete@@GLIBC_2.2.5' //lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status I feel so stupid wasting your time but really why is it so complicated for such a small program. Well I hope I will manage it once I find the right commands. \$\endgroup\$ – user3385993 Nov 27 '14 at 15:35
  • \$\begingroup\$ Add -lpthread. If you have undefined reference to symbol compilation error of function from some other library (not your function), that often means, that you forgot to add library. You can find in "google" what library you should add by request "undefined reference to symbol 'pthread_key_delete'". That's not always clear to understand what library you need, but it's works. In your case, you need this library because you use #include <thread>. \$\endgroup\$ – Kostya Regent Nov 27 '14 at 16:31
  • \$\begingroup\$ About -std=c++11. C++ language has different versions, C++11 means C++ with standart approved in 2011. I'm not sure that you need new features from C++11 version. Most of code examples from Internet use simple C++, so just delete std::this_thread::sleep_for(std::chrono::seconds(1)); and #include <thread>, and you wouldn't need to use -std=c++11. I would be happy to give you other guides, but I don't work with glfw library... \$\endgroup\$ – Kostya Regent Nov 27 '14 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.