[SOLVED] Library Link error

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
abraker95
Posts: 10
Joined: Thu Sep 05, 2013 3:34 pm

[SOLVED] Library Link error

Post by abraker95 »

So I am doing a project with Irrlicht when I came into a problem figuring out some of the program's logic. I decided to take it apart and create a separate project for the problem to later merge it. Upon compiling that mini-project, I come across a rather illogical error. Ok, time to get back to baby steps and recompile something so simple:

This worries me:
x86_64-w64-mingw32-g++.exe -L..\..\lib\Win32-gcc -o ..\..\bin\Win32-gcc\HelloWorld.exe .objs\main.o C:\...\irrlicht-1.8\lib\Win32-gcc\libIrrlicht.a "C:\Program Files (x86)\CodeBlocks\mingw 4.7.0\x86_64-w64-mingw32\lib32\libIrrlicht.a"
.objs\main.o: In function `main':
C:/.../irrlicht-1.8/examples/01.HelloWorld/main.cpp:128: undefined reference to `__imp_createDevice'

The library is included, I know it is the right one version because I compiled it from scratch, and I have no problem compiling and linking my other project. I played around with my compiler and linker options as well with no avail.

GNU GCC 4.7.0
Irrlicht 1.8
Windows 8

EDIT: What is the library's status upon the support of GCC 4.7.0?
EDIT2: Ok, the example is compiling ok after I switched to a previous GCC, but the mini-project still shows the same error. I copied the same code from the example over to the source file, and still no luck.

Ok, Irrlicht is having problems with GCC 4.7.0. Fix my IDE's settings to compile using the older compiler version.
CuteAlien
Admin
Posts: 9923
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: [SOLVED] Library Link error

Post by CuteAlien »

I'm working with gcc 4.7 on Windows. Can't really tell - rebuilding the lib and linking to the correct version should be sufficient. Did you double-check if the linker path is set correct and the version there is really a new one (should have a new date when you compiled it)?
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
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: [SOLVED] Library Link error

Post by mongoose7 »

Is __imp_createDevice a C++ reference. It looks like a C reference to me. Is he writing a C program?
CuteAlien
Admin
Posts: 9923
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: [SOLVED] Library Link error

Post by CuteAlien »

It's about createDevice - and usually happens when linking to a wrong version of the library or not linking at all or any kind of linker troubles.
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
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: [SOLVED] Library Link error

Post by hendu »

The __imp at the beginning means he tried to link a static lib without the static define. That only works on Linux, Windows mangles symbols differently in static vs dynamic libs.
abraker95
Posts: 10
Joined: Thu Sep 05, 2013 3:34 pm

Re: [SOLVED] Library Link error

Post by abraker95 »

CuteAlien wrote:I'm working with gcc 4.7 on Windows. Can't really tell - rebuilding the lib and linking to the correct version should be sufficient. Did you double-check if the linker path is set correct and the version there is really a new one (should have a new date when you compiled it)?

