I'm just recently came to know the existence of SFML and I wanted to try it out !
So I followed the instructions from the SFML Github Wiki using Cmake with Clion on Windows
Here's where I installed SFML : `C:\SFML`
Here's the layout of my Clion project folder : http://prntscr.com/ezgo1n
Here's the content of my `main.cpp`:
#include "config.h"
#define SFML_STATIC
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
int main()
{
sf::Window w(sf::VideoMode(800,600),"da");
return 0;
}
Here's the content of the `config.h.in` file:
#define Adventures_VERSION_MAJOR @Adventures_VERSION_MAJOR@
#define Adventures_VERSION_MINOR @Adventures_VERSION_MINOR@
Here's the content of my `CMakeLists.txt`: https://pastebin.com/2QQCycEv
And finally here's the error I got :
"C:\Program Files (x86)\JetBrains\CLion 2016.3.2\bin\cmake\bin\cmake.exe" --build C:\Users\user\Documents\Projects\Adventures\cmake-build-debug --target Adventures -- -j 4
[ 50%] Linking CXX executable Adventures.exe
CMakeFiles\Adventures.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/user/Documents/Projects/Adventures/main.cpp:10: undefined reference to `sf::String::String(char const*, std::locale const&)'
C:/Users/user/Documents/Projects/Adventures/main.cpp:10: undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
C:/Users/user/Documents/Projects/Adventures/main.cpp:10: undefined reference to `sf::Window::Window(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
C:/Users/user/Documents/Projects/Adventures/main.cpp:10: undefined reference to `sf::Window::~Window()'
C:/Users/user/Documents/Projects/Adventures/main.cpp:10: undefined reference to `sf::Window::~Window()'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\Adventures.dir\build.make:101: recipe for target 'Adventures.exe' failed
mingw32-make.exe[3]: *** [Adventures.exe] Error 1
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Adventures.dir/all' failed
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/Adventures.dir/rule' failed
mingw32-make.exe[2]: *** [CMakeFiles/Adventures.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/Adventures.dir/rule] Error 2
Makefile:183: recipe for target 'Adventures' failed
mingw32-make.exe: *** [Adventures] Error 2
And I can't seem to figure it out... I've looked all over stackoverflow, the forums, nothing fixed it
Any clue ?
[1]: https://github.com/SFML/SFML/wiki/Tutorial%3A-Build-your-SFML-project-with-CMake
I'm not an expert in any of this, but I got an example working.
Using:
CLion 2016.3.2, with included cmake
mingw64
SFML 2.4 for mingw64, installed to C:/SFML
CMakeLists.txt
https://pastebin.com/PxhBfWmc (https://pastebin.com/PxhBfWmc)
I had to add line 16 and change link 22 from TARGET to my project name.
Looking at your project setup, it looks like the SFML dll files are in the root of your project directory. The dlls should be in the cmake-build-debug directory where the executable (Adventure.exe) is placed after building the project.
main.cpp
#include "config.h"
#include <iostream>
#include <SFML/Window.hpp>
int main()
{
sf::Window window(sf::VideoMode(800, 600), "My window");
// run the program as long as the window is open
while (window.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
}
}
return 0;
}