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

Author Topic: Undefined reference to `sf::CircleShape::CircleShape(float, unsigned int)'  (Read 2217 times)

0 Members and 1 Guest are viewing this topic.

NathV

  • Newbie
  • *
  • Posts: 2
    • View Profile
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

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Undefined reference to `sf::CircleShape::CircleShape(float, unsigned int)'
« Reply #1 on: September 09, 2017, 08:19:27 pm »
Use file on your main.o, it looks somewhat like if you are using a 32 bit g++. A 64 bit compiler would look for sf::CircleShape::CircleShape(float, unsigned long) not sf::CircleShape::CircleShape(float, unsigned int) because that second argument in SFML code is std::size_t (that's a typedef that is unsigned int on 32 bit Linuxes and unsigned long on 64 bit ones).
Back to C++ gamedev with SFML in May 2023

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10830
    • View Profile
    • development blog
    • Email
Re: Undefined reference to `sf::CircleShape::CircleShape(float, unsigned int)'
« Reply #2 on: September 09, 2017, 09:05:15 pm »
Sounds like you've some old headers lying around.

At best you get rid of any traces of SFML and then do a clean install.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Undefined reference to `sf::CircleShape::CircleShape(float, unsigned int)'
« Reply #3 on: September 09, 2017, 09:21:07 pm »
That'd cause the same error message and make more sense than mixing 32 bit and 64 bit compilers/typedefs but they'd be such old headers.. wow. :o

https://github.com/SFML/SFML/commit/1cfa5c6f1d5ace7354d255e3870a2bdf63d143c6
Back to C++ gamedev with SFML in May 2023

NathV

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Undefined reference to `sf::CircleShape::CircleShape(float, unsigned int)'
« Reply #4 on: September 11, 2017, 03:23:22 pm »
Thank you all, i've desinstalled CSFML, SFML, DSFML and pySFML, and reinstalled SFML, and it work now.
I think the problem come from the fact that in /usr/include/SFML there is both SFML and CSFML header(SFML have for example Graphics.hpp, and CSFML have Graphics.h).

> ls /usr/include/SFML    
Audio      Config.hpp    Main.hpp     OpenGL.h    System.hpp
Audio.h    Graphics      Network      OpenGL.hpp  Window
Audio.hpp  Graphics.h    Network.h    System      Window.h
Config.h   Graphics.hpp  Network.hpp  System.h    Window.hpp
> sudo apt-get remove "libcsfml*"
> ls /usr/include/SFML          
Audio       Graphics      Network      System      Window.hpp
Audio.hpp   Graphics.hpp  Network.hpp  System.hpp
Config.hpp  Main.hpp      OpenGL.hpp   Window
 
« Last Edit: September 11, 2017, 03:25:53 pm by NathV »

 

anything