SFML community forums

Help => General => Topic started by: tavrin on December 12, 2012, 05:13:50 pm

Title: [Weird] Linking problems
Post by: tavrin on December 12, 2012, 05:13:50 pm
Hello, I'm trying out SFML for the first time and everything worked fine, with the example code. So then I started integrating it with my project and came across a really weird problem. So I started with this piece of code:
#include <SFML/Window.hpp>

/*
 * @brief Main function, entry point
 *
 * @return      Exit code
 */


int main() {
        sf::Window window;
        return 0;
}
 

And got the following errors:
Quote
/usr/local/lib/libsfml-window.so: undefined reference to `sf::Clock::Reset()'
/usr/local/lib/libsfml-window.so: undefined reference to `sf::Unicode::UTF8Offsets'
/usr/local/lib/libsfml-window.so: undefined reference to `sf::Clock::Clock()'
/usr/local/lib/libsfml-window.so: undefined reference to `sf::Clock::GetElapsedTime() const'
/usr/local/lib/libsfml-window.so: undefined reference to `sf::Unicode::UTF8TrailingBytes'
/usr/local/lib/libsfml-window.so: undefined reference to `sf::Sleep(float)'

Now, I 'fixed' it like so:
#include <SFML/Window.hpp>

/*
 * @brief Main function, entry point
 *
 * @return      Exit code
 */


int main() {
        sf::Clock testClock; //this fixed the problem???!!!!
        sf::Window window;
        return 0;
}
 



it builds fine, no errors at all...

Someone please help me?

By the way, I'm using SFML 1. 6 on an Ubuntu machine
Title: Re: [Weird] Linking problems
Post by: tavrin on December 15, 2012, 04:58:50 pm
anyone? *bump*
Title: Re: [Weird] Linking problems
Post by: Laurent on December 15, 2012, 05:13:38 pm
Did you link to sfml-system?
Title: Re: [Weird] Linking problems
Post by: tavrin on December 16, 2012, 12:08:48 pm
Did you link to sfml-system?

Yes, I do so in my src/CMakeLists.txt
Quote
set(CMAKE_MODULE_PATH "../cmake_modules/" ${CMAKE_MODULE_PATH})
find_package(SFML 1.6 REQUIRED system window graphics network audio)
Title: Re: [Weird] Linking problems
Post by: Nexus on December 16, 2012, 12:17:27 pm
Yes, I do so in my src/CMakeLists.txt
Quote
set(CMAKE_MODULE_PATH "../cmake_modules/" ${CMAKE_MODULE_PATH})
find_package(SFML 1.6 REQUIRED system window graphics network audio)
No, you don't. What you do is finding the package, not linking. In CMake, you can link with the command target_link_libraries. The command names are quite expressive, aren't they? ;)

And I recommend to start with SFML 2. It has more features, less bugs and is actively developed.
Title: Re: [Weird] Linking problems
Post by: tavrin on December 16, 2012, 12:21:32 pm
Yes, I do so in my src/CMakeLists.txt
Quote
set(CMAKE_MODULE_PATH "../cmake_modules/" ${CMAKE_MODULE_PATH})
find_package(SFML 1.6 REQUIRED system window graphics network audio)
No, you don't. What you do is finding the package, not linking. In CMake, you can link with the command target_link_libraries. The command names are quite expressive, aren't they? ;)

And I recommend to start with SFML 2. It has more features, less bugs and is actively developed.

I tought SFML 2 was still in beta? And sorry, I forgot that portion where I actually link it, but it's in there:
Quote
#SFML lookup
set(CMAKE_MODULE_PATH "../cmake_modules/" ${CMAKE_MODULE_PATH})
find_package(SFML 1.6 REQUIRED system window graphics network audio)

#Executable
add_executable(${exec_name} ${exec_source_files})

#Libraries
set(project_libraries config engine graphics grid input unit util)
set(external_libraries ${SFML_LIBRARIES})
set(libraries  ${project_libraries} ${external_libraries})

#Libraries Link
target_link_libraries(${exec_name} ${libraries})
Title: Re: [Weird] Linking problems
Post by: Nexus on December 16, 2012, 12:34:33 pm
I tought SFML 2 was still in beta?
No, there is a release candidate. And you can get the newest sources from GitHub.

I suggest you try it with SFML 2, because the 1.x versions were not designed with CMake integration in mind. For example, the FindSFML module has been written for version 2.
Title: Re: [Weird] Linking problems
Post by: tavrin on December 16, 2012, 01:05:44 pm
I tought SFML 2 was still in beta?
No, there is a release candidate. And you can get the newest sources from GitHub.

I suggest you try it with SFML 2, because the 1.x versions were not designed with CMake integration in mind. For example, the FindSFML module has been written for version 2.

thanks, i'll give it a shot! :)
Title: Re: [Weird] Linking problems
Post by: tavrin on December 16, 2012, 01:42:38 pm
I tought SFML 2 was still in beta?
No, there is a release candidate. And you can get the newest sources from GitHub.

I suggest you try it with SFML 2, because the 1.x versions were not designed with CMake integration in mind. For example, the FindSFML module has been written for version 2.

Using SFML 2 indeed solved the problem!