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

Author Topic: Link problem with SFML2  (Read 3138 times)

0 Members and 1 Guest are viewing this topic.

prchakal

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Link problem with SFML2
« on: May 17, 2013, 05:06:01 pm »
Hi,

I have a link problem im my temporary project:
https://github.com/prsolucoes/sfml-cmake-temp

The problem is when the compiler will link the libraries SFML2.

Can anyone analyse the CMakeLists.txt to see if find the problem to help me?

To test it, you only need:

1 - Download from github
2 - cd build
3 - ./rebuild.sh

My log:

Quote
Paulos-MacBook-Pro:build paulo$ ./rebuild.sh
-- The C compiler identification is Clang 4.2.0
-- The CXX compiler identification is Clang 4.2.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found SFML . in /Users/paulo/Documents/workspaces/cpp/sfml-cmake/library/sfml/mac/include
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/paulo/Documents/workspaces/cpp/sfml-cmake/build
/usr/local/Cellar/cmake/2.8.10.2/bin/cmake -H/Users/paulo/Documents/workspaces/cpp/sfml-cmake -B/Users/paulo/Documents/workspaces/cpp/sfml-cmake/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/Cellar/cmake/2.8.10.2/bin/cmake -E cmake_progress_start /Users/paulo/Documents/workspaces/cpp/sfml-cmake/build/CMakeFiles /Users/paulo/Documents/workspaces/cpp/sfml-cmake/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make -f CMakeFiles/sfml-project.dir/build.make CMakeFiles/sfml-project.dir/depend
cd /Users/paulo/Documents/workspaces/cpp/sfml-cmake/build && /usr/local/Cellar/cmake/2.8.10.2/bin/cmake -E cmake_depends "Unix Makefiles" /Users/paulo/Documents/workspaces/cpp/sfml-cmake /Users/paulo/Documents/workspaces/cpp/sfml-cmake /Users/paulo/Documents/workspaces/cpp/sfml-cmake/build /Users/paulo/Documents/workspaces/cpp/sfml-cmake/build /Users/paulo/Documents/workspaces/cpp/sfml-cmake/build/CMakeFiles/sfml-project.dir/DependInfo.cmake --color=
Dependee "/Users/paulo/Documents/workspaces/cpp/sfml-cmake/build/CMakeFiles/sfml-project.dir/DependInfo.cmake" is newer than depender "/Users/paulo/Documents/workspaces/cpp/sfml-cmake/build/CMakeFiles/sfml-project.dir/depend.internal".
Dependee "/Users/paulo/Documents/workspaces/cpp/sfml-cmake/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/Users/paulo/Documents/workspaces/cpp/sfml-cmake/build/CMakeFiles/sfml-project.dir/depend.internal".
Scanning dependencies of target sfml-project
make -f CMakeFiles/sfml-project.dir/build.make CMakeFiles/sfml-project.dir/build
/usr/local/Cellar/cmake/2.8.10.2/bin/cmake -E cmake_progress_report /Users/paulo/Documents/workspaces/cpp/sfml-cmake/build/CMakeFiles 1
[ 25%] Building CXX object CMakeFiles/sfml-project.dir/main.cpp.o
/usr/bin/c++    -g -I/Users/paulo/Documents/workspaces/cpp/sfml-cmake/library/sfml/mac/include    -o CMakeFiles/sfml-project.dir/main.cpp.o -c /Users/paulo/Documents/workspaces/cpp/sfml-cmake/main.cpp
/usr/local/Cellar/cmake/2.8.10.2/bin/cmake -E cmake_progress_report /Users/paulo/Documents/workspaces/cpp/sfml-cmake/build/CMakeFiles 2
[ 50%] Building CXX object CMakeFiles/sfml-project.dir/Engine.cpp.o
/usr/bin/c++    -g -I/Users/paulo/Documents/workspaces/cpp/sfml-cmake/library/sfml/mac/include    -o CMakeFiles/sfml-project.dir/Engine.cpp.o -c /Users/paulo/Documents/workspaces/cpp/sfml-cmake/Engine.cpp
/usr/local/Cellar/cmake/2.8.10.2/bin/cmake -E cmake_progress_report /Users/paulo/Documents/workspaces/cpp/sfml-cmake/build/CMakeFiles 3
[ 75%] Building CXX object CMakeFiles/sfml-project.dir/Util.cpp.o
/usr/bin/c++    -g -I/Users/paulo/Documents/workspaces/cpp/sfml-cmake/library/sfml/mac/include    -o CMakeFiles/sfml-project.dir/Util.cpp.o -c /Users/paulo/Documents/workspaces/cpp/sfml-cmake/Util.cpp
/usr/local/Cellar/cmake/2.8.10.2/bin/cmake -E cmake_progress_report /Users/paulo/Documents/workspaces/cpp/sfml-cmake/build/CMakeFiles 4
[100%] Building CXX object CMakeFiles/sfml-project.dir/ResourcePath.mm.o
/usr/bin/c++    -g -I/Users/paulo/Documents/workspaces/cpp/sfml-cmake/library/sfml/mac/include    -o CMakeFiles/sfml-project.dir/ResourcePath.mm.o -c /Users/paulo/Documents/workspaces/cpp/sfml-cmake/ResourcePath.mm
Linking CXX executable sfml-project.app/Contents/MacOS/sfml-project
/usr/local/Cellar/cmake/2.8.10.2/bin/cmake -E cmake_link_script CMakeFiles/sfml-project.dir/link.txt --verbose=1
/usr/bin/c++   -g -Wl,-search_paths_first -Wl,-headerpad_max_install_names -framework Foundation -w CMakeFiles/sfml-project.dir/main.cpp.o CMakeFiles/sfml-project.dir/Engine.cpp.o CMakeFiles/sfml-project.dir/Util.cpp.o CMakeFiles/sfml-project.dir/ResourcePath.mm.o  -o sfml-project.app/Contents/MacOS/sfml-project  ../library/sfml/mac/lib/libsfml-system.dylib ../library/sfml/mac/lib/libsfml-window.dylib ../library/sfml/mac/lib/libsfml-graphics.dylib ../library/sfml/mac/lib/libsfml-network.dylib ../library/sfml/mac/lib/libsfml-audio.dylib
Undefined symbols for architecture x86_64:
  "sf::String::String(std::string const&, std::locale const&)", referenced from:
      Engine::initializeGraphics() in Engine.cpp.o
  "sf::Texture::loadFromFile(std::string const&, sf::Rect<int> const&)", referenced from:
      Engine::run() in Engine.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [sfml-project.app/Contents/MacOS/sfml-project] Error 1
