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

Author Topic: Having trouble solving SFML linker errors  (Read 7272 times)

0 Members and 1 Guest are viewing this topic.

robrene

  • Newbie
  • *
  • Posts: 5
    • View Profile
Having trouble solving SFML linker errors
« on: November 18, 2013, 05:20:49 pm »
Hello

I'm having trouble setting up SFML on my laptop running Ubuntu 13.10 (32 bit). I've managed to set it up successfully already on my PC running Arch Linux (64 bit), but after carefully reproducing the steps I took it still doesn't work.

I downloaded the SFML sources, ran cmake-gui and successfully configured the project to a second directory. Running make completes successfully, and all the files are successfully installed to /usr/local after calling make install.

On both my machines, I've set the environment variables:
LD_LIBRARY_PATH=/usr/local/lib
C_INCLUDE_PATH=/usr/local/include
CPLUS_INCLUDE_PATH=/usr/local/include

Just for testing purposes, I'm trying to build the example from http://www.sfml-dev.org/tutorials/2.1/start-linux.php

The command I'm using to build is:
g++ -O3 -Wall -Wextra -pedantic -std=c++11 -lsfml-graphics -lsfml-window -lsfml-system main.cpp
Even when I try adding the -L/usr/local flag, which shouldn't be necessary with my environment variables set, I still get SFML linker errors.

The following is the output I get, just for completeness' sake:

/tmp/cc9WdUuM.o: In function `main':
main.cpp:(.text.startup+0x5b): undefined reference to `sf::String::String(char const*, std::locale const&)'
main.cpp:(.text.startup+0x7f): undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
main.cpp:(.text.startup+0xba): undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
main.cpp:(.text.startup+0xee): undefined reference to `sf::CircleShape::CircleShape(float, unsigned int)'
main.cpp:(.text.startup+0xfa): undefined reference to `sf::Color::Green'
main.cpp:(.text.startup+0x102): undefined reference to `sf::Shape::setFillColor(sf::Color const&)'
main.cpp:(.text.startup+0x10c): undefined reference to `sf::Window::isOpen() const'
main.cpp:(.text.startup+0x130): undefined reference to `sf::Window::pollEvent(sf::Event&)'
main.cpp:(.text.startup+0x15c): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
main.cpp:(.text.startup+0x16f): undefined reference to `sf::RenderTarget::clear(sf::Color const&)'
main.cpp:(.text.startup+0x186): undefined reference to `sf::RenderStates::Default'
main.cpp:(.text.startup+0x18e): undefined reference to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'
main.cpp:(.text.startup+0x196): undefined reference to `sf::Window::display()'
main.cpp:(.text.startup+0x1a4): undefined reference to `sf::Window::close()'
main.cpp:(.text.startup+0x1b8): undefined reference to `vtable for sf::CircleShape'
main.cpp:(.text.startup+0x1c0): undefined reference to `vtable for sf::CircleShape'
main.cpp:(.text.startup+0x1c5): undefined reference to `sf::Shape::~Shape()'
main.cpp:(.text.startup+0x1cd): undefined reference to `sf::RenderWindow::~RenderWindow()'
main.cpp:(.text.startup+0x207): undefined reference to `sf::RenderWindow::~RenderWindow()'
main.cpp:(.text.startup+0x220): undefined reference to `vtable for sf::CircleShape'
main.cpp:(.text.startup+0x228): undefined reference to `vtable for sf::CircleShape'
main.cpp:(.text.startup+0x22d): undefined reference to `sf::Shape::~Shape()'
collect2: error: ld returned 1 exit status


Maybe I'm just missing a crucial step, or I'm missing something that I'm unaware I should be doing to get it running in Ubuntu. Nevertheless, I would appreciate a fresh set of eyes looking at my situation, because I can't seem to get this working by myself. Thanks in advance

metulburr

  • Newbie
  • *
  • Posts: 49
    • View Profile
    • Email
Re: Having trouble solving SFML linker errors
« Reply #1 on: November 23, 2013, 07:50:23 am »
Quote
I've managed to set it up successfully already on my PC running Arch Linux
that is easy, as SFML 2.1 and SFML 1.6 are both in the AUR.
metulburr@arch ~/$ pacaur -Ss sfml
community/sfml 2.1-1 [installed]
    A simple, fast, cross-platform, and object-oriented multimedia API
aur/sfml1.6 1.6-6 (15)
    A simple, fast, cross-platform, and object-oriented multimedia API

In ubuntu the method i use is just coping from the extracted sfml file to /usr
metulburr@ubuntu ~/Downloads/SFML-2.1 $ sudo cp -r include/SFML /usr/include
[sudo] password for metulburr:
metulburr@ubuntu ~/Downloads/SFML-2.1 $ sudo cp -r lib/* /usr/lib    
metulburr@ubuntu ~/Downloads/SFML-2.1 $ sudo cp -r share/SFML /usr/share  
metulburr@ubuntu ~/Downloads/SFML-2.1 $

and in my IDE's i execute:
g++ -std=c++11 -Wall -o "%e" "%f" -lsfml-audio -lsfml-graphics -lsfml-window -lsfml-system &&"./%e"
or via terminal:
metulburr@arch ~/Downloads $ g++ -std=c++11 test.cpp -o test -lsfml-audio -lsfml-graphics -lsfml-window -lsfml-system
metulburr@arch ~/Downloads $ ./test
 

It is in Windows, i have a hell of a time and have yet to compile a successful SFML example.

« Last Edit: November 23, 2013, 07:58:42 am by metulburr »
OS Ubuntu 13.04, Arch Linux, Gentoo, Windows 7/8
SFML 2.1
Ati Radeon HD 6770

wintertime

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Re: Having trouble solving SFML linker errors
« Reply #2 on: November 23, 2013, 11:08:25 am »
It is basically the same in Windows? If you add the bin directories of MinGW (for the build tools) and SFML (for the dll files) to the PATH environment variable (preferably permanently through some hidden Windows menu) and add -I or -L options pointing to include or lib directories of SFML to g++ command when compiling or linking it should go smoothly.

metulburr

  • Newbie
  • *
  • Posts: 49
    • View Profile
    • Email
Re: Having trouble solving SFML linker errors
« Reply #3 on: November 23, 2013, 11:43:00 am »
i get a g++.exe/cc1plus.exe/etc. No disk error when using the latest mingw. This led me to believe there was something wrong with the latest mingw based on some forums who said to get a different version. I am not sure how exactly as their website has no previous versions. I prefer cygwin, as then i have access to bash commands in wins command prompt, but SFML complained that it was the wrong type of operating system if i attempt to compile it with cygwin's gcc/g++.
C:\Users\micah_000>g++ -std=c++11 test.cpp -IC:\SFML-2.1\include -LC:\SFML-2.1\l
ib -o test -lsfml-audio -lsfml-system -lsfml-window -lsfml-graphics
cygwin warning:
  MS-DOS style path detected: C:\SFML-2.1\include
  Preferred POSIX equivalent is: /cygdrive/c/SFML-2.1/include
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
In file included from C:\SFML-2.1\include/SFML/System.hpp:32:0,
                 from C:\SFML-2.1\include/SFML/Window.hpp:32,
                 from C:\SFML-2.1\include/SFML/Graphics.hpp:32,
                 from test.cpp:1:
C:\SFML-2.1\include/SFML/Config.hpp:65:6: error: #error This operating system is
 not supported by SFML library
     #error This operating system is not supported by SFML library
      ^
In file included from C:\SFML-2.1\include/SFML/Window.hpp:40:0,
                 from C:\SFML-2.1\include/SFML/Graphics.hpp:32,
                 from test.cpp:1:
C:\SFML-2.1\include/SFML/Window/Window.hpp:105:34: error: expected `)' before `h
andle'
     explicit Window(WindowHandle handle, const ContextSettings& settings = Cont
extSettings());
                                  ^
