2013-01-12 4 views
1
project (2dplatformer) 
cmake_minimum_required (VERSION 2.8) 

set(CMAKE_MODULE_PATH ${sfmle_SOURCE_DIR}/cmake/modules 
         ${CMAKE_MODULE_PATH}) 

find_package(SFML 2.0 REQUIRED audio graphics network system window) 

include_directories (${SFML_INCLUDE_DIR}) 
link_libraries (${SFML_LIBRARIES}) 

add_library (Tilemap.o src/Tilemap.cpp) 
add_library (State.o src/State.cpp) 
add_library (TitleState.o src/TitleState.cpp) 
add_library (PlayState.o src/PlayState.cpp) 
add_library (Player.o src/Player.cpp) 

add_executable (2dplatformer src/Game.cpp) 
target_link_libraries (2dplatformer sfml-audio sfml-system sfml-graphics sfml-window Player.o PlayState.o Tilemap.o State.o TitleState.o) 

C'est mon CMakeLists.txt, que j'utilise pour construire mon projet.Liaison ne fonctionne pas correctement

[ 16%] Built target TitleState.o 
[ 33%] Built target Tilemap.o 
[ 50%] Built target Player.o 
[ 66%] Built target PlayState.o 
[ 83%] Built target State.o 
Linking CXX executable 2dplatformer 
libPlayState.o.a(PlayState.cpp.o): In function `PlayState::PlayState(Game*)': 
PlayState.cpp:(.text+0x286): undefined reference to `Player::Player(Game*, Tilemap*)' 
libPlayState.o.a(PlayState.cpp.o): In function `PlayState::update()': 
PlayState.cpp:(.text+0x378): undefined reference to `Player::update()' 
libPlayState.o.a(PlayState.cpp.o): In function `PlayState::draw()': 
PlayState.cpp:(.text+0x44f): undefined reference to `Player::draw()' 
collect2: error: ld returned 1 exit status 
make[2]: *** [2dplatformer] Error 1 
make[1]: *** [CMakeFiles/2dplatformer.dir/all] Error 2 
make: *** [all] Error 2 

Mon jeu fonctionne très bien quand j'utilise cette Makefile très mal écrit:

LIBS=-lsfml-graphics -lsfml-window -lsfml-system 

all: 
    @echo "*** Building the game" 

    g++ -c "src/Tilemap.cpp" -o "build/Tilemap.o" 
    g++ -c "src/State.cpp"  -o "build/State.o" 
    g++ -c "src/TitleState.cpp" -o "build/TitleState.o" 
    g++ -c "src/PlayState.cpp" -o "build/PlayState.o" 
    g++ -c "src/Game.cpp"  -o "build/Game.o" 
    g++ -c "src/Player.cpp"  -o "build/Player.o" 
    g++ -o 2dplatformer build/Tilemap.o build/Game.o build/State.o build/Player.o build/TitleState.o build/PlayState.o $(LIBS) 

map_editor: 
    @echo "*** Building the level editor" 

    g++ -c "src/Tilemap.cpp" -o "build/Tilemap.o" 
    g++ -c "src/Editor.cpp" -o "build/Editor.o" 

    g++ -o editor build/Tilemap.o build/Editor.o $(LIBS) 

clean: 
    @echo "*** Removing object files and executable..." 

    rm -rf build/* 
    rm -f 2dplatformer 

Je liant les bibliothèques, donc je ne peux pas dire pourquoi il ne peut pas les trouver.

+0

Peut-être 'cmake' ne mettra pas les drapeaux de l'éditeur de bibliothèque à la fin de l'invocation (ils ** doivent ** être à la fin si vous utilisez une chaîne d'outils GNU récente). –

Répondre

0
project (2dplatformer) 
cmake_minimum_required (VERSION 2.8) 

set(CMAKE_MODULE_PATH ${sfmle_SOURCE_DIR}/cmake/modules 
         ${CMAKE_MODULE_PATH}) 

find_package(SFML 2.0 REQUIRED audio graphics network system window) 

include_directories (${SFML_INCLUDE_DIR}) 
link_libraries (${SFML_LIBRARIES}) 

add_library (Tilemap.o src/Tilemap.cpp) 
add_library (State.o src/State.cpp) 
add_library (TitleState.o src/TitleState.cpp) 
add_library (PlayState.o src/PlayState.cpp) 
add_library (Player.o src/Player.cpp) 

link_libraries (Player.o PlayState.o Tilemap.o State.o TitleState.o) 

add_executable (2dplatformer src/Game.cpp) 
target_link_libraries (2dplatformer Player.o PlayState.o Tilemap.o State.o TitleState.o) 

J'ai ajouté un link_libraries() et il l'a corrigé.

Questions connexes