Code::Blocks and Irrlicht in Linux

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
d3wu
Posts: 5
Joined: Sat May 06, 2006 1:06 am

Code::Blocks and Irrlicht in Linux

Post by d3wu »

i found the tutorial how to setup Irrlicht in Windows, but am having trouble in Linux.

http://irrlicht.sourceforge.net/tut_codeblocks.html

when I do the cmd make in the console for the Hello World example, everything works correctly.

but when using Code::Blocks, im getting linker errors when building. I went into Build Options -> Linker and tried to point to the lib file that the make file uses too. it looks like code::blocks still can't find it.

i also added the directory lib/Linux in the Linker directory path. any suggestions would help! thanks
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

To compile the engine in order to get the libraries created, I'd suggest simply going to your "source" folder, open a shell there and do a "make".

Once you get your libraries created then you can start using codeblocks to start projects using the project wizard for Irrlicht. Remember Codeblocks expects you to have irrlicht at /opt/irrlicht for things to work properly so even before compiling the engine make sure you have placed the Irrlicht files there and that you have read-write rights for tht folder.

If you get compiling errors then you might be having the problems Nvidia cards users are getting (the glXGetProcAddressARB issue). You might try and search the forums here for the fixes or modify the linux make file according to this tip:
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=11600

Let me know if it helps.
d3wu
Posts: 5
Joined: Sat May 06, 2006 1:06 am

Post by d3wu »

thanks for the tips

i did the steps but seem to get the same errors. here's a sample of the first couple lines in the console:

