SFML community forums

Help => General => Topic started by: Sebox on March 11, 2017, 10:23:59 am

Title: Static linking problem
Post by: Sebox on March 11, 2017, 10:23:59 am
Hello

I try to static link my game and i get error.
I add SFML_STATIC to preprocessor.
In Release:
(click to show/hide)
In Debug:
(click to show/hide)

And when i run compile all is good but when i try to open my game i get error: "Program game.exe stopped working" when i use debug i get error in line when code is:
 RenderWindow window(VideoMode::getDesktopMode(), "Game", Style::Default, sett);
And the error is "Unhandled exception at the Location 0x77A2FF33 (Ntdll.dll)"
I use Visual Studio 2017, and i download package Visual C++ 14 (2015) - 32-bit
I really dont know where are problem.
Title: Re: Static linking problem
Post by: sjaustirni on March 11, 2017, 10:48:53 am
Quote from: SFML downloads (http://www.sfml-dev.org/download/sfml/2.4.2/)
The compiler versions have to match 100%!

which basically means that you need to compile SFML on your own. thankfully, with VS 2017 it's easy these days.
BTW, While we're at it, make sure that if you compile SFML for 32-bit, that you compile your project for 32-bit as well. The same goes for Debug/Release versions.
Title: Re: Static linking problem
Post by: Sebox on March 11, 2017, 10:59:38 am
Thank you for your answer, i add path for compile my own SFML(libs and include) and when i try co compile i get error
"LNK1104 cannot open file 'sfml-window-s-d.lib' client"
Title: Re: Static linking problem
Post by: sjaustirni on March 11, 2017, 12:34:43 pm
This means that you point to a wrong folder, or that VS has no access to it. Check it.

Also, what compiler and linking chain do you use? The MSVC one, or CMake?
Title: Re: Static linking problem
Post by: Sebox on March 11, 2017, 12:47:17 pm
I use CMake. I have 3 folders:
(https://iv.pl/images/51068943674501256122_thumb.jpg) (https://iv.pl/viewer.php?file=51068943674501256122.png)

I use path to install:
(https://iv.pl/images/25650679264796829054_thumb.jpg) (https://iv.pl/viewer.php?file=25650679264796829054.png)
include and lib. But in lib i only have:
(https://iv.pl/images/10543608140951231475_thumb.jpg) (https://iv.pl/viewer.php?file=10543608140951231475.png)
so where can i should find files with suffix -s ??
Title: Re: Static linking problem
Post by: Laurent on March 11, 2017, 01:30:29 pm
Look at the CMake tutorial, it explains all the options that you can change when you configure your SFML build -- including the one to build static libraries.
Title: Re: Static linking problem
Post by: Sebox on March 11, 2017, 02:14:33 pm
Now i have error: "cannot open file freetype.lib"

(https://iv.pl/images/43465828144879187627_thumb.jpg) (https://iv.pl/viewer.php?file=43465828144879187627.png)
Title: Re: Static linking problem
Post by: Laurent on March 11, 2017, 08:19:59 pm
Where? When you do what?
Title: Re: Static linking problem
Post by: Sebox on March 11, 2017, 08:23:42 pm
In compilator, when i try to compile program
Title: Re: Static linking problem
Post by: Laurent on March 12, 2017, 06:18:52 pm
If you correctly installed SFML after building it, freetype.lib should be in the same directory as the SFML libraries. So I guess you haven't done the install step.
Title: Re: Static linking problem
Post by: Sebox on March 12, 2017, 07:35:58 pm
I downloaded SFML source next i open this in CMake, next i choose when the CMake have to build the binaries and where is the source code, next i marked the SFML_USE_STATIC_STD_LIBS and i click Configure and Generate, next open the compiled of CMake in Visual Studio and click Build Solution in Debug and in Release.

After build solution i have this folder:
(https://iv.pl/images/91043043616895586777_thumb.jpg) (https://iv.pl/viewer.php?file=91043043616895586777.png)

And i copy the libs from this folder /\ and include from SFML source to one folder. Next i set the path in visual studio to libs and include. But i dont have freetype.lib, only lib type "sfml-window-s.lib"
Title: Static linking problem
Post by: eXpl0it3r on March 12, 2017, 07:46:35 pm
If you build the INSTALL target (project) in Visual Studio you don't have to copy anything around.
Title: Re: Static linking problem
Post by: Laurent on March 12, 2017, 08:28:48 pm
It is explained in the CMake tutorial, just read it (search "install" if you can't find where it is explained -- hint: it's at the end ;)).
Title: Re: Static linking problem
Post by: Sebox on March 12, 2017, 08:34:16 pm
When i build INSTALL in visual studio i get error:

MSB3073 The command "setlocal
C:\Users\Sebastian\Desktop\cmake-3.8.0-rc2-win32-x86\bin\cmake.exe -DBUILD_TYPE=Debug -P cmake_install.cmake
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd
:VCEnd"
exited with code 1.     INSTALL
Title: Re: Static linking problem
Post by: Laurent on March 13, 2017, 06:32:20 am
Is your CMAKE_INSTALL_PREFIX in C:\Program Files ? If so, you need admin rights (so I personally never install there).
Title: Re: Static linking problem
Post by: Sebox on March 13, 2017, 05:45:04 pm
Ok now certainly i have good compiled and installed SFML but when i try to compile my own program, i get error: LNK2038   mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in animation.obj   client

When i changed Runtime Library in Debug to Multi-threaded Debug i dont have this error but when i try to open the compiled exe i get error system "Application stopped working"
Title: Re: Static linking problem
Post by: Laurent on March 13, 2017, 06:40:20 pm
Quote
next i marked the SFML_USE_STATIC_STD_LIBS
Don't do that ;)
Title: Re: Static linking problem
Post by: Sebox on March 13, 2017, 06:52:30 pm
Are you sure? If i dont marked this i dont have lib with suffix -s so i can't static link.  :(
Title: Re: Static linking problem
Post by: Laurent on March 14, 2017, 06:30:11 am
Please read the documentation carefully. This one is a totally different thing. The option you need to care about is BUILD_SHARED_LIBS.
Title: Re: Static linking problem
Post by: Sebox on March 14, 2017, 12:47:15 pm
I unmarked BUILD_SHARED_LIBS and marked SFML_USE_STATIC_STD_LIBS, so i have lib with -s suffix. When i only marked BUILD_SHARED_LIBS i have dynamically libs so without -s. So how i can add this to visual studio ?
Title: Static linking problem
Post by: eXpl0it3r on March 14, 2017, 12:58:47 pm
You have to uncheck BUILD_SHARED_LIBS and uncheck SFML_USE_STATIC_STD_LIBS. Read the SFML CMake tutorial to understand what each option does.
Title: Re: Static linking problem
Post by: Sebox on March 14, 2017, 04:53:33 pm
I did what u spoken and i have same problem "...Application stopped working..."
Title: Static linking problem
Post by: eXpl0it3r on March 14, 2017, 05:01:20 pm
SFML hasn't been tested with VS 2017 yet, so there maybe a chance that Microsoft changed something that breaks SFML. However it may also just be a misconfiguration on your end somehow.

I'll look into building SFML with VS 2017 this evening myself.
Title: Re: Static linking problem
Post by: Sebox on March 14, 2017, 05:51:08 pm
I turned on debugging and i get error in mutex, so i find in google that sf::RenderWindow can no't be a global variables, i get this in the main() and all is good. Thank you very much for help i think i would do this with super documentation but my main problem is english thats why the lucid tutorial dont help me much. :) :) :)

Intrestingly why its work in dynamic libraries and it makes problem in static hmm :)
Title: Re: Static linking problem
Post by: eXpl0it3r on March 14, 2017, 06:28:42 pm
Yes, don't initialize any SFML resources in a global scope. I'd even suggest to not use any global variables at all. There are always better designs, the most simple one being to wrap things into a class and just use the main() function to initialize the class.

I also just quickly built SFML with VS 2017 and everything works fine. :)
Title: Re: Static linking problem
Post by: Sebox on March 15, 2017, 08:38:21 pm
As i wrote all is good but what i have to do if can build static libraries of Visual Studio like "msvcrt140d.dll" ??
When i change runtime library to Multi-Threaded Debug i get error type: LNK2038   mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MTd_StaticDebug' in animation.obj client
Title: Re: Static linking problem
Post by: eXpl0it3r on March 15, 2017, 10:02:06 pm
As explained in the CMake tutorial, if you want to link the runtime library statically, you check SFML_USE_STATIC_STD_LIBS and switch your project to /MT and /MTd.