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

Author Topic: undefined reference to `sf::CircleShape  (Read 3477 times)

0 Members and 1 Guest are viewing this topic.

lewashby

  • Newbie
  • *
  • Posts: 7
    • View Profile
undefined reference to `sf::CircleShape
« on: July 25, 2016, 02:13:14 am »
This compile command
g++ -o run09 main-09.cpp -lsfml-graphics -lsfml-window -lsfml-system

Is giving me this error
/tmp/ccaxb42w.o: In function `main':
main-09.cpp:(.text+0x189): undefined reference to `sf::CircleShape::CircleShape(float, unsigned long)'
collect2: error: ld returned 1 exit status

For this program
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(300, 200), "New Window");
    sf::CircleShape shape(50);
    shape.setFillColor(sf::Color::Red);
    shape.setPosition(sf::Vector2f(150, 100));
    sf::RectangleShape rectshape(sf::Vector2f(50, 50));
    rectshape.setFillColor(sf::Color::Blue);

    while(window.isOpen())
    {
        sf::Event event;

        while(window.pollEvent(event))
        {
            switch(event.type)
            {
            case sf::Event::Closed:
                window.close();
                break;
            case sf::Event::KeyPressed:
                if(event.key.code == sf::Keyboard::Space)
                {
                    window.setTitle("Space Pressed");
                }

                break;
            }
        }

        window.clear(sf::Color::Black);
        window.draw(shape);
        window.draw(rectshape);
        window.display();
    }

    return 0;
}
 
Any ideas?
« Last Edit: July 25, 2016, 07:56:09 am by Laurent »

GameBear

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
    • Email
Re: undefined reference to `sf::CircleShape
« Reply #1 on: July 25, 2016, 09:19:19 am »
Without computing it, I think the error is this line:
  sf::CircleShape shape(50);
Circleshapes constructor takes 2 arguments, radius and points.
Either try this:
  sf::CircleShape shape(50,30);
Where 30 is the number of points making the circle
Or do this
  sf::CircleShape shape;
 shape.setRadius(50);

:)
« Last Edit: July 25, 2016, 09:20:53 am by GameBear »
string message = "some random dude";
cout << "I'm just " << message;

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: undefined reference to `sf::CircleShape
« Reply #2 on: July 25, 2016, 01:01:31 pm »
sf::CircleShape is fine taking just a single parameter for its radius. Both parameters have default values so you can leave off both or just the second one (points).

I tested this code you provided and it executes perfectly.

The error you are receiving looks to me like a linker problem. One thing that can cause this error is if the actual libraries that are alongside the executable are not the exact same version as the libraries inluded and linked. This often happens if you get change versions but forget to change the libraries that accompany the executable or change those libraries but forget to update which version you're linking to.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

