MinGW Linking/compiling problems with Example 1 Hello World

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
knicholes
Posts: 14
Joined: Sat Aug 30, 2008 8:21 pm

MinGW Linking/compiling problems with Example 1 Hello World

Post by knicholes »

I have inserted the code for example 1 for irrlicht into MinGW Developer Studio. I configured the setup to look for the .lib files in the \lib\Win32-visualstudio. The mingw version I'm compiling with is the most recent.

It compiles just fine, but when I tell it to execute I get the following error:

###################################
###################################

Linking...
D:\MinGWStudio\CS3540Test\Debug\main.o: In function `ZN3irr4core12irrAllocatorIcE12internal_newEj':
C:\Documents and Settings\Kelly\Desktop\CS3540\irrlicht-1.3.1\include\irrAllocator.h:(.text+0x9b): undefined reference to `_imp___ZN3irr12createDeviceENS_5video13E_DRIVER_TYPEERKNS_4core11dimension2dIiEEjbbbPNS_14IEventReceiverEPKc'
collect2: ld returned 1 exit status

CS3540Test.exe - 1 error(s), 0 warning(s)

--------------------Configuration: CS3540Test - Release--------------------
Compiling source file(s)...
main.cpp
main.cpp:50:2: warning: no newline at end of file
Linking...
D:\MinGWStudio\CS3540Test\Release\main.o:main.cpp:(.text+0x6d): undefined reference to `_imp___ZN3irr12createDeviceENS_5video13E_DRIVER_TYPEERKNS_4core11dimension2dIiEEjbbbPNS_14IEventReceiverEPKc'
collect2: ld returned 1 exit status

CS3540Test.exe - 1 error(s), 1 warning(s)

####################################
####################################

I found a fix where a guy recompiled the .dlls for irrlicht to work for mingw (http://irrlicht.sourceforge.net/phpBB2/ ... c3c0114f70), I updated my direct9x redistributable, and I copied his new files over my 1.3.1 installation, but it still won't work.

What can I do to get this to compile/link properly? I read something about converstions from one type of object not being the same as what MinGW uses? Is there any easier way to compile this code and have it work with some different compiler?

Any help would be appreciated! Thank you!
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: MinGW Linking/compiling problems with Example 1 Hello Wo

Post by randomMesh »

knicholes wrote:I configured the setup to look for the .lib files in the \lib\Win32-visualstudio.
Wrong, wrong, wrong! Use the one in "lib\Win32-gcc".

MinGW is GCC.
knicholes
Posts: 14
Joined: Sat Aug 30, 2008 8:21 pm

Oh-- -haha

Post by knicholes »

That's embarrassing! Thanks for the clarification. So I switched to the lib\Win32-gcc directory for the "Library Files" directory. I get this error message:

--------------------Configuration: CS3540Test - Debug--------------------
Linking...
D:\MinGWStudio\CS3540Test\Debug\main.o: In function `ZN3irr4core12irrAllocatorIcE12internal_newEj':
C:\Documents and Settings\Kelly\Desktop\CS3540\irrlicht-1.3.1\include\irrAllocator.h:(.text+0x9b): undefined reference to `_imp___ZN3irr12createDeviceENS_5video13E_DRIVER_TYPEERKNS_4core11dimension2dIiEEjbbbPNS_14IEventReceiverEPKc'
collect2: ld returned 1 exit status

CS3540Test.exe - 1 error(s), 0 warning(s)

Help!! :)
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Re: Oh-- -haha

Post by randomMesh »

Seems like both error mesage were the same, weren't they?
knicholes
Posts: 14
Joined: Sat Aug 30, 2008 8:21 pm

Yeah

Post by knicholes »

Yeah, they seem the same. I think the problem is the same-- It's just having problems linking? It looks like it's going to the right place to link, it's just having some issue with the function names? I don't know. I read the forum a bunch and other people have similar problems, but I can't understand what they're talking about.
CuteAlien
Admin
Posts: 9720
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

I have the feeling you still don't link to the correct lib. The library should be an import library and the real object should actually be in the dll. Check for the size of the .a - it shouldn't have several MB.

edit: Maybe also look for it in bin/Win32-gcc, if you compiled the lib itself with Codeblocks I think it might put it in there (because you can't set two different output folders for the .dll and the .a in c::b).

I also tried creating a static library with MinGW the last days, but currently I also fail to get that linked (with the same error). Not sure why. So for now I just use the import library + dll combination.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
knicholes
Posts: 14
Joined: Sat Aug 30, 2008 8:21 pm

Still trying!!

Post by knicholes »

So I've added both of the folders you have recommended into my MinGW Developer Studio directory for "Library Files." I've verified that there are .a files in both folders, the \bin\Win32-GCC and \lib\Win32-GCC. The .a files are both 3kb. the \bin\Win32-GCC folder contains a Irrlicht.dll. I'm guessing that's the library I need to link to?

This is my time time using dlls and .a files, so I have no idea what they even mean and how they work. I get this error:

Linking...
D:\MinGWStudio\CS3540Test\Debug\main.o: In function `ZN3irr4core12irrAllocatorIcE12internal_newEj':
C:\Documents and Settings\Kelly\Desktop\CS3540\irrlicht-1.3.1\include\irrAllocator.h:(.text+0x9b): undefined reference to `_imp___ZN3irr12createDeviceENS_5video13E_DRIVER_TYPEERKNS_4core11dimension2dIiEEjbbbPNS_14IEventReceiverEPKc'

This is still probably the same error. I'll check once I post this and compare them.

When I look in the libIrrlicht.DEF file, I see this

EXPORTS
_ZN3irr12createDeviceENS_5video13E_DRIVER_TYPEERKNS_4core11dimension2dIiEEjbbbPNS_14IEventReceiverEPKc @1
_ZN3irr14createDeviceExERKNS_27SIrrlichtCreationParametersE @2


It's the exact same name as in the error. Do I have to move the DLL to any folder or is just telling the compiler where the .dll is enough? Does the .a file just explain what to do with the .dll?
CuteAlien
Admin
Posts: 9720
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

The import library (.a) basically is a placeholder for shared libraries (.so or .dll). It contains not much more than the function names so you can link it to your binary. The real code of the functions is loaded later on (at runtime) from the dll. (info: static libraries are also called .a (in gcc) or .lib (with ms compiler) but are larger as they contain the real functions so they don't get loaded from dll later on but are linked directly into your executable).

If the same name is in several folders it will only use the first. I don't know exactly which one is the correct one, just try removing the other folder. I suppose for MinGW you should use the one in bin/Win32-gcc. Don't care much about the dll. This is only needed once you are able to start your application (and it will complain then if that is missing). Right now it's not linking to the correct .a file.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
knicholes
Posts: 14
Joined: Sat Aug 30, 2008 8:21 pm

Post by knicholes »

Oh great! Thank you for the clarification! Unfortunately I still have no clue what I need to do to get it to link. I've tried 1.3.1 and 1.4.1 and nothing works. I've tried copying the .a file to pretty much every file there is, including the minggw project folder and other folders within. Does anyone else have any other ideas? I just can't get it to link!

Please help!
knicholes
Posts: 14
Joined: Sat Aug 30, 2008 8:21 pm

Post by knicholes »

Oh sweet!!!!! I figured it out! I just went to the "Project" tab in MinGW Developer Studio and clicked settings. Then I clicked on the "Link" tab and input the .a path and filename! It totally compiles and links now, but still has an error-- something about being unable to find the ../../media/sydney.md2. Thanks for explaining all of the file extensions to me. I never would have figured it out without your help!

Thanks again
CuteAlien
Admin
Posts: 9720
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Glad to hear it works. If data is not found, that's probably because the path to the data in the sources is not pointing to the media folder. Look in the source where ../../media/sydney.md is loaded and make the path relative to your working directory (I think you can also set that in codeblocks somewhere).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply