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

Author Topic: Failing to link release build on Windows  (Read 1427 times)

0 Members and 1 Guest are viewing this topic.

kingguru

  • Newbie
  • *
  • Posts: 12
    • View Profile
Failing to link release build on Windows
« on: March 27, 2021, 12:07:22 am »
I have a fairly simple SFML project that is also fairly simple in how I build it with CMake.

I use the standard CMake FindPackage command:

find_package(SFML 2.5 COMPONENTS graphics system window REQUIRED)

And then link it to my target:

target_link_libraries(${PROJECT_NAME} PRIVATE
  sfml-graphics
  sfml-system
  sfml-window
)

This work just fine on Linux with the SFML package installed from my package manager and on Windows it also works fine, but only when using the Debug configuration. Building it in release mode like this:

cmake --build . --config Release

Fails to link as there is no Release directory in the prebuilt SFML .zip file I downloaded (64-bit VS 2017). The Debug build works fine since there is indeed a Debug directory where I assume CMake tells the linker to find the required .lib files. As far as I can tell, both the Debug and Release version of the libraries are in the root lib folder of the prebuilt SFML .zip file.

Am I missing something? This seems like the "normal" way to build CMake projects on Windows, but I must admit I'm not very experienced on that platform.

Thanks a lot.

LucaCiucci

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Failing to link release build on Windows
« Reply #1 on: March 27, 2021, 03:34:01 pm »
Hi, I'll explain you my setup since I use SFML on Windows with CMake.

SFML installation
We need CMake system to properly find the SFML library:
  • Add a global environment variable, for exaple SFML_install="G:\SFML-2.5.1";
  • add the following to PATH:
     
    • "%SFML_install%\lib"
    • "%SFML_install%\bin"
    • "%SFML_install%\lib\cmake\SFML"
    (the last one sould not be necessary, but I fund that camake won't find the library without it)

Note: obviously you would need to restart the IDE, cmd or anything you use. Sometimes Windows would not expand the PATH entries automatically. To solve this you should use the admin rights or simply sobstitute %SFML_install% with the actual value)

Configurations
I use Visual studio in my project, I create the debug and release configurations. The debug configuration should work fine while the release one would not work since VS will build your project in "RelWithDebInfo" by default, but the SFML are only built in "Debug" ad "Release". You have to edit the release configuration and change "Configuration Type" (not the configuration name) from "RelWithDebInfo" to "Release".

This method works fine for me, but if you want the "RelWithDebInfo" you have to build the SFML library from source... but I did not succeed: https://en.sfml-dev.org/forums/index.php?topic=27949.0

« Last Edit: March 27, 2021, 03:38:43 pm by LucaCiucci »

kingguru

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Failing to link release build on Windows
« Reply #2 on: March 27, 2021, 08:42:51 pm »
@LucaCiucci

Thanks a lot for your reply.

I think I forgot the most useful information which is, that I was configuring CMake with:

cmake -DSFML_DIR="<path to SFML> <path to my CMakeLists.txt>"

Rereading the forum post where I originally found the instructions (https://en.sfml-dev.org/forums/index.php?topic=24070.0), that was clearly wrong as it states that I should set SFML_DIR to "<sfml root prefix>/lib/cmake/SFML".

Doing so works perfectly with both Debug and Release configurations.

So this was clearly just a mistake on my side, but thankfully I figured it out.

I generally don't think it should be necessary to mess around with environment variables for reasonably well written CMake projects, which SFML thankfully is. But if it works for you, then no reason to change anything of course :-)

Thanks once again. This can definitely be considered solved although I'm still wondering why it almost works when given the wrong path.

 

anything