SFML community forums

Help => General => Topic started by: PewPew on January 26, 2016, 11:55:07 am

Title: Having some issues with SFML
Post by: PewPew on January 26, 2016, 11:55:07 am
I was following this http://www.gamefromscratch.com/post/2015/06/02/Creating-an-SFML-project-on-Mac-OS-using-CLion-and-CMake.aspx  (http://www.gamefromscratch.com/post/2015/06/02/Creating-an-SFML-project-on-Mac-OS-using-CLion-and-CMake.aspx) tutorial on setting up SFML with Clion.  I have the correct working directory but I got an error  saying

Quote
Error:Could NOT find SFML (missing: SFML_GRAPHICS_LIBRARY SFML_WINDOW_LIBRARY SFML_SYSTEM_LIBRARY)

This is my cmake

Quote
cmake_minimum_required(VERSION 3.2)
project(SFMLTest)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES main.cpp)
add_executable(SFMLTest ${SOURCE_FILES})

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "/SFML-2.3.2/cmake/Modules/")
find_package(SFML REQUIRED graphics window system)
if (SFML_FOUND)
    include_directories(${SFML_INCLUDE_DIR})
    target_link_libraries(SFMLTest ${SFML_LIBRARIES})
endif(SFML_FOUND)

Please help..
Title: Re: Having some issues with SFML
Post by: Satus on January 26, 2016, 02:43:59 pm
Don't know if it will help you, but I use this lines in my CMakeLists in CLion:

