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

Author Topic: Undefined References  (Read 6270 times)

0 Members and 1 Guest are viewing this topic.

joeparrilla

  • Newbie
  • *
  • Posts: 14
    • View Profile
Undefined References
« on: November 12, 2011, 05:54:28 pm »
Hey everyone. So I followed the SFML Coder page exactly to get sfml 2.0 set up using gcc.
This page : http://sfmlcoder.wordpress.com/2011/08/16/building-sfml-2-0-with-make-for-gcc/

It seemed to be all correct. I then wrote this simple program:

Code: [Select]
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

int main()
{
sf::VideoMode VMode(800, 600, 32);
sf::RenderWindow Window(VMode, "SFML Window");

while (Window.IsOpened())
{
sf::Event Event;
while (Window.PollEvent(Event))
{
switch (Event.Type)
{
case sf::Event::Closed:
Window.Close();
break;
default:
break;
}
}

Window.Clear(sf::Color(0, 255, 255));
Window.Display();
}

return 0;
}


and all I get is this message, which basically is telling me that it doesnt see any of the sfml stuff:

joe@joe-Latitude-D620:~/Desktop$ gcc -c sfmlwindow.cpp
joe@joe-Latitude-D620:~/Desktop$ gcc -o sfmlwindow sfmlwindow.o
sfmlwindow.o: In function `main':
sfmlwindow.cpp:(.text+0x30): undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
sfmlwindow.cpp:(.text+0x76): undefined reference to `std::allocator<char>::allocator()'
sfmlwindow.cpp:(.text+0x98): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
sfmlwindow.cpp:(.text+0xe3): undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long, sf::ContextSettings const&)'
sfmlwindow.cpp:(.text+0xf2): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
sfmlwindow.cpp:(.text+0x101): undefined reference to `std::allocator<char>::~allocator()'
sfmlwindow.cpp:(.text+0x11f): undefined reference to `sf::Window::Close()'
sfmlwindow.cpp:(.text+0x137): undefined reference to `sf::Window::PollEvent(sf::Event&)'
sfmlwindow.cpp:(.text+0x16a): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
sfmlwindow.cpp:(.text+0x184): undefined reference to `sf::RenderTarget::Clear(sf::Color const&)'
sfmlwindow.cpp:(.text+0x190): undefined reference to `sf::Window::Display()'
sfmlwindow.cpp:(.text+0x19c): undefined reference to `sf::Window::IsOpened() const'
sfmlwindow.cpp:(.text+0x1b1): undefined reference to `sf::RenderWindow::~RenderWindow()'
sfmlwindow.cpp:(.text+0x1c9): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
sfmlwindow.cpp:(.text+0x1d9): undefined reference to `sf::RenderWindow::~RenderWindow()'
sfmlwindow.cpp:(.text+0x1ec): undefined reference to `std::allocator<char>::~allocator()'
sfmlwindow.cpp:(.text+0x204): undefined reference to `sf::RenderWindow::~RenderWindow()'
sfmlwindow.o:(.eh_frame+0x4b): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status


ANY IDEAS?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Undefined References
« Reply #1 on: November 12, 2011, 06:05:59 pm »
Code: [Select]
g++ -c sfmlwindow.cpp
g++ -o sfmlwindow sfmlwindow.o -lsfml-window -lsfml-system
Laurent Gomila - SFML developer

joeparrilla

  • Newbie
  • *
  • Posts: 14
    • View Profile
Undefined References
« Reply #2 on: November 12, 2011, 06:16:13 pm »
Quote from: "Laurent"
Code: [Select]
g++ -c sfmlwindow.cpp
g++ -o sfmlwindow sfmlwindow.o -lsfml-window -lsfml-system


Of course! Thanks so much I completely forgot about that.

But I am getting this now:

joe@joe-Latitude-D620:~/Desktop$ gcc -c sfmlwindow.cpp
joe@joe-Latitude-D620:~/Desktop$ gcc -o sfmlwindow sfmlwindow.o -lsfml-graphics -lsfml-window -lsfml-system
joe@joe-Latitude-D620:~/Desktop$ ./sfmlwindow
./sfmlwindow: error while loading shared libraries: libsfml-graphics.so.2: cannot open shared object file: No such file or directory


Sorry for this, but Im coming from a lot of Java game development in eclipse so Im not used to linking a bunch of libraries :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Undefined References
« Reply #3 on: November 12, 2011, 07:13:29 pm »
libsfml-graphics.so.2 must be in a path that the library loader (ld) knows. So either you didn't install SFML properly, or you installed it to a path that it doesn't know.
Laurent Gomila - SFML developer

joeparrilla

  • Newbie
  • *
  • Posts: 14
    • View Profile
Undefined References
« Reply #4 on: November 12, 2011, 08:31:50 pm »
Quote from: "Laurent"
libsfml-graphics.so.2 must be in a path that the library loader (ld) knows. So either you didn't install SFML properly, or you installed it to a path that it doesn't know.


When following the link I posted to install all of this, libsfml-graphics.so.2 wound up  in my Home directory in a subfolder called sfml2.0

It is there along with all the other lib files. Is there something I can do from here or do I have to wipe and redo all of this? Would adding that folder to my PATH work?

EDIT: If I move the exe into the sfml folder where the ]libsfml-graphics.so.2 is located, it works fine. How can I get the lib files to be visible everywhere? Im guessing the PATH variable...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Undefined References
« Reply #5 on: November 12, 2011, 11:09:31 pm »
Why did it install in your home folder? Did you change the CMAKE_INSTALL_PREFIX CMake variable? By default it should go to /usr/local/lib.

Adding a path to ld is an easy task but I don't know how to do it permanently (I work on Windows). However to do it temporarily, you can set the LD_LIBRARY_PATH environment variable before running the executable.
Laurent Gomila - SFML developer

 

anything