Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Static Linking Errors  (Read 5473 times)

0 Members and 1 Guest are viewing this topic.

TheCommunistDuck

  • Newbie
  • *
  • Posts: 11
    • View Profile
Static Linking Errors
« on: January 01, 2010, 06:57:24 pm »
I'm trying to statically link the sfml-window and sfml-system libraries to use the OpenGL window stuff. I've got SFML2 for the GL3.x support, but the tutorial code gives me linker errors. I have copied sfml-window-s/-s-d and sfml-system-s/-s-d to C::B lib directory. I have also put
Code: [Select]
-lsfml-window-s -lsfml-system-s
For release.
Code: [Select]
#include <SFML/System.hpp>
#include <iostream>

int main(int argc, char* argv[])
{
    sf::Clock Clock;
    while (Clock.GetElapsedTime() < 5.f)
    {
        std::cout << Clock.GetElapsedTime() << std::endl;
        sf::Sleep(0.5f);
    }

    return 0;
}

I get:
Code: [Select]
obj\Release\main.o:main.cpp:(.text+0x21)||undefined reference to `__imp___ZN2sf5ClockC1Ev'|
obj\Release\main.o:main.cpp:(.text+0x2c)||undefined reference to `__imp___ZNK2sf5Clock14GetElapsedTimeEv'|
obj\Release\main.o:main.cpp:(.text+0x52)||undefined reference to `__imp___ZN2sf5SleepEf'|
obj\Release\main.o:main.cpp:(.text+0x5b)||undefined reference to `__imp___ZNK2sf5Clock14GetElapsedTimeEv'|
||=== Build finished: 4 errors, 0 warnings ===|


Any ideas? I recently did a small test with sfml, a few weeks back, with the DLL libs and it worked fine. However I'd much prefer to lnik with static. Thanks. :D
-Mark.[/code]

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Static Linking Errors
« Reply #1 on: January 01, 2010, 07:20:06 pm »
Are you sure that you don't define SFML_DYNAMIC in your preprocessor options?
Laurent Gomila - SFML developer

TheCommunistDuck

  • Newbie
  • *
  • Posts: 11
    • View Profile
Static Linking Errors
« Reply #2 on: January 01, 2010, 07:25:00 pm »
Ah. I forgot C::B keeps settings; I had that defined. :P

All works fine, or appears to. Thanks. :D
-Mark.

bnz

  • Newbie
  • *
  • Posts: 22
    • View Profile
Static Linking Errors
« Reply #3 on: January 29, 2010, 10:44:22 pm »
Since this topic covers exactly the same problem, I'm posting mine here.

I'm trying to link SFML statically, so my include list looks like this:
sfml-window-s-d.lib;sfml-system-s-d.lib;sfml-main-d.lib;sfml-graphics-s-d.lib

I don't define SFML_DYNAMIC.

However, when I compile (e.g. the tutorial code on event handling with windows), I get the linker errors like the following ones:
Code: [Select]
1>sfml-window-s-d.lib(VideoModeSupport.obj) : error LNK2019: unresolved external symbol __imp__EnumDisplaySettingsA@12 referenced in function "public: static void __cdecl sf::priv::VideoModeSupport::GetSupportedVideoModes(class std::vector<class sf::VideoMode,class std::allocator<class sf::VideoMode> > &)" (?GetSupportedVideoModes@VideoModeSupport@priv@sf@@SAXAAV?$vector@VVideoMode@sf@@V?$allocator@VVideoMode@sf@@@std@@@std@@@Z)
1>sfml-window-s-d.lib(WindowImplWin32.obj) : error LNK2019: unresolved external symbol __imp__ShowWindow@8 referenced in function "public: __thiscall sf::priv::WindowImplWin32::WindowImplWin32(void)" (??0WindowImplWin32@priv@sf@@QAE@XZ)

I'm using VC++ 2010 beta2.

I guess I'm missing something obvious here, so please give me a hint. =)

bnz

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Static Linking Errors
« Reply #4 on: January 29, 2010, 11:21:58 pm »
Are you linking the library in the right order?
All sfml libraries depends on sfml-system, so this one should come last on the linking list
Pluma - Plug-in Management Framework