It's about createDevice - and usually happens when linking to a wrong version of the library or not linking at all or any kind of linker troubles.
Actually while I previously thought that it is the result of version incompatibilities (don't know if that can be true, would be annoying if it is), it is actually different releases of GCC. For people who are going to stumble across this rather interesting problem with libraries, compilation of libraries, and such, Code::Blocks comes with TDM-GCC, which is what I original compiled Irrlicht with. I wanted to upgrade to a newer version of GCC, and downloaded GCC from here http://gcc.gnu.org/. See the problem? Allow me: http://tdm-gcc.tdragon.net/. Yea... So the link errors is a product of linking against libraries compiled with a (slightly) different compiler, in my case anyway .
Noiecity
Posts: 314
Joined: Wed Aug 23, 2023 7:22 pm
Contact:

Re: [SOLVED] Library Link error

Post by Noiecity »

I had the same problem when trying to compile o.O, I only get this problem if I use the static library, maybe I wrote the code wrong? (Maybe I should also compile the .dll file?(the not static library))

Code: Select all

#define IRRLICHT_STATIC
#pragma comment(lib, "libIrrlicht.a")
#include <irrlicht/irrlicht.h>
#include <windows.h>

 using namespace irr;

 int main()
 {
    // start up the engine
    IrrlichtDevice *device = createDevice(video::EDT_SOFTWARE,
        core::dimension2d<u32>(640,480));

    video::IVideoDriver* driver = device->getVideoDriver();
    scene::ISceneManager* scenemgr = device->getSceneManager();

    device->setWindowCaption(L"Hello World!");

    // load and show quake2 .md2 model
    scene::ISceneNode* node = scenemgr->addAnimatedMeshSceneNode(
        scenemgr->getMesh("quake2model.md2"));

    // if everything worked, add a texture and disable lighting
    if (node)
    {
        node->setMaterialTexture(0, driver->getTexture("texture.bmp"));
        node->setMaterialFlag(video::EMF_LIGHTING, false);
    }

    // add a first person shooter style user controlled camera
    scenemgr->addCameraSceneNodeFPS();

    // draw everything
    while(device->run() && driver)
    {
        Sleep(60);
        driver->beginScene(true, true, video::SColor(255,0,0,255));
        scenemgr->drawAll();
        driver->endScene();
    }

    // delete device
    device->drop();
    return 0;
 }
make.exe -f "C:\Dev-Cpp\Projects\test19\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -c

g++.exe main.o -o "test19.exe" -L"C:/Dev-Cpp/lib" -L"C:/Dev-Cpp/lib" ../../lib/libIrrlicht.a -lIrrlicht

main.o(.text+0x174):main.cpp: undefined reference to `_imp__createDevice'
main.o(.text$_ZN3irr5video9SMaterial7setFlagENS0_15E_MATERIAL_FLAGEb[irr::video::SMaterial::setFlag(irr::video::E_MATERIAL_FLAG, bool)]+0x28d):main.cpp: undefined reference to `_imp___ZN3irr5video26MATERIAL_MAX_TEXTURES_USEDE'

main.o(.text$_ZN3irr5video9SMaterial7setFlagENS0_15E_MATERIAL_FLAGEb[irr::video::SMaterial::setFlag(irr::video::E_MATERIAL_FLAG, bool)]+0x2d7):main.cpp: undefined reference to `_imp___ZN3irr5video26MATERIAL_MAX_TEXTURES_USEDE'
main.o(.text$_ZN3irr5video9SMaterial7setFlagENS0_15E_MATERIAL_FLAGEb[irr::video::SMaterial::setFlag(irr::video::E_MATERIAL_FLAG, bool)]+0x327):main.cpp: undefined reference to `_imp___ZN3irr5video26MATERIAL_MAX_TEXTURES_USEDE'
main.o(.text$_ZN3irr5video9SMaterial7setFlagENS0_15E_MATERIAL_FLAGEb[irr::video::SMaterial::setFlag(irr::video::E_MATERIAL_FLAG, bool)]+0x35b):main.cpp: undefined reference to `_imp___ZN3irr5video26MATERIAL_MAX_TEXTURES_USEDE'
main.o(.text$_ZN3irr5video9SMaterial7setFlagENS0_15E_MATERIAL_FLAGEb[irr::video::SMaterial::setFlag(irr::video::E_MATERIAL_FLAG, bool)]+0x3d2):main.cpp: undefined reference to `_imp___ZN3irr5video26MATERIAL_MAX_TEXTURES_USEDE'
collect2: ld returned 1 exit status

make.exe: *** [test19.exe] Error 1
**
If you are looking for people with whom to develop your game, even to try functionalities, I can help you, free. CC0 man.

Image
**
n00bc0de
Posts: 116
Joined: Tue Oct 04, 2022 1:21 am

Re: [SOLVED] Library Link error

Post by n00bc0de »

Noiecity wrote: Thu Feb 13, 2025 5:09 pm I had the same problem when trying to compile o.O, I only get this problem if I use the static library, maybe I wrote the code wrong? (Maybe I should also compile the .dll file?(the not static library))
g++.exe main.o -o "test19.exe" -L"C:/Dev-Cpp/lib" -L"C:/Dev-Cpp/lib" ../../lib/libIrrlicht.a -lIrrlicht
This compiler command is probably your issue. You are linking against the static library with "../../lib/libIrrlicht.a" but you are also linking against the dynamic library with "-lIrrlicht"
Noiecity
Posts: 314
Joined: Wed Aug 23, 2023 7:22 pm
Contact:

Re: [SOLVED] Library Link error

Post by Noiecity »

n00bc0de wrote: Fri Feb 14, 2025 1:42 pm
Noiecity wrote: Thu Feb 13, 2025 5:09 pm I had the same problem when trying to compile o.O, I only get this problem if I use the static library, maybe I wrote the code wrong? (Maybe I should also compile the .dll file?(the not static library))
g++.exe main.o -o "test19.exe" -L"C:/Dev-Cpp/lib" -L"C:/Dev-Cpp/lib" ../../lib/libIrrlicht.a -lIrrlicht
This compiler command is probably your issue. You are linking against the static library with "../../lib/libIrrlicht.a" but you are also linking against the dynamic library with "-lIrrlicht"
I would like to think that it is correct, if it were not for the fact that when compiling the version of irrlicht 1.3 I have it exactly the same and it compiles successfully, although using the dynamic library (libIrrlicht.a weighs much less but it is still used).

I'm trying to compile irrlicht 1.9.0, but I gave up and used visual studio instead
**
If you are looking for people with whom to develop your game, even to try functionalities, I can help you, free. CC0 man.

Image
**
Post Reply