# Compiling using GCC through MSYS...

This topic is 3868 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey folks! The project I'm currently working upon requires my C++ code to call a Fortran 90 library, and as VS8 Express doesn't support this I've started using the GCC compiler through the MSYS command line interface. I am however running into one or two issues. Upon compilation I recieve a string of errors, of the type "undefined reference to <function name>". All the functions that the compiler is having trouble with appear to be common C++ calls, e.g.: C:/DOCUME~1/JAMESD~1/LOCALS~1/Temp/ccySaaaa.o(.text+0x37):Application_Main.cpp: undefined reference to operator new[](unsigned)' C:/DOCUME~1/JAMESD~1/LOCALS~1/Temp/ccySaaaa.o(.text+0x1120):Application_Main.cpp: undefined reference to __gxx_personality_sj0' C:/DOCUME~1/JAMESD~1/LOCALS~1/Temp/ccySaaaa.o(.text+0x11f7):Application_Main.cpp: undefined reference to _imp___ZN3irr12createDeviceENS_5video13E_DRIVER_TYPEERKNS_4core11dimension2dIiEEjbbbPNS_14IEventReceiverEPKc' C:/DOCUME~1/JAMESD~1/LOCALS~1/Temp/ccySaaaa.o(.text+0x1b2f):Application_Main.cpp: undefined reference to operator new(unsigned)' C:/DOCUME~1/JAMESD~1/LOCALS~1/Temp/ccySaaaa.o(.text+0x1b92):Application_Main.cpp: undefined reference to operator delete(void*)' This is just a few of many, so if any further need to be posted just let me know. My current command for compilation is as follows (im using the Irrlicht engine): gcc Application_Main.cpp -I../irrlicht-1.3/include/ -I../irrlicht-1.3/source/Irrlicht/ -I/C/Program\ Files\Microsoft\ Platform\ SDK\ for\ Windows\ Server\ 2003\ R2/Include/ Am I missing an important include folder, or file to link? I feel a bit like a fish out of water jumping from Visual Studio to a command line compiler. Thankyou for all your help, it is very much appreciated!

##### Share on other sites
You have two choices, use g++ instead of gcc or pass the standard C++ library to link against (-lstdc++).

##### Share on other sites
Ah thankyou, using g++ removed every error but one...

I'm guessing that's something to do with the Irrlicht engine. I'm sure a browse of the internet will provide an answer. :)

##### Share on other sites
Quote:
 Original post by HelderashAh thankyou, using g++ removed every error but one...C:/DOCUME~1/JAMESD~1/LOCALS~1/Temp/ccofbaaa.o(.text+0x11f7):Application_Main.cpp: undefined reference to _imp___ZN3irr12createDeviceENS_5video13E_DRIVER_TYPEERKNS_4core11dimension2dIiEEjbbbPNS_14IEventReceiverEPKc'I'm guessing that's something to do with the Irrlicht engine. I'm sure a browse of the internet will provide an answer. :)

Yeah, that's a linker error. In this case it's telling you that Applicaion_Main.cpp has promised the existence of something in another file. During the linking phase the linker looked for that something and couldn't find it in any of the libraries or object files that were already compiled.

The reference's name was mangled (the linker doesn't know what the original looked like). The first part specifies things like return type, the middle part is probably the name of the function, and the rest is the parameters that were passed(including their types). Basically, the linker can't find CreateDevice anywhere (create device is apparenlty described in detail here)

I don't use g++ much (except through an IDE) so I'm not sure how to link in libraries, but the library you may be interested in is libIrrlicht.a I bet the command is -llibIrrlicht though, it looks right to me

##### Share on other sites
Quote:

The _imp__ tells you you're looking for a symbol in a DLL linklib (that is, as static library used to link in a DLL).

The demangled name of the function is
irr::createDevice(irr::video::E_DRIVER_TYPE,                  irr::core::dimension2d<int> const&,                  unsigned int,                  bool,                  bool,                  bool,                  irr::IEventReceiver*,                  char const*)

which does sound an awful lot like the irrlicht library. Double-check to make sure the .LIB (or .a or .dll.a) file appears on the link line, and remember that order is important when it comes to static libraries that appear on the link line.

##### Share on other sites
Changing the compile command to:

g++ Application_Main.cpp -I../irrlicht-1.3/include/ -I. -I../irrlicht-1.3/source/Irrlicht/ -I/C/Program\ Files\Microsoft\ Platform\ SDK\ for\ Windows\ Server\ 2003\ R2/Include/ -l../irrlicht-1.3/lib/Win32-gcc/libIrrlicht.a

C:\MinGW\bin\..\lib\gcc-lib\mingw32\3.2.3\..\..\..\..\mingw32\bin\ld.exe: cannot find -l../irrlicht-1.3/lib/Win32-gcc/libIrrlicht.a

I've double checked and that file definately exists in that folder, so I'm very confused about what could be going wrong now.

Thanks for the help so far everyone. :)

##### Share on other sites
Try:

g++ Application_Main.cpp -I../irrlicht-1.3/include/ -I. -I../irrlicht-1.3/source/Irrlicht/ -I/C/Program\ Files\Microsoft\ Platform\ SDK\ for\ Windows\ Server\ 2003\ R2/Include/ -L../irrlicht-1.3/lib/Win32-gcc -lIrrlicht

ld expects -l to give the library name without the path, "lib" and ".a". The -L option adds the irrlicht lib directory to the list of directories ld searches.

##### Share on other sites
That worked perfectly Dave, thankyou very much!

Now just to find out how to compile the Direct3D9 drivers into the Irrlicht.dll. Running the compiled exe file currently gives the error: DIRECT3D9 Driver was not compiled into this dll. Try another one. I'm pretty certain there will be something in the documentation about this though.

##### Share on other sites
Quote:
 Original post by HelderashThat worked perfectly Dave, thankyou very much!Now just to find out how to compile the Direct3D9 drivers into the Irrlicht.dll. Running the compiled exe file currently gives the error: DIRECT3D9 Driver was not compiled into this dll. Try another one. I'm pretty certain there will be something in the documentation about this though.

You will probably need to copy over the DXSDK headers into your mingw instalation include directory, or use -I/path/to/dx/headers on your CXXFLAGS, then you need to use reimp on the DX lib files in order to get libX.a libraries suitable for MinGW (you copy those into /lib), you can also pass the .lib files as if they were object files, but I find the -l format more elegant, its up to you though.

If you're using autotools (./configure) then you have to find out how is Irrlich expecting to find the library files though.

##### Share on other sites
Hey everyone! Thankyou very much for the help so far!

I do seem to be making some progress, though building the Irrlicht.dll is still proving troublesome. The build is failing, yet the compiler is giving no reason for the error so I'm a little lost. The output i'm getting is:

In file included from c:/DX90SDK/Include/d3d9.h:199,
from CD3D9Driver.h:18,
from CD3D9Driver.cpp:9:
c:/DX90SDK/Include/d3d9types.h:25: warning: ignoring #pragma warning
c:/DX90SDK/Include/d3d9types.h:1789: warning: ignoring #pragma warning
In file included from c:/DX90SDK/Include/d3dx9.h:45,
from CD3D9Driver.cpp:18:
c:/DX90SDK/Include/d3dx9math.h:19: warning: ignoring #pragma warning
In file included from c:/DX90SDK/Include/d3dx9.h:45,
from CD3D9Driver.cpp:18:
c:/DX90SDK/Include/d3dx9math.h:1755: warning: ignoring #pragma warning
In file included from c:/DX90SDK/Include/d3dx9.h:46,
from CD3D9Driver.cpp:18:
c:/DX90SDK/Include/d3dx9core.h:636:1: warning: multi-line comment
In file included from c:/DX90SDK/Include/d3dx9mesh.h:15,
from c:/DX90SDK/Include/d3dx9.h:47,
from CD3D9Driver.cpp:18:
c:/DX90SDK/Include/dxfile.h:240: stray '\32' in program
In file included from c:/DX90SDK/Include/d3dx9mesh.h:15,
from c:/DX90SDK/Include/d3dx9.h:47,
from CD3D9Driver.cpp:18:
c:/DX90SDK/Include/dxfile.h:240:2: warning: no newline at end of file
CD3D9Driver.cpp: In member function virtual void
irr::video::CD3D9Driver::drawVertexPrimitiveList(const void*, unsigned int,
const u16*, unsigned int, irr::video::E_VERTEX_TYPE,
irr::scene::E_PRIMITIVE_TYPE)':
CD3D9Driver.cpp:867: warning: enumeration value EPT_QUAD_STRIP' not handled in
switch
CD3D9Driver.cpp:867: warning: enumeration value EPT_QUADS' not handled in
switch
CD3D9Driver.cpp:867: warning: enumeration value EPT_POLYGON' not handled in
switch
make: *** [CD3D9Driver.o] Error 1