Linking console executable: HelloWorld.exe
../../lib/Linux/libIrrlicht.a(CIrrDeviceLinux.o): In function `irr::CIrrDeviceLinux::createWindow(irr::core::dimension2d<int> const&, unsigned int, bool, bool)':
CIrrDeviceLinux.cpp:(.text+0x66): undefined reference to `XOpenDisplay'
CIrrDeviceLinux.cpp:(.text+0xd5): undefined reference to `XF86VidModeQueryVersion'
CIrrDeviceLinux.cpp:(.text+0x12d): undefined reference to `XF86VidModeGetAllModeLines'
CIrrDeviceLinux.cpp:(.text+0x2b5): undefined reference to `glXChooseVisual'
CIrrDeviceLinux.cpp:(.text+0x31b): undefined reference to `glXChooseVisual'
CIrrDeviceLinux.cpp:(.text+0x367): undefined reference to `glXChooseVisual'

so it finds the library im pointing to but still has many undefined references. i feel like im just missing one little include somewhere. any insight?
mandrav
Posts: 117
Joined: Sat Aug 27, 2005 8:29 pm
Contact:

Post by mandrav »

Add the following libraries in "Project->Build options->[select the project in the tree]->Linker->Libraries"

Code: Select all

X11
Xext
Xxf86vm
d3wu
Posts: 5
Joined: Sat May 06, 2006 1:06 am

Post by d3wu »

i definitely see the makefile including those library files. if i try to just add those 3 to my linker->libraries, code::blocks complains about not finding it. so im guessing i have to add every library that the makefile is:

g++ main.cpp -o example -I"../../include" -I"/usr/X11R6/include" -L"/usr/X11R6/lib" -L"../../lib/Linux" -lIrrlicht -lGL -lGLU -lXxf86vm -lXext -lX11

can't seem to successfully add these in codeblocks
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

try to search for the libraries to be sure the path is correct. Either try 'locate libX11.so' or 'find / -name libX11.so' and add the path you find those libraries with -L/absolute/path/to/X11 into the makefile. There are sometimes different locations, esp. when using x64-Linux.
mandrav
Posts: 117
Joined: Sat Aug 27, 2005 8:29 pm
Contact:

Post by mandrav »

Add /usr/X11R6/lib in "Project->Build options->[select the project in the tree]->Directories->Linker".

You know, you have to learn a few things about how your compiler and linker works, before starting a big program on your own...

Whenever you see undefined symbols, it means the linker didn't find them. Essentially this means you didn't link with the required libraries. That's what my previous post told you to do.

After all needed libraries are defined you 're ready to link. If the linker complains that it can't find some of them it means, well, that it can't find them in its standard search path. You have to tell it where they are. What I told you at the start of this post, does just that: it tells the linker that additionally to wherever else it might search for libs, it should search in /usr/X11R6/lib also (that's where the X libs usually are - adjust for your system if needed).
d3wu
Posts: 5
Joined: Sat May 06, 2006 1:06 am

Post by d3wu »

i found all the libraries and directories i needed, and put them in the exact order as the make file did - it turns out they were in /usr/lib/

mandrav i understand that i need to find the libraries since they are missing, but i dont see which ones are needed without looking at the makefile, etc.

im down to just a couple other linker errors. its not clear to me which library should be added before these to prevent the errors. thanks for the help though - almost there.

Code: Select all

Linking console executable: HelloWorld.exe
/usr/lib/libGL.a(glxext.o): In function `init_thread_data':
: undefined reference to `pthread_key_create'
/usr/lib/libGL.a(glxext.o): In function `__glXSetCurrentContext':
: undefined reference to `pthread_once'
/usr/lib/libGL.a(glxext.o): In function `__glXSetCurrentContext':
: undefined reference to `pthread_setspecific'
/usr/lib/libGL.a(glxext.o): In function `__glXGetCurrentContext':
: undefined reference to `pthread_once'
/usr/lib/libGL.a(glxext.o): In function `__glXGetCurrentContext':
: undefined reference to `pthread_getspecific'
/usr/lib/libGL.a(glxext.o): In function `__glXInitialize':
: undefined reference to `drmUnmap'
/usr/lib/libGL.a(glxext.o): In function `__glXInitialize':
: undefined reference to `drmUnmap'
/usr/lib/libGL.a(glxext.o): In function `__glXInitialize':
: undefined reference to `drmClose'
/usr/lib/libGL.a(glxext.o): In function `__glXInitialize':
: undefined reference to `drmOpen'
/usr/lib/libGL.a(glxext.o): In function `__glXInitialize':
: undefined reference to `drmGetMagic'
/usr/lib/libGL.a(glxext.o): In function `__glXInitialize':
: undefined reference to `drmGetVersion'
/usr/lib/libGL.a(glxext.o): In function `__glXInitialize':
: undefined reference to `drmFreeVersion'
/usr/lib/libGL.a(glxext.o): In function `__glXInitialize':
: undefined reference to `drmMap'
/usr/lib/libGL.a(glxext.o): In function `__glXInitialize':
: undefined reference to `drmMap'
/usr/lib/libGL.a(dri_glx.o): In function `OpenDriver':
: undefined reference to `dlopen'
/usr/lib/libGL.a(dri_glx.o): In function `OpenDriver':
: undefined reference to `dlerror'
/usr/lib/libGL.a(dri_glx.o): In function `OpenDriver':
: undefined reference to `dlsym'
/usr/lib/libGL.a(dri_glx.o): In function `OpenDriver':
: undefined reference to `dlclose'
/usr/lib/libGL.a(dri_glx.o): In function `glXGetDriverConfig':
: undefined reference to `dlsym'
/usr/lib/libGL.a(dri_glx.o): In function `driDestroyDisplay':
: undefined reference to `dlclose'
/usr/lib/libGL.a(glapi.o): In function `_glapi_set_dispatch':
: undefined reference to `pthread_once'
/usr/lib/libGL.a(glthread.o): In function `_glthread_InitTSD':
: undefined reference to `pthread_key_create'
/usr/lib/libGL.a(glthread.o): In function `_glthread_SetTSD':
: undefined reference to `pthread_setspecific'
/usr/lib/libGL.a(glthread.o): In function `_glthread_GetTSD':
: undefined reference to `pthread_getspecific'
/usr/lib/libX11.a(ConnDis.o): In function `_X11TransConnectDisplay':
: undefined reference to `XauDisposeAuth'
/usr/lib/libX11.a(ConnDis.o): In function `_X11TransConnectDisplay':
: undefined reference to `XauGetBestAuthByAddr'
/usr/lib/libX11.a(CrGlCur.o): In function `open_library':
: undefined reference to `dlopen'
/usr/lib/libX11.a(CrGlCur.o): In function `fetch_symbol':
: undefined reference to `dlsym'
/usr/lib/libX11.a(CrGlCur.o): In function `fetch_symbol':
: undefined reference to `dlsym'
/usr/lib/libX11.a(XlcDL.o): In function `open_object':
: undefined reference to `dlopen'
/usr/lib/libX11.a(XlcDL.o): In function `fetch_symbol':
: undefined reference to `dlsym'
/usr/lib/libX11.a(XlcDL.o): In function `fetch_symbol':
: undefined reference to `dlsym'
/usr/lib/libX11.a(XlcDL.o): In function `close_object':
: undefined reference to `dlclose'
collect2: ld returned 1 exit status
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

-lpthread -lGLU -lGL -lX11 -ldl
d3wu
Posts: 5
Joined: Sat May 06, 2006 1:06 am

SOLVED

Post by d3wu »

i finally solved it :)

so i decided to do an Irrlicht Project Wizard. i compiled that and it worked perfectly. so i looked into that project's build options. and the only difference it had was the way it was linking the libraries:

I was putting in the exact path to the file

Code: Select all

../../lib/libIrrlicht.a
/usr/lib/libGLU.a
/usr/lib/libGL.a
/usr/lib/libXxf86vm.a
whereas the auto generated project was using

Code: Select all

Irrlicht
GLU
GL
Xxf86vm
I think I had the right idea initially along with the help from you guys, but I still don't get why pointing to the direct file wont work. also so many other errors popped up when i added X11 or Xevt.

im kinda confused about why the autogenerated project only requires those 4 libs when the makefile includes more - really weird but im glad i finally found out how to get it working. thanks for the help
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The best way is to add the libraries by name instead of the direct object. This introduces major trouble because all parts are added statically (usually most libraries are linked dynamically, using the .so files). X11 libraries cannot be linked statically by dault, you would need specially built libraries for that (or add c++ and c library statically as well, adding several megabytes). So add just the library (with -lname if dong it manually) because this will handle many things for you. If you want to add an archive (e.g. because you use the .a files just for convenience reasons) you have to handle them just as objects, so add them on a different level to the project.
Forgot one thing: Linking with some X helper libraries like you do can add X11 linking automatically. It's usually safer to link against X11 as well, though.
juantar
Posts: 9
Joined: Mon Apr 10, 2006 4:02 pm

Finally worked for Knoppix

Post by juantar »

For any new user wanting to compile it under Knoppix and Code blocks you must copy the libXxf86vm.so.1.0 library in the /usr/X11R6/lib/ and paste it there with the name libXxf86vm.so (without the 1.0). I did that and it worked for me (I hope this doesn't affect my system :D ).
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Better call ldconfig to update all symbolic links and the library/linker cache.
Post Reply