了解制作错误消息

时间:2017-03-07 05:22:46

标签: c++ makefile cmake sfml

因此,我将SqAtx的GitHub存储库SuperMarioWorld克隆到我的Ubuntu 16.04(64位)计算机上。我想运行他的超级马里奥克隆,以了解他的项目,并通过他做这个游戏的方式学习。

首先,我无法编译它,因为他在README.md中解释了它。但是,我已经成功地以相同的方式编译了自己的Battleship游戏(它告诉我Cmake,make,SFML和C编译器已正确安装)。作为错误,我从构建文件夹运行cmake ..后收到此错误消息:

CMake Error at CMakeLists.txt:24 (add_executable):
 add_executable called with incorrect number of arguments


 -- Found SFML 2.4.0 in /usr/include
 CMake Error at CMakeLists.txt:32 (target_link_libraries):
 Cannot specify link libraries for target "SuperMarioWorld" which is not
 built by this project.


 -- Configuring incomplete, errors occurred!

然后我修改了他的CMakeList.txt,以便它成功创建一个makefile。我的CMakeList.txt如下所示:

#Change this if you need to target a specific CMake version
cmake_minimum_required (VERSION 2.6)  

# Enable debug symbols by default
# must be done before project() statement
if(NOT CMAKE_BUILD_TYPE)  
  set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build (Debug or Release)" FORCE)  
endif()  

project (SuperMarioWorld)  

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -Wall -g")  

# I guess you have not released the project yet :p
set (SuperMarioWorld_VERSION_MAJOR 0)  
set (SuperMarioWorld_VERSION_MINOR 1)  
set (SuperMarioWorld_VERSION_PATCH 0)  

include_directories("${PROJECT_BINARY_DIR}")  
set(SOURCE_FILES  
    EventEngine/Listeners/CharacterDiedListener.cpp  
    EventEngine/Listeners/CharacterPositionUpdateListener.cpp  
    EventEngine/Listeners/CloseRequestListener.cpp  
    EventEngine/Listeners/DebugInfoUpdatedListener.cpp  
    EventEngine/Listeners/ForegroundItemRemovedListener.cpp  
    EventEngine/Listeners/ForegroundItemUpdatedListener.cpp  
    EventEngine/Listeners/GotLevelInfoListener.cpp  
    EventEngine/Listeners/KeyboardListener.cpp  
    EventEngine/Listeners/LevelStartListener.cpp  
    EventEngine/Listeners/MarioJumpListener.cpp  
    EventEngine/Listeners/MarioKickedEnemyListener.cpp  
    EventEngine/Listeners/NewCharacterReadListener.cpp  
    EventEngine/Listeners/NewForegroundItemReadListener.cpp  
    EventEngine/Listeners/NewPipeReadListener.cpp  
    EventEngine/Listeners/ToggleIgnoreInputListener.cpp  
    EventEngine/EventEngine.cpp  
    Game/CollisionHandler.cpp  
    Game/GameEngine.cpp  
    Game/LevelImporter.cpp  
    Graphics/GraphicsEngine.cpp  
    Graphics/SpriteHandler.cpp  
    Sound/SoundEngine.cpp  
    SuperMario/Game.cpp  
    SuperMario/main.cpp  
    System/Characters/Enemy.cpp  
    System/Characters/Goomba.cpp  
    System/Characters/MovingObject.cpp  
    System/Characters/Player.cpp  
    System/Items/Box.cpp  
    System/Items/Pipe.cpp  
    System/irrXML/irrXML.cpp  
    System/Engine.cpp  
    System/Util.cpp  
)  
# Define sources and executable
set (EXECUTABLE_NAME "SuperMarioWorld")  
add_executable(${EXECUTABLE_NAME} ${SOURCE_FILES})  

# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/lib" ${CMAKE_MODULE_PATH})  
#Find any version 2.X of SFML
#See the FindSFML.cmake file for additional details and instructions
find_package(SFML 2 REQUIRED system window graphics network audio)  
if(SFML_FOUND)  
  include_directories(${SFML_INCLUDE_DIR})  
  target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})  
endif()  

# Install target
install(TARGETS ${EXECUTABLE_NAME} DESTINATION bin)

使用此CMakeList.txt,我可以成功创建一个makefile。运行make我首先得到两个错误,其中相同:

/home/lex/Documents/cs/games/SuperMarioWorld/EventEngine/Listeners/NewForegroundItemReadListener.cpp:21:95: error: taking address of temporary [-fpermissive]
m_graphicsEngine->UpdateForegroundItem(&(_event->GetDisplayableObject()->GetInfoForDisplay()));

所以我必须在第24行的NewPipeReadListener.cpp和第24行的NewForegroundItemReadListener.cpp中修复它。我修复了它:

InfoForDisplay temp = _event->GetPipe()->GetInfoForDisplay();
m_graphicsEngine->UpdateForegroundItem(&temp);

现在,makefile给了我一个我无法解决的错误,因为我不懂一个单词..我想在这里包含整个错误消息,但Stackoverflow不允许我这样做... <登记/> 但它就是这样开始的。

[  2%] Linking CXX executable SuperMarioWorld
CMakeFiles/SuperMarioWorld.dir/EventEngine/Listeners/KeyboardListener.cpp.o: In function `KeyboardListener::onEvent(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Event*)':
/home/lex/Documents/cs/games/SuperMarioWorld/EventEngine/Listeners/KeyboardListener.cpp:12: undefined reference to `KeyboardEvent::GetType()'
/home/lex/Documents/cs/games/SuperMarioWorld/EventEngine/Listeners/KeyboardListener.cpp:13: undefined reference to `KeyboardEvent::GetKey()'
/home/lex/Documents/cs/games/SuperMarioWorld/EventEngine/Listeners/KeyboardListener.cpp:14: undefined reference to `KeyboardEvent::GetType()'
/home/lex/Documents/cs/games/SuperMarioWorld/EventEngine/Listeners/KeyboardListener.cpp:15: undefined reference to `KeyboardEvent::GetKey()'
CMakeFiles/SuperMarioWorld.dir/Game/CollisionHandler.cpp.o: In function `CollisionHandler::HandleCollisionsWithMapEdges(MovingObject&)':
/home/lex/Documents/cs/games/SuperMarioWorld/Game/CollisionHandler.cpp:25: undefined reference to `DisplayableObject::GetCoordinates() const'
CMakeFiles/SuperMarioWorld.dir/Game/CollisionHandler.cpp.o: In function `CollisionHandler::DetectCollisionWithObj(MovingObject&, DisplayableObject&)':

如果有人能帮我理解这个错误并且可能让我的系统运行项目,我将不胜感激。

编辑: 修复包含EventEngine/KeyboardEvent.cpp的第一个错误后,它会链接到100%,并吐出以下错误消息:

