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

Author Topic: Functioning Project for Running SFML in CLion IDE  (Read 7255 times)

0 Members and 1 Guest are viewing this topic.

MS07112

  • Newbie
  • *
  • Posts: 3
    • View Profile
Functioning Project for Running SFML in CLion IDE
« on: July 20, 2017, 12:54:19 pm »
:D Hello Everyone, 

I have been trying to successfully compile and run the SFML HelloWorld program in CLion, but was constantly bombarded by CMake linker errors and other problems.

Thankfully though, I have been able to modify the CMake and other settings to get the CLion IDE to successfully compile and run the executable. And have now uploaded the whole project folder to my GitHub so that users trying to develop SFML with CLion can get started easily.

Here's the GitHub page:
https://github.com/MS07112/CLion_SFML_HelloWorld

YouTube video about the CLion project:
https://www.youtube.com/watch?v=SbBz_94bk1Y&feature=youtu.be


This project was done on an Arch-based Linux OS (Manjaro 17.0.2 Gellivara), using the CLion package from the AUR (Arch User Repository).

CPU Architecture:  x86_64
Linux Kernel:  4.9.37

Thanks!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Functioning Project for Running SFML in CLion IDE
« Reply #1 on: July 20, 2017, 01:07:18 pm »
Hard coding where GCC and G++ are located isn't a very good idea.
For one it's not portable and otherwise CLion should find those when you properly setup the toolchain.
Alternatively you can just set them by editing the cache file, so it works for your local installation and isn't hard coded into your CMake project file.

The order you're requesting the SFML libraries is wrong. It should be like when you're linking libraries manually. I just use the "depends on"-rule, so sfml-graphics "depends on" sfml-window "depends on" sfml-system, so the order should be graphics, window and system (audio and network only depend on sfml-system).

I wouldn't mix project name and executable name. When you're linking a library you need to pass it the project name and not the executable name.

Additionally I recommend you also add ${SFML_DEPENDENCIES} after ${SFML_LIBRARIES} just in case you ever want to link statically, so you already link the potential SFML dependencies.

A while ago I've used CLion for the Ludum Dare game jam, so if you want, you can also check out the CMake file I created back then. It's not perfect and I just force static linking as I was developing on Windows, but maybe you see one or the other thing.
« Last Edit: July 20, 2017, 01:09:35 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MS07112

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Functioning Project for Running SFML in CLion IDE
« Reply #2 on: July 21, 2017, 10:31:05 am »
Thank you very much for the advice on CMake, as I'm still very new to its usage.

I tried to use the invocation order listed in the example file you linked, but unfortunately the compiler/linker/??? freaked out (again) and told me this time that it couldn't find SFML. I went back to the old order (which was based on someone's StackOverflow post -- see my GitHub page's README for the link) and it worked (I have no clue).

TBH: I have a limited understanding as to what is going on with CMake, and am basically 'walking on eggshells' whilst hoping that the compiler will have mercy on me and let me write a simple HelloWorld program so I can start learning SFML (instead of how to debug whatever terrible creature lies beneath the IDE  ;D).

The CMake file should definitely be fixed up, but I'm not versed enough in its usage to know what to do. I'd definitely be thankful if  someone could write and upload a suitable example project; as that's what I've been after this whole time.

Thanks

MS07112

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Functioning Project for Running SFML in CLion IDE
« Reply #3 on: July 21, 2017, 11:58:15 am »
Here is a cleaner version of the CMakeLists.txt file:

Quote
cmake_minimum_required(VERSION 3.7)
project(Game)

set(CMAKE_CXX_STANDARD 11)

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


# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
find_package(SFML 2 REQUIRED system window graphics network audio)
if(SFML_FOUND)
    include_directories(${SFML_INCLUDE_DIR})
    target_link_libraries(${PROJECT_NAME} ${SFML_LIBRARIES})
endif()

seyuup

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Functioning Project for Running SFML in CLion IDE
« Reply #4 on: August 16, 2017, 05:26:58 pm »
Hey! Another CLion user!
I too used to have problems getting CLion to work with SFML. When I get a chance today I'll see if I can help you with your problem.

Edit: That's if you're still experiencing it, as your last post was in July.