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

Author Topic: CMAKE error missing dependencies of SFML  (Read 5273 times)

0 Members and 1 Guest are viewing this topic.

Kvaz1r

  • Newbie
  • *
  • Posts: 39
    • View Profile
    • Email
CMAKE error missing dependencies of SFML
« on: October 14, 2020, 04:01:27 pm »
I want to use SFML with CMAKE but get error:

Quote
CMake Error at /SFML-2.5.1/build/SFMLConfig.cmake:139 (message):
  SFML found but some of its dependencies are missing ( FreeType OpenAL
  VorbisFile VorbisEnc Vorbis Ogg FLAC)
Call Stack (most recent call first):
  CMakeLists.txt:11 (find_package)


CMake Error at CMakeLists.txt:11 (find_package):
  Found package configuration file:

    /SFML-2.5.1/build/SFMLConfig.cmake

  but it set SFML_FOUND to FALSE so package "SFML" is considered to be NOT
  FOUND.


Configuring incomplete, errors occurred!

CMake file:

cmake_minimum_required(VERSION 3.1)

project(SFMLTest)

## If you want to link SFML statically
set(SFML_STATIC_LIBRARIES TRUE)

## In most cases better set in the CMake cache
set(SFML_DIR "SFML-2.5.1\\build")

find_package(SFML 2.5.1 COMPONENTS graphics audio REQUIRED)
add_executable(SFMLTest appl.cpp)
target_link_libraries(SFMLTest sfml-graphics)

I use static SFML 2.5.1 that built myself with CMAKE.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11053
    • View Profile
    • development blog
    • Email
Re: CMAKE error missing dependencies of SFML
« Reply #1 on: October 14, 2020, 06:12:07 pm »
Looks like you don't have static libraries built.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Kvaz1r

  • Newbie
  • *
  • Posts: 39
    • View Profile
    • Email
Re: CMAKE error missing dependencies of SFML
« Reply #2 on: October 14, 2020, 06:35:36 pm »
If I define paths manually:
Quote
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "SFML-2.5.1\\extlibs\\headers")   
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "SFML-2.5.1\\extlibs\\libs-msvc\\x86")   
CMAKE generate project files.

cmathai

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: CMAKE error missing dependencies of SFML
« Reply #3 on: October 25, 2023, 05:21:33 am »
I have the same issue too.

This doesnt happen with SFML built as shared library.

I have this problem when SFML is built as a static library.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11053
    • View Profile
    • development blog
    • Email
Re: CMAKE error missing dependencies of SFML
« Reply #4 on: October 25, 2023, 09:30:13 am »
I have the same issue too.
Can you be a bit more specific?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

cmathai

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: CMAKE error missing dependencies of SFML
« Reply #5 on: October 25, 2023, 10:36:43 pm »
OK I made some more progress. Basically the original issue was because I was not linking the target against SFML dependencies (which I missed, although described in https://www.sfml-dev.org/tutorials/2.6/start-vc.php)

Here is the issue I have now - I built a static version of SFML myself. I took an SFML toy example, but got a lot of link errors when building my application.

Here are the steps I followed (and how I fixed it)
  • Downloaded SFML 2.6.0 source from https://www.sfml-dev.org/files/SFML-2.6.0-sources.zip
  • Use Cmake GUI and Visual Studio 2019 to build SFML

    Where is the source code: C:/SFML-2.6.0-sources/SFML-2.6.0
    Where to build the libraries: C:/SFML_static_2.6.0
    Click on Configure. Uncheck BUILD_SHARED_LIBS, and check SFML_USE_STATIC_STD_LIBS. Click on Configure again. Click on Generate. This generates a visual studio solution SFML.sln. Open it and build the release version of SFML. This builds a static version of SFML in C:\SFML_static_2.6.0\lib\Release

  • Edit SFMLConfig.cmake in 'C:\SFML_static_2.6.0\SFMLConfig.cmake' (where SFML gets built)

    Add the paths lib/Release and the paths to SFML dependencies. To FIND_SFML_PATHS , add


    "${CMAKE_CURRENT_LIST_DIR}/lib/Release" (where SFML libraries are built)
    "C:/SFML-2.6.0-sources/SFML-2.6.0/extlibs/libs-msvc-universal/x64" (SFML dependencies shipped with SFML source)

  • Create a toy example. I created main.cpp with the code in https://www.sfml-dev.org/tutorials/2.6/start-vc.php
    In the same location, create CMakeLists.txt with the following content (code taken from https://en.sfml-dev.org/forums/index.php?topic=24070.0)

    cmake_minimum_required(VERSION 3.23)
    project(SFMLTest)
    ## If you want to link SFML statically
    set(SFML_STATIC_LIBRARIES TRUE)
    ## In most cases better set in the CMake cache
    set(SFML_DIR "C:/SFML_static_2.6.0")
    find_package(SFML 2.6 COMPONENTS graphics audio REQUIRED)
    add_executable(SFMLTest main.cpp)
    target_link_libraries(SFMLTest sfml-graphics sfml-audio)

  • Generate VS 2019 solution
    cmake -G "Visual Studio 16 2019" -A x64 -B build
  • Open SFMLTest.sln in 'build' folder, and Build the solution.

The last step gives a lot of link errors. Eg:-

Error LNK2038 mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in main.obj SFMLTest sfml-graphics-s.lib(Color.obj)
   

To fix this, I did the following.
Right click SFMLTest, click on properties.
C/C++ > Code Generation > Runtime Library is set to 'Multi-threaded DLL (/MD)'.

I changed it to 'Multi-threaded (/MT)' .

What I do not understand is, if I use the the pre-built version of SFML for VS 2019 from https://www.sfml-dev.org/files/SFML-2.6.0-windows-vc16-64-bit.zip, it works out of the box. And interestingly, when I check the solution generated with this, I still have Multi-threaded DLL (/MD), but it works. I am curious about why this works.

So I can't quite figure out what I am doing wrong. Any help is appreciated.
« Last Edit: October 25, 2023, 10:42:42 pm by cmathai »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11053
    • View Profile
    • development blog
    • Email
Re: CMAKE error missing dependencies of SFML
« Reply #6 on: October 25, 2023, 11:40:54 pm »
The difference/issue is:

and check SFML_USE_STATIC_STD_LIBS

That says to use static standard libs (i.e. /MT), which then requires that you also use static standard libs.

You can also solve this in CMake with:
set_property(TARGET my-target PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

cmathai

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: CMAKE error missing dependencies of SFML
« Reply #7 on: October 26, 2023, 12:34:33 am »
Thanks!!!

That was the problem  :)