[100%] Linking CXX executable SuperMarioWorld
CMakeFiles/SuperMarioWorld.dir/Game/CollisionHandler.cpp.o: In function `CollisionHandler::HandleCollisionsWithMapEdges(MovingObject&)':
/home/lex/Documents/cs/games/SuperMarioWorld/Game/CollisionHandler.cpp:25: undefined reference to `DisplayableObject::GetCoordinates() const'
CMakeFiles/SuperMarioWorld.dir/Game/CollisionHandler.cpp.o: In function `CollisionHandler::DetectCollisionWithObj(MovingObject&, DisplayableObject&)':
/home/lex/Documents/cs/games/SuperMarioWorld/Game/CollisionHandler.cpp:40: undefined reference to `DisplayableObject::GetCoordinates() const'
/home/lex/Documents/cs/games/SuperMarioWorld/Game/CollisionHandler.cpp:40: undefined reference to `DisplayableObject::GetCoordinates() const'
CMakeFiles/SuperMarioWorld.dir/Game/CollisionHandler.cpp.o: In function `CollisionHandler::ReactToCollisionsWithObj(MovingObject&, DisplayableObject&, CollisionDirection)':
/home/lex/Documents/cs/games/SuperMarioWorld/Game/CollisionHandler.cpp:45: undefined reference to `DisplayableObject::GetCoordinates() const'
CMakeFiles/SuperMarioWorld.dir/Game/CollisionHandler.cpp.o: In function `CollisionHandler::HandleCollisionWithRect(unsigned int, sf::Rect<float>)':
/home/lex/Documents/cs/games/SuperMarioWorld/Game/CollisionHandler.cpp:73: undefined reference to `DisplayableObject::GetCoordinates() const'
CMakeFiles/SuperMarioWorld.dir/Game/CollisionHandler.cpp.o:/home/lex/Documents/cs/games/SuperMarioWorld/Game/CollisionHandler.cpp:138: more undefined references to `DisplayableObject::GetCoordinates() const' follow
CMakeFiles/SuperMarioWorld.dir/Game/GameEngine.cpp.o: In function `GameEngine::UpdateForegroundItem(unsigned int, sf::Rect<float>)':
/home/lex/Documents/cs/games/SuperMarioWorld/Game/GameEngine.cpp:114: undefined reference to `DisplayableObject::SetCoordinates(sf::Rect<float>)'
CMakeFiles/SuperMarioWorld.dir/Game/LevelImporter.cpp.o: In function `LevelImporter::StoreFloor()':
/home/lex/Documents/cs/games/SuperMarioWorld/Game/LevelImporter.cpp:180: undefined reference to `DisplayableObject::DisplayableObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sf::Vector2<float>, State)'
CMakeFiles/SuperMarioWorld.dir/System/Characters/MovingObject.cpp.o: In function `MovingObject::MovingObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sf::Vector2<float>, State)':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Characters/MovingObject.cpp:5: undefined reference to `DisplayableObject::DisplayableObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sf::Vector2<float>, State)'
/home/lex/Documents/cs/games/SuperMarioWorld/System/Characters/MovingObject.cpp:5: undefined reference to `DisplayableObject::~DisplayableObject()'
CMakeFiles/SuperMarioWorld.dir/System/Characters/MovingObject.cpp.o: In function `MovingObject::MovingObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, float, float, State)':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Characters/MovingObject.cpp:10: undefined reference to `DisplayableObject::DisplayableObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, float, float, State)'
/home/lex/Documents/cs/games/SuperMarioWorld/System/Characters/MovingObject.cpp:10: undefined reference to `DisplayableObject::~DisplayableObject()'
CMakeFiles/SuperMarioWorld.dir/System/Characters/MovingObject.cpp.o: In function `MovingObject::~MovingObject()':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Characters/MovingObject.cpp:25: undefined reference to `DisplayableObject::~DisplayableObject()'
CMakeFiles/SuperMarioWorld.dir/System/Characters/MovingObject.cpp.o: In function `MovingObject::GetInfoForDisplay()':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Characters/MovingObject.cpp:32: undefined reference to `DisplayableObject::GetInfoForDisplay()'
CMakeFiles/SuperMarioWorld.dir/System/Characters/MovingObject.cpp.o:(.rodata._ZTI12MovingObject[_ZTI12MovingObject]+0x10): undefined reference to `typeinfo for DisplayableObject'
CMakeFiles/SuperMarioWorld.dir/System/Items/Box.cpp.o: In function `Box::Box(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sf::Vector2<float>, State)':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Box.cpp:3: undefined reference to `DisplayableObject::DisplayableObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sf::Vector2<float>, State)'
CMakeFiles/SuperMarioWorld.dir/System/Items/Box.cpp.o: In function `Box::Box(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, float, float, State)':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Box.cpp:8: undefined reference to `DisplayableObject::DisplayableObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, float, float, State)'
CMakeFiles/SuperMarioWorld.dir/System/Items/Box.cpp.o:(.rodata._ZTV3Box[_ZTV3Box]+0x20): undefined reference to `DisplayableObject::GetInfoForDisplay()'
CMakeFiles/SuperMarioWorld.dir/System/Items/Box.cpp.o: In function `Box::~Box()':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Box.hpp:9: undefined reference to `DisplayableObject::~DisplayableObject()'
CMakeFiles/SuperMarioWorld.dir/System/Items/Box.cpp.o:(.rodata._ZTI3Box[_ZTI3Box]+0x10): undefined reference to `typeinfo for DisplayableObject'
CMakeFiles/SuperMarioWorld.dir/System/Items/Pipe.cpp.o: In function `Pipe::Pipe(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sf::Vector2<float>, int, PipeType, EventEngine*)':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Pipe.cpp:5: undefined reference to `DisplayableObject::DisplayableObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, sf::Vector2<float>, State)'
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Pipe.cpp:5: undefined reference to `DisplayableObject::~DisplayableObject()'
CMakeFiles/SuperMarioWorld.dir/System/Items/Pipe.cpp.o: In function `Pipe::~Pipe()':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Pipe.cpp:14: undefined reference to `DisplayableObject::~DisplayableObject()'
CMakeFiles/SuperMarioWorld.dir/System/Items/Pipe.cpp.o: In function `Pipe::SpawnEnemyIfTimeElapsed()':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Pipe.cpp:50: undefined reference to `DisplayableObject::DisplayableObject(EventEngine*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, float, float, State)'
CMakeFiles/SuperMarioWorld.dir/System/Items/Pipe.cpp.o: In function `Pipe::MoveEnemyBeingSpawned(float)':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Pipe.cpp:58: undefined reference to `DisplayableObject::Slide(float, float)'
CMakeFiles/SuperMarioWorld.dir/System/Items/Pipe.cpp.o: In function `Pipe::IsEnemyReadyToLeavePipe()':
/home/lex/Documents/cs/games/SuperMarioWorld/System/Items/Pipe.cpp:92: undefined reference to `DisplayableObject::GetCoordinates() const'
CMakeFiles/SuperMarioWorld.dir/System/Items/Pipe.cpp.o:(.rodata._ZTV4Pipe[_ZTV4Pipe]+0x20): undefined reference to `DisplayableObject::GetInfoForDisplay()'
CMakeFiles/SuperMarioWorld.dir/System/Items/Pipe.cpp.o:(.rodata._ZTV4Pipe[_ZTV4Pipe]+0x28): undefined reference to `DisplayableObject::UpdateAfterCollision(CollisionDirection, ObjectClass)'
CMakeFiles/SuperMarioWorld.dir/System/Items/Pipe.cpp.o:(.rodata._ZTI4Pipe[_ZTI4Pipe]+0x10): undefined reference to `typeinfo for DisplayableObject'
collect2: error: ld returned 1 exit status
CMakeFiles/SuperMarioWorld.dir/build.make:957: recipe for target 'SuperMarioWorld' failed
make[2]: *** [SuperMarioWorld] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/SuperMarioWorld.dir/all' failed
make[1]: *** [CMakeFiles/SuperMarioWorld.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

EDIT2: 现在,我感到愚蠢,还有另一个我忘记包含的文件,它是System/DisplayableObject.cpp

谢谢,大家帮忙!!!

1 个答案:

答案 0 :(得分:0)

您没有在构建中包含所有源文件。

例如,在您的错误消息中,链接器抱怨它缺少link函数的定义。

在github上搜索KeyboardEvent::GetType()的repo会很快告诉你这个函数是在KeyboardEvent中定义的,它不是你的CMake EventEngine/KeyboardEvent.cpp的一部分。

您可能也缺少其他源文件。尝试逐个修复链接器错误,直到它编译完毕。