bnz

  • Newbie
  • *
  • Posts: 22
    • View Profile
Static Linking Errors
« Reply #5 on: January 29, 2010, 11:30:10 pm »
I didn't even know the order in the linking list made any difference.
So now I'm linking in the following order:
sfml-window-s-d.lib;sfml-main-d.lib;sfml-graphics-s-d.lib;sfml-system-s-d.lib

However, this does not solve the problem.

Any other suggestions?

Thanks,
bnz.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Static Linking Errors
« Reply #6 on: January 30, 2010, 12:40:39 pm »
Quote
I didn't even know the order in the linking list made any difference.

It is explained in the "getting started" tutorial.

Quote
sfml-window-s-d.lib;sfml-main-d.lib;sfml-graphics-s-d.lib;sfml-system-s-d.lib

This is still wrong, use this instead:
Code: [Select]
sfml-graphics-s-d.lib;sfml-window-s-d.lib;sfml-system-s-d.lib;sfml-main-d.lib

But I think this is a different problem, the unresolved symbols are from the OS libraries, not from SFML. You'll probably have to recompile SFML with VS2010 to make it work.
Laurent Gomila - SFML developer

bnz

  • Newbie
  • *
  • Posts: 22
    • View Profile
Static Linking Errors
« Reply #7 on: January 30, 2010, 02:08:23 pm »
Quote
It is explained in the "getting started" tutorial.

It says so in the Code::Blocks tutorial - not in the VC++ one. ;)

Quote
But I think this is a different problem, the unresolved symbols are from the OS libraries, not from SFML. You'll probably have to recompile SFML with VS2010 to make it work.

Again?
If you recall this topic, I already did that. However this was on another computer (and maybe with beta1, not beta2 - EDIT: no, it was definetly beta2), so I'll give it another try.

Greetings,
bnz.

EDIT:

Well, now I tried to rebuild the library, using VC++ 2010 beta2 as I tried in the afore mentioned thread, and now VC++ 2010 beta2 says the following:

The german sentence means something like: "The system could not find the specified file."
Because of this error only four files are actually compiled.

I guess until you provide the proper builds for VC++ 2010 I won't be able to statically link to sfml.

Greetings,
bnz.

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Static Linking Errors
« Reply #8 on: January 30, 2010, 04:41:57 pm »
This is a bit offtopic, but why is sfml-main needed for VS?
Just wondering because I don't use VS/VC++
Pluma - Plug-in Management Framework

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Static Linking Errors
« Reply #9 on: January 30, 2010, 05:01:45 pm »
Quote
It says so in the Code::Blocks tutorial - not in the VC++ one.

Ah, so I guess this is not an issue on VC++ (I always get confused with this thing) :)

Quote
"The system could not find the specified file."

You'll probably have to change a few project settings. I'm sorry I can't help much, I don't use VS2010 yet.

Quote
I guess until you provide the proper builds for VC++ 2010 I won't be able to statically link to sfml.

And I won't do that until the final version is released :P

Quote
This is a bit offtopic, but why is sfml-main needed for VS?

This is not related to the compiler, it is Windows-specific: if you don't want the console to show up you have to use WinMain as the entry point; and this is where sfml-main is needed :)
Laurent Gomila - SFML developer

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Static Linking Errors
« Reply #10 on: January 30, 2010, 08:42:35 pm »
Quote from: "Laurent"
it is Windows-specific: if you don't want the console to show up you have to use WinMain as the entry point; and this is where sfml-main is needed :)

I use C::B on Windows, running SFML apps without console and no need for sfml-main. Or you mean for integration with windows specific code?  :?
Pluma - Plug-in Management Framework

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Static Linking Errors
« Reply #11 on: January 30, 2010, 08:48:35 pm »
Quote
I use C::B on Windows, running SFML apps without console and no need for sfml-main

But you use a WinMain, don't you?
Laurent Gomila - SFML developer

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Static Linking Errors
« Reply #12 on: January 31, 2010, 01:08:51 am »
No.
I set the target type as a GUI application. I don't know what C::B does behind, but the application shows without console.
Useful for debug and release targets. I set debug target as console application, and release as GUI application :wink:.

Pluma - Plug-in Management Framework