I've checked through the entire output log, and though there are numerous warnings there aren't any errors. Would there be any reason why the g++ compiler wouldn't output the reason for a build fail?

##### Share on other sites
Weird, are you using -Werror? that means threat warnings as errors, which could be a cause.

##### Share on other sites
Quote:
 Original post by Helderashmake: *** [CD3D9Driver.o] Error 1I've checked through the entire output log, and though there are numerous warnings there aren't any errors. Would there be any reason why the g++ compiler wouldn't output the reason for a build fail?

(1) Are you building with -Werror (which treats warnings as errors)?
(2) Is it the compiler that's failing or is it another make rule that's failing?
(3) Are your sure that "stray '\32'" message is not an error? Try fixing that and recompiling.

##### Share on other sites
Removing the stray \32 from the DirectX header file did allow the compiler to move on. It's now failing when it reaches the library linking, as it doesn't like the DirectX .lib files, e.g:

c:/DX90SDK/Lib/\d3dx9.lib(obj/i386/ctransform.obj)(.text+0x3e7):..\ctransform.cpp: undefined reference to ??3@YAXPAX@Z'

I guess this is to do with MinGW disliking .lib files as you mentioned. I have tried using reimp, but it seems to fill the folder with a large number of files with numbers as names. Am I doing something incorrectly?

Thankyou all for the help with this, hopefully it's not too much further from the end.

##### Share on other sites
Quote:
 Original post by Helderashc:/DX90SDK/Lib/\d3dx9.lib(obj/i386/ctransform.obj)(.text+0x3e7):..\ctransform.cpp: undefined reference to ??3@YAXPAX@Z'I guess this is to do with MinGW disliking .lib files as you mentioned. I have tried using reimp, but it seems to fill the folder with a large number of files with numbers as names. Am I doing something incorrectly?Thankyou all for the help with this, hopefully it's not too much further from the end.

Yes, seems like your d3dx9.lib is a static library and not a reference library for a dll, sadly, reimp wont work on it, but luckily d3dx was moved from static to DLL more than a year ago, so it should work with a fairly recent release of the DX SDK, how old is yours anyway? just in case, the latest that will work on Windows 2000 is April 2005 (or was it 06?), if you have any later version of Windows, there probably is month or so old release by now (The SDK that works on Windows 2000 already moved d3dx to a dll).

##### Share on other sites
Checking through the DX releases the last one to support Windows 2000 was Decemember 2004, which I'm downloading now (I am a Windows 2000 user at the moment).

Hopefully this one will work too.. I guess I'll find out once its downloaded.

##### Share on other sites
I built a new machine today, and am having to go through the whole process again. I made notes of everything I did previously, and thought it would be a simple case of following instructions. I have come across a new error however:

g++ -I../../include -Izlib -Ijpeglib -Ilibpng -I/C/Program\ Files/Microsoft\ DirectX\ 9.0\ SDK\ (December\ 2004)/Include/ -DIRRLICHT_EXPORTS=1 -MM -MF CGUISpriteBank.d CGUISpriteBank.cpp
/bin/sh.exe: -c: line 1: syntax error near unexpected token (D'
/bin/sh.exe: -c: line 1: `g++ -I../../include -Izlib -Ijpeglib -Ilibpng -I/C/Program\ Files/Microsoft\ DirectX\ 9.0\ SDK\ (December\ 2004)/Include/ -DIRRLICHT_EXPORTS=1 -MM -MF CGUISpriteBank.d CGUISpriteBank.cpp'
make: *** [CGUISpriteBank.d] Error 2

I checked CGUISpriteBank.cpp but there appears to be nothing wrong with it.

[EDIT] The problem appears to be with sh.exe disliking backslashes. I could potentially solve the problem by moving files to locations with no filename gaps.

Thankyou very much for your help so far Kwizatz, I very much appreciate it!

##### Share on other sites
Quote:
 Original post by HelderashThankyou very much for your help so far Kwizatz, I very much appreciate it!

No problem.

Actually the problem I think is that the parentheses characters require escaping just like spaces so change (December\ 2004) to $$December\ 2004$$

##### Share on other sites

This topic is 3868 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628698
• Total Posts
2984274

• 20
• 9
• 13
• 13
• 11