make[1]: *** [CMakeFiles/sfml-project.dir/all] Error 2
make: *** [all] Error 2

« Last Edit: May 17, 2013, 05:23:34 pm by prchakal »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Link problem with SFML2
« Reply #1 on: May 17, 2013, 05:39:58 pm »
Try to revert the components order in find_package(SFML ...).
Laurent Gomila - SFML developer

prchakal

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: Link problem with SFML2
« Reply #2 on: May 17, 2013, 05:42:43 pm »
I revert to:

Quote
find_package(SFML COMPONENTS audio network graphics window system REQUIRED)

The same problem :(

One question: I need add the sndfile and freetype to my SFML2 project?

prchakal

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: Link problem with SFML2
« Reply #3 on: May 17, 2013, 06:27:50 pm »
I made a modified file CMakeLists more organized.

But i have the problem now:

Quote
CMake Error at CMakeLists.txt:66 (target_link_libraries):
  Cannot specify link libraries for target "sfml-project" which is not built
  by this project.

The line that generate the error is:

Quote
target_link_libraries(${PROJECT_NAME} ${EXTRA_TARGET_LINK_LIBRARIES} ${SFML_LIBRARIES})

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Link problem with SFML2
« Reply #4 on: May 17, 2013, 07:06:54 pm »
Call target_link_libraries after add_executable.
Laurent Gomila - SFML developer

prchakal

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: Link problem with SFML2
« Reply #5 on: May 17, 2013, 07:18:28 pm »
Ok.

I already do it and work it.

But i have another problem (i think that is the last). I need add two framework to binary execute(sndfile and freetype). I can compile without it and it generate the binary, but when execute i got error that sndfile and freetype is not linked.

So to solve, i add the sndfile and freetype framework and made a new cmakelists. But if i put:

Quote
target_link_libraries(${PROJECT_NAME} ${EXTRA_TARGET_LINK_LIBRARIES} ${SFML_LIBRARIES} ${SNDFILE_LIBRARY} ${FREETYPE_LIBRARY})

The final command to link is:

Quote
Linking CXX executable sfml-project.app/Contents/MacOS/sfml-project
/usr/local/Cellar/cmake/2.8.10.2/bin/cmake -E cmake_link_script CMakeFiles/sfml-project.dir/link.txt --verbose=1
/usr/bin/c++   -g -Wl,-search_paths_first -Wl,-headerpad_max_install_names   CMakeFiles/sfml-project.dir/main.cpp.o CMakeFiles/sfml-project.dir/Engine.cpp.o CMakeFiles/sfml-project.dir/Util.cpp.o CMakeFiles/sfml-project.dir/ResourcePath.mm.o  -o sfml-project.app/Contents/MacOS/sfml-project  -F/Users/paulo/Documents/workspaces/cpp/sfml-cmake/library/freetype/mac/lib  -framework Foundation ../library/sfml/mac/lib/libsfml-audio.dylib ../library/sfml/mac/lib/libsfml-graphics.dylib ../library/sfml/mac/lib/libsfml-network.dylib ../library/sfml/mac/lib/libsfml-system.dylib ../library/sfml/mac/lib/libsfml-window.dylib -framework sndfile -framework freetype
ld: framework not found sndfile

In red you see that cmake only add a -F command to freetype.

So, if i remove freetype from target_link_libraries, like this:

Quote
target_link_libraries(${PROJECT_NAME} ${EXTRA_TARGET_LINK_LIBRARIES} ${SFML_LIBRARIES} ${SNDFILE_LIBRARY})

I get:

Quote
Linking CXX executable sfml-project.app/Contents/MacOS/sfml-project
/usr/local/Cellar/cmake/2.8.10.2/bin/cmake -E cmake_link_script CMakeFiles/sfml-project.dir/link.txt --verbose=1
/usr/bin/c++   -g -Wl,-search_paths_first -Wl,-headerpad_max_install_names   CMakeFiles/sfml-project.dir/main.cpp.o CMakeFiles/sfml-project.dir/Engine.cpp.o CMakeFiles/sfml-project.dir/Util.cpp.o CMakeFiles/sfml-project.dir/ResourcePath.mm.o  -o sfml-project.app/Contents/MacOS/sfml-project  -F/Users/paulo/Documents/workspaces/cpp/sfml-cmake/library/sndfile/mac/lib  -framework Foundation ../library/sfml/mac/lib/libsfml-audio.dylib ../library/sfml/mac/lib/libsfml-graphics.dylib ../library/sfml/mac/lib/libsfml-network.dylib ../library/sfml/mac/lib/libsfml-system.dylib ../library/sfml/mac/lib/libsfml-window.dylib -framework sndfile
/usr/local/Cellar/cmake/2.8.10.2/bin/cmake -E copy_directory /Users/paulo/Documents/workspaces/cpp/sfml-cmake/library/sfml/mac/lib /Users/paulo/Documents/workspaces/cpp/sfml-cmake/build/sfml-project.app/Contents/Frameworks
/usr/local/Cellar/cmake/2.8.10.2/bin/cmake -E copy_directory /Users/paulo/Documents/workspaces/cpp/sfml-cmake/library/sndfile/mac/lib /Users/paulo/Documents/workspaces/cpp/sfml-cmake/build/sfml-project.app/Contents/Frameworks
/usr/local/Cellar/cmake/2.8.10.2/bin/cmake -E copy_directory /Users/paulo/Documents/workspaces/cpp/sfml-cmake/library/freetype/mac/lib /Users/paulo/Documents/workspaces/cpp/sfml-cmake/build/sfml-project.app/Contents/Frameworks
/usr/local/Cellar/cmake/2.8.10.2/bin/cmake -E make_directory /Users/paulo/Documents/workspaces/cpp/sfml-cmake/build/sfml-project.app/Contents/Resources/js
/usr/local/Cellar/cmake/2.8.10.2/bin/cmake -E copy_directory /Users/paulo/Documents/workspaces/cpp/sfml-cmake/resources /Users/paulo/Documents/workspaces/cpp/sfml-cmake/build/sfml-project.app/Contents/Resources
/usr/local/Cellar/cmake/2.8.10.2/bin/cmake -E cmake_progress_report /Users/paulo/Documents/workspaces/cpp/sfml-cmake/build/CMakeFiles  1 2 3 4
[100%] Built target sfml-project

As you see, the -F command is to sndfile and the compilation was done.

So, how i can add parameter to sndfile and freetype framework path?

prchakal

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: Link problem with SFML2
« Reply #6 on: May 17, 2013, 09:08:56 pm »
Hi,

Problem +/- solved.

I dont need link to sndfile and freetype, i only need copy the *.framework to correct path.

Now everything is ok in the main project.

https://github.com/prsolucoes/sfml-cmake

 

anything