set(SFML_ROOT "${CMAKE_SOURCE_DIR}/SFML-2.3/")

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/SFML-2.3/cmake/Modules")
set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH} ${CMAKE_SOURCE_DIR}/SFML-2.3/lib")
set(SFML_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/SFML-2.3/include")
find_package(SFML 2.3 COMPONENTS system window graphics network audio REQUIRED)
Title: Re: Having some issues with SFML
Post by: Laurent on January 26, 2016, 05:47:27 pm
Yes, it will help. Also, using the REQUIRED keyword will trigger a fatal error if the library is not found, so it is totally useless to test SFML_FOUND after that.
Title: Re: Having some issues with SFML
Post by: PewPew on January 27, 2016, 07:58:28 am
Yes, it will help. Also, using the REQUIRED keyword will trigger a fatal error if the library is not found, so it is totally useless to test SFML_FOUND after that.

Hi, thanks but still not working. I tried bot the COMPONENTS and REQUIRED both gave me the same error messages

Quote
Error:Could NOT find SFML (missing: SFML_SYSTEM_LIBRARY SFML_WINDOW_LIBRARY SFML_GRAPHICS_LIBRARY SFML_NETWORK_LIBRARY SFML_AUDIO_LIBRARY)

Still have any idea why? The SFML folder is on my DemoProject. So im pretty sure I have the correct directory.

This is the updated CmakeList

Quote
cmake_minimum_required(VERSION 3.2)
project(SFMLDemo3)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES main.cpp)
add_executable(SFMLDemo3 ${SOURCE_FILES})

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "/SFML-2.3.2/cmake/Modules/")
set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH} ${CMAKE_SOURCE_DIR}/SFML-2.3.2/lib")
set(SFML_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/SFML-2.3.2/include/SFML")
find_package(SFML COMPONENTS system window graphics network audio REQUIRED)

if (SFML_FOUND)
    include_directories(${SFML_INCLUDE_DIR})
    target_link_libraries(SFMLDemo3 ${SFML_LIBRARIES})
endif(SFML_FOUND)
Title: Re: Having some issues with SFML
Post by: Hiura on January 27, 2016, 09:11:44 am
Your `CMAKE_MODULE_PATH` path is inconsistent with `CMAKE_PREFIX_PATH` so I guess it's wrong.
Title: Re: Having some issues with SFML
Post by: Satus on January 27, 2016, 12:06:49 pm
The SFML folder is on my DemoProject. So im pretty sure I have the correct directory.

You can use message command to output cmake variables to CLion console and ensure that they are correctly set.
Title: Re: Having some issues with SFML
Post by: PewPew on January 29, 2016, 04:48:10 am
Hi,
So i just message all the directory. Copy it and paste it to the address bar of my file explorer. and yes I got the working directory. here is the updated cmake

Quote
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/SFML-2.3.2/cmake/Modules/")
set(SFML_LIBRARIES "${CMAKE_SOURCE_DIR}/SFML-2.3.2/lib")
set(SFML_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/SFML-2.3.2/include")

MESSAGE(${SOURCE_FILES})
find_package(SFML COMPONENTS system window graphics network audio REQUIRED)

if (SFML_FOUND)
    include_directories(${SFML_INCLUDE_DIR})
    target_link_libraries(SFMLDemo3 ${SFML_LIBRARIES})
endif(SFML_FOUND)

 but i still have this problem
Quote
(missing: SFML_SYSTEM_LIBRARY SFML_WINDOW_LIBRARY
  SFML_GRAPHICS_LIBRARY SFML_NETWORK_LIBRARY SFML_AUDIO_LIBRARY)

I am hundred percent sure that the directory is working. I message the SOURCE DIR  and the MODULE PATH. All of them points to the directory of the SFML inside my demo project.
I remove the PREFIX PATH and put the SFML LIBRARIES there to point it to the correct lib folder as I notice that the SFML LIBRARIES return invalid in MESSAGE. Still having the same issue.
Title: Re: Having some issues with SFML
Post by: PewPew on January 29, 2016, 05:08:35 am
Okay so I just remove the IFs on CmakeLists as it turns out the SFML FOUND is returning invalid argument in message. I also remove the REQUIRED on find_package(). This did the trick on removing the errors on CMAKE but now gives another problem.

The intellisense is showing every function of the SFML but I have this error

Quote
CMakeFiles\SFMLDemo3.dir/objects.a(main.cpp.obj): In function `main':
ClionProjects/SFMLDemo3/main.cpp:8: undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'
ClionProjects/SFMLDemo3/main.cpp:8: undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'
ClionProjects/SFMLDemo3/main.cpp:8: undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'
ClionProjects/SFMLDemo3/main.cpp:17: undefined reference to `_imp___ZN2sf6Window5closeEv'
ClionProjects/SFMLDemo3/main.cpp:13: undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'
ClionProjects/SFMLDemo3/main.cpp:21: undefined reference to `_imp___ZN2sf5ColorC1Ehhhh'
ClionProjects/SFMLDemo3/main.cpp:21: undefined reference to `_imp___ZN2sf12RenderTarget5clearERKNS_5ColorE'
ClionProjects/SFMLDemo3/main.cpp:22: undefined reference to `_imp___ZN2sf6Window7displayEv'
ClionProjects/SFMLDemo3/main.cpp:10: undefined reference to `_imp___ZNK2sf6Window6isOpenEv'
ClionProjects/SFMLDemo3/main.cpp:25: undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
ClionProjects/SFMLDemo3/main.cpp:25: undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'

The intellisense is working. It can see the function of SFML when I press window. for example. or sf::Renderwindow. Is there something wrong in the CMAKE again? thanks

This is btw my CMAKELISTS


Quote
set(SOURCE_FILES main.cpp)
add_executable(SFMLDemo3 ${SOURCE_FILES})

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/SFML-2.3.2/cmake/Modules/")
set(SFML_LIBRARIES "${CMAKE_SOURCE_DIR}/SFML-2.3.2/lib")
set(SFML_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/SFML-2.3.2/include")
MESSAGE(${SFML_INCLUDE_DIR} "   hahahaha")
find_package(SFML COMPONENTS system window graphics network audio)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(SFMLDemo3 ${SFML_LIBRARIES})
Title: Re: Having some issues with SFML
Post by: eXpl0it3r on February 09, 2016, 09:53:47 am
In case you haven't solved this yet, you need to change the order of search for the SFML libs:

find_package(SFML COMPONENTS audio network graphics window system)
Title: Re: Having some issues with SFML
Post by: leo.martin on March 06, 2016, 12:53:05 am
Did you find the solution ?