C:\SFML-2.1\include/SFML/Window/Window.hpp:141:17: error: `WindowHandle' has not
 been declared
     void create(WindowHandle handle, const ContextSettings& settings = ContextS
ettings());
                 ^
C:\SFML-2.1\include/SFML/Window/Window.hpp:424:5: error: `WindowHandle' does not
 name a type
     WindowHandle getSystemHandle() const;
     ^
In file included from C:\SFML-2.1\include/SFML/Graphics.hpp:40:0,
                 from test.cpp:1:
C:\SFML-2.1\include/SFML/Graphics/RenderWindow.hpp:93:40: error: expected `)' be
fore `handle'
     explicit RenderWindow(WindowHandle handle, const ContextSettings& settings
= ContextSettings());
                                        ^

C:\Users\micah_000>
So then i just stole code blocks mingw and copied it over to c:\ to use instead. This at least successfully compiles. However running the program resusts in the error:
the procedure entry point __gxx_personality_v0 could not be located in the dynamic link library C:\SFML-2.1\bin\sfml-graphics-2.dll
with the command:
C:\Users\micah_000>g++ -std=c++11 test.cpp -IC:\SFML-2.1\include -LC:\SFML-2.1\l
ib -o test -lsfml-audio -lsfml-graphics -lsfml-window -lsfml-system
and i am not quite sure what that means. After how easy it is to install in any linux distro i find it quite absurd the process in windows.

EDIT:
oh ok so i came across that code blocks mingw needs sfml TDM. Which now it runs in windows. So in that case is there a version that would run by cygwin's gcc/g++?

Sorry OP, i didn't mean to hijack your thread.
« Last Edit: November 23, 2013, 12:29:33 pm by metulburr »
OS Ubuntu 13.04, Arch Linux, Gentoo, Windows 7/8
SFML 2.1
Ati Radeon HD 6770

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Re: Having trouble solving SFML linker errors
« Reply #4 on: November 23, 2013, 12:38:56 pm »
oh ok so i came across that code blocks mingw needs sfml TDM. Which now it runs in windows. So in that case is there a version that would run by cygwin's gcc/g++?
C++ libraries nedd to be compiled with the same compiler as you want to build your application with, therefore if you use C::B default compiler you'll need libs that where compiled with TDM as well. All the offical per-compiled libraries can be found on the download page and sincd there's no download for cygwin, there are no pre-compiled binaries. You can however easily build SFML on your own. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

wintertime

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Re: Having trouble solving SFML linker errors
« Reply #5 on: November 23, 2013, 02:39:09 pm »
Also you would not want to compile it with cygwin, because if not carefully configured it would use the incompatible cygwin gcc that needs a cygwin dll, not the MinGW gcc thats independent of it.
You want MSYS (from MinGW) if you need a bash shell that is configured to use MinGW gcc that depends on the msvcrt.dll files installed on all Windows versions, but could somehow also be made dependent on a msys dll for posix emulation (though you would typically not want this if its not a contrived pure UNIX program you are not able to make crossplatform).
There is also the colored bash from msys-git, but they made it independent and I therefore had no luck in compiling from that.

(Sorry for derailing the thread.)
« Last Edit: November 23, 2013, 02:42:52 pm by wintertime »

 

anything