System : Debian 9.1 Stretch
Architecture : amd64
SFML version : 2.4
Hello i try to compile this ->
main.cpp
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
> g++ -c main.cpp
> g++ main.o -o test -lsfml-graphics -lsfml-window -lsfml-system
main.o: In function `main':
main.cpp:(.text+0xc8): undefined reference to `sf::CircleShape::CircleShape(float, unsigned int)'
collect2: error: ld returned 1 exit status
I've tried with cmake too
cmake_minimum_required(VERSION 2.6)
project(apathfindingsfml)
add_executable(apathfindingsfml main.cpp)
# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
set(CMAKE_MODULE_PATH "/usr/share/SFML/cmake/Modules")
#Find any version 2.X of SFML
#See the FindSFML.cmake file for additional details and instructions
find_package(SFML 2 COMPONENTS audio network graphics window system REQUIRED)
if(SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(apathfindingsfml ${SFML_LIBRARIES})
endif()
install(TARGETS apathfindingsfml RUNTIME DESTINATION bin)
> cmake .
-- Found SFML 2.1.0 in /usr/local/include
-- Configuring done
-- Generating done
-- Build files have been written to: /home/op/projects/APathFIndingSFML
I find this weird that cmake find SFML 2.1.0, since i have 2.4 installed in my computer
> sudo apt-cache search sfml
libcsfml-audio2.3 - Libraries for the C Binding of SFML - Audio Part
libcsfml-dev - Libraries for the C Binding of SFML - Development Files
libcsfml-doc - Libraries for the C Binding of SFML - Documentation
libcsfml-graphics2.3 - Libraries for the C Binding of SFML - Graphics Part
libcsfml-network2.3 - Libraries for the C Binding of SFML - Network Part
libcsfml-system2.3 - Libraries for the C Binding of SFML - System Part
libcsfml-window2.3 - Libraries for the C Binding of SFML - Window Part
libsfml-audio2.4 - Simple and Fast Multimedia Library - Audio part
libsfml-dev - Simple and Fast Multimedia Library - Development Files
libsfml-doc - Simple and Fast Multimedia Library - Documentation
libsfml-graphics2.4 - Simple and Fast Multimedia Library - Graphics part
libsfml-network2.4 - Simple and Fast Multimedia Library - Network part
libsfml-system2.4 - Simple and Fast Multimedia Library - System part
libsfml-window2.4 - Simple and Fast Multimedia Library - Window part
python-sfml - Simple and Fast Multimedia Library - Python 2 Bindings
python-sfml-dbg - Simple and Fast Multimedia Library - Python 2 Debug Bindings
python-sfml-doc - Simple and Fast Multimedia Library - Documentation
python3-sfml - Simple and Fast Multimedia Library - Python 3 Bindings
python3-sfml-dbg - Simple and Fast Multimedia Library - Python 3 Debug Bindings
dsfmlc - DSFMLC is the backend of DSFML, a awesome binding of SFML
Whatever, i tried to compile and then :
> make
[ 33%] Linking CXX executable apathfindingsfml
CMakeFiles/apathfindingsfml.dir/main.cpp.o: In function `main':
main.cpp:(.text+0xc8): undefined reference to `sf::CircleShape::CircleShape(float, unsigned int)'
collect2: error: ld returned 1 exit status
CMakeFiles/apathfindingsfml.dir/build.make:99: recipe for target 'apathfindingsfml' failed
make[2]: *** [apathfindingsfml] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/apathfindingsfml.dir/all' failed
make[1]: *** [CMakeFiles/apathfindingsfml.dir/all] Error 2
Makefile:116: recipe for target 'all' failed
make: *** [all] Error 2
So i change the argument "2" in find_package to "2.4" :
> cmake .
CMake Error at /usr/share/SFML/cmake/Modules/FindSFML.cmake:355 (message):
SFML found but version too low (requested: 2.4, found: 2.1.0)
Call Stack (most recent call first):
CMakeLists.txt:10 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/op/projects/APathFIndingSFML/CMakeFiles/CMakeOutput.log".
I've also try to see if the linking is correct, and it seem :
> sudo ldconfig -v | grep "sfml"
ldconfig: Can't stat /lib/i686-linux-gnu: No such file or directory
ldconfig: Can't stat /usr/lib/i686-linux-gnu: No such file or directory
ldconfig: Path `/usr/local/lib' given more than once
ldconfig: Path `/lib/x86_64-linux-gnu' given more than once
ldconfig: Path `/usr/lib/x86_64-linux-gnu' given more than once
ldconfig: /lib/i386-linux-gnu/ld-2.24.so is the dynamic linker, ignoring
ldconfig: /lib/x86_64-linux-gnu/ld-2.24.so is the dynamic linker, ignoring
libdsfmlc-system.so.2 -> libdsfmlc-system.so.2.1
libdsfmlc-graphics.so.2 -> libdsfmlc-graphics.so.2.1
libdsfmlc-window.so.2 -> libdsfmlc-window.so.2.1
libdsfmlc-network.so.2 -> libdsfmlc-network.so.2.1
libdsfmlc-audio.so.2 -> libdsfmlc-audio.so.2.1
libcsfml-system.so.2.3 -> libcsfml-system.so.2.3.0
libcsfml-audio.so.2.3 -> libcsfml-audio.so.2.3.0
libcsfml-network.so.2.3 -> libcsfml-network.so.2.3.0
libsfml-window.so.2.4 -> libsfml-window.so.2.4.1
libcsfml-window.so.2.3 -> libcsfml-window.so.2.3.0
libsfml-system.so.2.4 -> libsfml-system.so.2.4.1
libsfml-network.so.2.4 -> libsfml-network.so.2.4.1
libcsfml-graphics.so.2.3 -> libcsfml-graphics.so.2.3.0
libsfml-audio.so.2.4 -> libsfml-audio.so.2.4.1
libsfml-graphics.so.2.4 -> libsfml-graphics.so.2.4.1
ldconfig: /lib32/ld-2.24.so is the dynamic linker, ignoring
ldconfig: /lib/ld-lsb.so.3 is the dynamic linker, ignoring
Can you help me please to figure out the problem ?
Excuse me if my english isn't correct, this isn't my native language