lewashby

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: undefined reference to `sf::CircleShape
« Reply #3 on: July 26, 2016, 03:05:20 am »
sf::CircleShape is fine taking just a single parameter for its radius. Both parameters have default values so you can leave off both or just the second one (points).

I tested this code you provided and it executes perfectly.

The error you are receiving looks to me like a linker problem. One thing that can cause this error is if the actual libraries that are alongside the executable are not the exact same version as the libraries inluded and linked. This often happens if you get change versions but forget to change the libraries that accompany the executable or change those libraries but forget to update which version you're linking to.

How can I find this out and fix this problem. I dropped all of my SFML header files in /usr/local/include/SFML/

Here's list

Quote
garrett@mint-desktop include $ pwd
/usr/local/include
garrett@mint-desktop include $ ls -lR
.:
total 4
drwxr-xr-x 8 garrett garrett 4096 Jul 23 20:34 SFML

./SFML:
total 60
drwxr-xr-x 2 garrett garrett 4096 Oct 27  2015 Audio
-rwxr-xr-x 1 garrett garrett 2095 May  8  2015 Audio.hpp
-rwxr-xr-x 1 garrett garrett 5342 Sep 11  2015 Config.hpp
drwxr-xr-x 2 garrett garrett 4096 Oct 27  2015 Graphics
-rwxr-xr-x 1 garrett garrett 2530 May  8  2015 Graphics.hpp
-rwxr-xr-x 1 garrett garrett 1521 May  8  2015 Main.hpp
drwxr-xr-x 2 garrett garrett 4096 Oct 27  2015 Network
-rwxr-xr-x 1 garrett garrett 1982 May  8  2015 Network.hpp
-rwxr-xr-x 1 garrett garrett 2252 May  8  2015 OpenGL.hpp
drwxr-xr-x 2 garrett garrett 4096 Jul 23 20:02 SFML
drwxr-xr-x 2 garrett garrett 4096 Oct 27  2015 System
-rwxr-xr-x 1 garrett garrett 2287 May  8  2015 System.hpp
drwxr-xr-x 2 garrett garrett 4096 Oct 27  2015 Window
-rwxr-xr-x 1 garrett garrett 2046 May  8  2015 Window.hpp

./SFML/Audio:
total 160
-rw-r--r-- 1 garrett garrett  2327 May  8  2015 AlResource.hpp
-rw-r--r-- 1 garrett garrett  1662 May  8  2015 Export.hpp
-rw-r--r-- 1 garrett garrett  9318 May  8  2015 InputSoundFile.hpp
-rw-r--r-- 1 garrett garrett  8910 May  8  2015 Listener.hpp
-rw-r--r-- 1 garrett garrett  8232 Jul  6  2015 Music.hpp
-rw-r--r-- 1 garrett garrett  4523 May  8  2015 OutputSoundFile.hpp
-rw-r--r-- 1 garrett garrett 12929 May  8  2015 SoundBuffer.hpp
-rw-r--r-- 1 garrett garrett  4848 May  8  2015 SoundBufferRecorder.hpp
-rw-r--r-- 1 garrett garrett  7190 May  8  2015 SoundFileFactory.hpp
-rw-r--r-- 1 garrett garrett  3154 May  8  2015 SoundFileFactory.inl
-rw-r--r-- 1 garrett garrett  5889 May  8  2015 SoundFileReader.hpp
-rw-r--r-- 1 garrett garrett  4430 May  8  2015 SoundFileWriter.hpp
-rw-r--r-- 1 garrett garrett  9266 May  8  2015 Sound.hpp
-rw-r--r-- 1 garrett garrett 14059 Jul  6  2015 SoundRecorder.hpp
-rw-r--r-- 1 garrett garrett 10387 May  8  2015 SoundSource.hpp
-rw-r--r-- 1 garrett garrett 14785 May  8  2015 SoundStream.hpp

./SFML/Graphics:
total 332
-rw-r--r-- 1 garrett garrett  9700 May  8  2015 BlendMode.hpp
-rw-r--r-- 1 garrett garrett  5344 May  8  2015 CircleShape.hpp
-rw-r--r-- 1 garrett garrett  9789 May  8  2015 Color.hpp
-rw-r--r-- 1 garrett garrett  5391 May  8  2015 ConvexShape.hpp
-rw-r--r-- 1 garrett garrett  3822 May  8  2015 Drawable.hpp
-rw-r--r-- 1 garrett garrett  1680 May  8  2015 Export.hpp
-rw-r--r-- 1 garrett garrett 17082 Sep 11  2015 Font.hpp
-rw-r--r-- 1 garrett garrett  2753 May  8  2015 Glyph.hpp
-rw-r--r-- 1 garrett garrett 12310 May  8  2015 Image.hpp
-rw-r--r-- 1 garrett garrett  2194 May  8  2015 PrimitiveType.hpp
-rw-r--r-- 1 garrett garrett  4465 May  8  2015 RectangleShape.hpp
-rw-r--r-- 1 garrett garrett  8763 May  8  2015 Rect.hpp
-rw-r--r-- 1 garrett garrett  5100 May  8  2015 Rect.inl
-rw-r--r-- 1 garrett garrett  6538 Jul  6  2015 RenderStates.hpp
-rw-r--r-- 1 garrett garrett 17532 May  8  2015 RenderTarget.hpp
-rw-r--r-- 1 garrett garrett 10188 May  8  2015 RenderTexture.hpp
-rw-r--r-- 1 garrett garrett  9637 May  8  2015 RenderWindow.hpp
-rw-r--r-- 1 garrett garrett 26008 Jul  6  2015 Shader.hpp
-rw-r--r-- 1 garrett garrett 13668 May  8  2015 Shape.hpp
-rw-r--r-- 1 garrett garrett 10685 May  8  2015 Sprite.hpp
-rw-r--r-- 1 garrett garrett 13917 May  8  2015 Text.hpp
-rw-r--r-- 1 garrett garrett 24256 Sep 11  2015 Texture.hpp
-rw-r--r-- 1 garrett garrett 16396 May  8  2015 Transformable.hpp
-rw-r--r-- 1 garrett garrett 16047 May  8  2015 Transform.hpp
-rw-r--r-- 1 garrett garrett  7768 May  8  2015 VertexArray.hpp
-rw-r--r-- 1 garrett garrett  5615 May  8  2015 Vertex.hpp
-rw-r--r-- 1 garrett garrett 12285 May  8  2015 View.hpp

./SFML/Network:
total 140
-rw-r--r-- 1 garrett garrett  1674 May  8  2015 Export.hpp
-rw-r--r-- 1 garrett garrett 24912 May  8  2015 Ftp.hpp
-rw-r--r-- 1 garrett garrett 19862 May  8  2015 Http.hpp
-rw-r--r-- 1 garrett garrett 12663 May  8  2015 IpAddress.hpp
-rw-r--r-- 1 garrett garrett 13974 May  8  2015 Packet.hpp
-rw-r--r-- 1 garrett garrett  1773 May  8  2015 SocketHandle.hpp
-rw-r--r-- 1 garrett garrett  7701 May  8  2015 Socket.hpp
-rw-r--r-- 1 garrett garrett  9312 May  8  2015 SocketSelector.hpp
-rw-r--r-- 1 garrett garrett  5366 May  8  2015 TcpListener.hpp
-rw-r--r-- 1 garrett garrett 11300 May  8  2015 TcpSocket.hpp
-rw-r--r-- 1 garrett garrett 10735 May  8  2015 UdpSocket.hpp

./SFML/SFML:
total 0

./SFML/System:
total 244
-rw-r--r-- 1 garrett garrett  3713 May  8  2015 Clock.hpp
-rw-r--r-- 1 garrett garrett  2641 May  8  2015 Err.hpp
-rw-r--r-- 1 garrett garrett  1668 May  8  2015 Export.hpp
-rw-r--r-- 1 garrett garrett  5442 Jul  6  2015 FileInputStream.hpp
-rw-r--r-- 1 garrett garrett  4855 May  8  2015 InputStream.hpp
-rw-r--r-- 1 garrett garrett  4246 May  8  2015 Lock.hpp
-rw-r--r-- 1 garrett garrett  5193 May  8  2015 MemoryInputStream.hpp
-rw-r--r-- 1 garrett garrett  4972 May  8  2015 Mutex.hpp
-rw-r--r-- 1 garrett garrett  4302 May  8  2015 NonCopyable.hpp
-rw-r--r-- 1 garrett garrett  1821 May  8  2015 Sleep.hpp
-rw-r--r-- 1 garrett garrett 25366 May  8  2015 String.hpp
-rw-r--r-- 1 garrett garrett  1785 May  8  2015 String.inl
-rw-r--r-- 1 garrett garrett  9233 May  8  2015 Thread.hpp
-rw-r--r-- 1 garrett garrett  2776 May  8  2015 Thread.inl
-rw-r--r-- 1 garrett garrett  3415 May  8  2015 ThreadLocal.hpp
-rw-r--r-- 1 garrett garrett  5000 May  8  2015 ThreadLocalPtr.hpp
-rw-r--r-- 1 garrett garrett  2210 May  8  2015 ThreadLocalPtr.inl
-rw-r--r-- 1 garrett garrett 16061 May  8  2015 Time.hpp
-rw-r--r-- 1 garrett garrett 35528 May  8  2015 Utf.hpp
-rw-r--r-- 1 garrett garrett 21501 May  8  2015 Utf.inl
-rw-r--r-- 1 garrett garrett  9778 May  8  2015 Vector2.hpp
-rw-r--r-- 1 garrett garrett  4158 May  8  2015 Vector2.inl
-rw-r--r-- 1 garrett garrett  9785 May  8  2015 Vector3.hpp
-rw-r--r-- 1 garrett garrett  4428 May  8  2015 Vector3.inl

./SFML/Window:
total 132
-rw-r--r-- 1 garrett garrett  4982 May  8  2015 Context.hpp
-rw-r--r-- 1 garrett garrett  6293 May  8  2015 ContextSettings.hpp
-rw-r--r-- 1 garrett garrett 13214 May  8  2015 Event.hpp
-rw-r--r-- 1 garrett garrett  1668 May  8  2015 Export.hpp
-rw-r--r-- 1 garrett garrett  2586 May  8  2015 GlResource.hpp
-rw-r--r-- 1 garrett garrett  8608 Jul  6  2015 Joystick.hpp
-rw-r--r-- 1 garrett garrett  8219 May  8  2015 Keyboard.hpp
-rw-r--r-- 1 garrett garrett  6321 May  8  2015 Mouse.hpp
-rw-r--r-- 1 garrett garrett  5820 May  8  2015 Sensor.hpp
-rw-r--r-- 1 garrett garrett  5037 May  8  2015 Touch.hpp
-rw-r--r-- 1 garrett garrett  8690 May  8  2015 VideoMode.hpp
-rw-r--r-- 1 garrett garrett  2368 May  8  2015 WindowHandle.hpp
-rw-r--r-- 1 garrett garrett 23120 May  8  2015 Window.hpp
-rw-r--r-- 1 garrett garrett  1961 May  8  2015 WindowStyle.hpp
garrett@mint-desktop include $

lewashby

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: undefined reference to `sf::CircleShape
« Reply #4 on: July 26, 2016, 03:19:36 am »
Did a complete removal and reinstalled and now everything is working just fine. Thanks. How do I mark solved?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: undefined reference to `sf::CircleShape
« Reply #5 on: July 26, 2016, 12:33:45 pm »
You're welcome :)

To mark as solved, you can simply edit the original post (the first one) and change the subject there to begin with [SOLVED] like this:
[SOLVED] undefined reference to `sf::CircleShape
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*