Dynamic linking... I'm going crazy
« on: 18 August 2014, 17:24:45 »
Hey Texus

I can't use the default SJLJ libs because I'm collaborating with another project that uses DW2 MinGW.

So I compiled my own by using CMake on windows. No problem there.

But when I try to link the libs in the example TGUI login program, I get

Code: [Select]
  tgui::EditBox::Ptr editBoxUsername = gui.get("Username");

Quote
"||=== Build: Debug in tgui_test (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function `main':|
C:\dev\TGUI-0.6\examples\tgui_test\main.cpp|98|undefined reference to `__imp___ZNK4tgui3Gui3getERKN2sf6StringE'|
C:\dev\TGUI-0.6\examples\tgui_test\main.cpp|99|undefined reference to `__imp___ZNK4tgui3Gui3getERKN2sf6StringE'|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|
"

Now, I understand that __imp__ is something to do with .dll's.

But I thought I am already supplying everything needed :

-ltgui-d -lsfml-graphics-d -lsfml-window-d -lsfml-system-d -lwsock32 -lwinmm -lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt

I have looked with nm into the original libtgui-d.a and tgui-d.dll and the name mangling looks identical to the libs I have compiled.

Do you have any suggestions where I am going wrong ?

Thanks ! This static/dynamic stuff is so confusing.

*

texus

  • *****
  • 1161
    • View Profile
    • Texus's Blog
Re: Dynamic linking... I'm going crazy
« Reply #1 on: 18 August 2014, 17:51:59 »
The __imp__ has something to do with static vs dynamic linking iirc. It would be caused when e.g. defining SFML_STATIC while linking to dynamic libs or the other way around.

Normally you just link against "-ltgui-d -lsfml-graphics-d -lsfml-window-d -lsfml-system-d", I don't think you need to specify any others unless you are using another library next to tgui and sfml as well.

Which compiler are u using exactly (download link if possible)? Then perhaps I can try to see for myself.
On second thought, I won't be able to install another compiler to test this.

You should also make sure that you are linking to the same sfml version that you used to compile tgui with.

Edit:
This answer was not marked as the solution, so it may not be correct. But if this is true then cmake may have found VS libraries from sfml instead of the MinGW ones (I've seen it happen before, it doesn't care that it is linking with .lib files instead of .a files).
https://stackoverflow.com/a/20240189
« Last Edit: 18 August 2014, 18:20:16 by texus »

Re: Dynamic linking... I'm going crazy [SOLVED]
« Reply #2 on: 24 August 2014, 00:21:54 »
Hello

I want to report I solved the problem.

I found a program called Dependency Walker

It is a fantastic program that shows in great detail what DLL's will be called by the program and how DLL's depend on each other.

https://dependencywalker.com/

Using this program I found out that I got burned (yet again) by the good old PATH variable in Windoze. The TGUI dll was calling a SFML dll that was in an earlier entry in the PATH. And that .dll happened to be a DW2 exception handler version. The error however, was pointing to libstdc++-6.dll BECAUSE the SFML dll was looking for the DW2 personality flag in the SJLJ libstdc++-6. Without dependency walker I probably would still be wondering whats wrong.

Fixed by putting the path to the SFML SJLJ directory before the path to the SFML DW2 directory ( I need both).

*

texus

  • *****
  • 1161
    • View Profile
    • Texus's Blog
Re: Dynamic linking... I'm going crazy
« Reply #3 on: 24 August 2014, 08:57:54 »
This is exactly why it is a bad idea to use the PATH. The dlls should be next to your exe and not in some folder in the PATH variable.

But I'm glad you figured it out, and I'll try to remember that program.