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

Author Topic: Error with static linking  (Read 12823 times)

0 Members and 1 Guest are viewing this topic.

accelleon

  • Newbie
  • *
  • Posts: 3
    • View Profile
Error with static linking
« on: June 25, 2009, 03:36:40 pm »
when i try to static link sfml-system-s.lib and sfml-window-s.lib it runs this error:
1>sfml-window-s.lib(WindowImplWin32.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z)
1>sfml-window-s.lib(Window.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z)
1>sfml-window-s.lib(VideoMode.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z)
1>sfml-window-s.lib(WindowImpl.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z)
1>sfml-window-s.lib(VideoModeSupport.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z)
1>sfml-window-s.lib(Window.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,int)" (__imp_?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHPBDH@Z)
1>sfml-window-s.lib(WindowImplWin32.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,int)" (__imp_?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHPBDH@Z)
1>C:\Users\Tony\Documents\Visual Studio 10\Projects\SFML_Window_Tut\Release\SFML_Window_Tut.exe : fatal error LNK1120: 2 unresolved externals

Please help as i don't know what the problem is because it works when i dynamic link them and no SFML_DYNAMIC is not defined.

drakelord

  • Newbie
  • *
  • Posts: 22
    • View Profile
Error with static linking
« Reply #1 on: June 30, 2009, 02:09:40 am »
First off, are you compiling with /MT or /MD?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Error with static linking
« Reply #2 on: July 05, 2009, 01:11:28 pm »
Quote
is this a mistake in the project file?

No, it's a stupid thing from Code::Blocks :)
I've tried many different versions of Code::Blocks, and in each the .inl files were *not* compiled by default. I could not even change the option, for users like you.
Unfortunately you have a version of Code::Blocks that *do* compile .inl files by default.

Quote
Remember if you are doing static libs, you need to link in the dependencies manually!

Laurent, maybe this could be handled automatically with a post-build script for the static targets?

The last time I tried I failed to make Code::Blocks execute an automatic post-build script.
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Error with static linking
« Reply #3 on: July 05, 2009, 06:01:09 pm »
Yes I'm using 8.02. But other users of 8.02 had their .inl files compiled :?
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Error with static linking
« Reply #4 on: July 05, 2009, 08:29:22 pm »
Quote
Btw, do you planing on compiling 1.6/2.0 (which ever is next) with MinGW/GCC4.4.0 ? It's officially supported now *wink* *wink* *nudge* *nudge*

I haven't tried, but I'm 99% sure it will compile fine. Don't forget that it already compiles on Linux with gcc 4.4.x ;)
Laurent Gomila - SFML developer

Phoenix

  • Newbie
  • *
  • Posts: 27
    • View Profile
Error with static linking
« Reply #5 on: July 05, 2009, 10:48:55 pm »
It's compile fine on GCC 4.4.0 TDM-1 and link external dependencies too.

Phoenix

  • Newbie
  • *
  • Posts: 27
    • View Profile
Error with static linking
« Reply #6 on: July 06, 2009, 10:54:06 am »

Phoenix

  • Newbie
  • *
  • Posts: 27
    • View Profile
Error with static linking
« Reply #7 on: July 07, 2009, 03:12:46 pm »
I use a batch script
Code: [Select]
@echo off
set mingw=C:\MinGW
set sfml="c:\SFML\SFML2"
set dest=C:\MinGW
set cb="%PROGRAMFILES%\CodeBlocks"
set PATH=%PATH%;%cb%
cd %sfml%\build\codeblocks
codeblocks -na -nd -ns --build sfml-audio.cbp
codeblocks -na -nd -ns --build sfml-graphics.cbp
codeblocks -na -nd -ns --build sfml-main.cbp
codeblocks -na -nd -ns --build sfml-network.cbp
codeblocks -na -nd -ns --build sfml-system.cbp
codeblocks -na -nd -ns --build sfml-window.cbp
mkdir %TEMP%\sfml
cd %sfml%\lib\mingw
xcopy *.a %TEMP%\sfml /q /y
cd %TEMP%
cd sfml
ar x %mingw%\lib\libgdi32.a
ar x %mingw%\lib\libopengl32.a
ar x %mingw%\lib\libwinmm.a
ar rs libsfml-window-s.a *.o
del *.o /f /q
ar x %mingw%\lib\libws2_32.a
ar rs libsfml-network-s.a *.o
del *.o /f /q
ar x %sfml%\extlibs\libs-mingw\libfreetype.a
ar rs libsfml-graphics-s.a *.o
del *.o /f /q
ar x %sfml%\extlibs\libs-mingw\libopenal32.a
ar x %sfml%\extlibs\libs-mingw\libsndfile.a
ar rs libsfml-audio-s.a *.o
del *.o /f /q
xcopy *.a %dest%\lib /q /y
del *.* /f /q
cd ../
rmdir sfml /s /q
xcopy %SFML%\include %dest%\include /s /q /y

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Error with static linking
« Reply #8 on: July 07, 2009, 10:53:06 pm »
Quote
recompiled SFML using the project files, then ran your bat file

I thyink the script already does it
Code: [Select]
codeblocks -na -nd -ns --build sfml-audio.cbp
codeblocks -na -nd -ns --build sfml-graphics.cbp
codeblocks -na -nd -ns --build sfml-main.cbp
codeblocks -na -nd -ns --build sfml-network.cbp
codeblocks -na -nd -ns --build sfml-system.cbp
codeblocks -na -nd -ns --build sfml-window.cbp


Quote
Laurent, it might be good to include this script in the Windows SDK.

Yep, it looks interesting, I'll see what I can do with it :)
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Error with static linking
« Reply #9 on: July 07, 2009, 11:34:52 pm »
Phoenix, do you mind if I use your script, and maybe modify and add it to the repository?
Laurent Gomila - SFML developer

Phoenix

  • Newbie
  • *
  • Posts: 27
    • View Profile
Error with static linking
« Reply #10 on: July 08, 2009, 10:30:44 pm »
You can modify it and add to repository, there isn't problem.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Error with static linking
« Reply #11 on: July 10, 2009, 03:36:58 pm »
Thanks :)

I added it to the repository (trunk), together with ar.exe and the required external libraries. So that the only thing required before running the script is that codeblocks.exe is accessible (in the PATH).

The script now builds every configuration (debug/release static/dynamic) and properly copies back the static libraries to lib\mingw after modifying them.

I guess my 3.4.5 libraries are compatible with the new version of MinGW (4.4.x); maybe someone can confirm that.
Laurent Gomila - SFML developer