Compiling using GCC through MSYS...

Started by
15 comments, last by Kwizatz 16 years, 11 months ago
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!
Advertisement
You have two choices, use g++ instead of gcc or pass the standard C++ library to link against (-lstdc++).
Ah 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. :)
Quote:Original post by Helderash
Ah 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

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

Quote:Original post by Helderash
_imp___ZN3irr12createDeviceENS_5video13E_DRIVER_TYPEERKNS_4core11dimension2dIiEEjbbbPNS_14IEventReceiverEPKc


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.

Stephen M. Webb
Professional Free Software Developer

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

produces the following error instead:

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. :)
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.
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.
Quote:Original post by Helderash
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.


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.
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 c:/DX90SDK/Include/d3dx9shader.h:10,
from CD3D9ShaderMaterialRenderer.h:13,
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 c:/DX90SDK/Include/d3dx9shader.h:10,
from CD3D9ShaderMaterialRenderer.h:13,
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 c:/DX90SDK/Include/d3dx9shader.h:10,
from CD3D9ShaderMaterialRenderer.h:13,
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 c:/DX90SDK/Include/d3dx9shader.h:10,
from CD3D9ShaderMaterialRenderer.h:13,
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 c:/DX90SDK/Include/d3dx9shader.h:10,
from CD3D9ShaderMaterialRenderer.h:13,
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?

This topic is closed to new replies.

Advertisement