我正在尝试使用SFML和SFGUI构建项目。该项目构建,直到我尝试实例化sfg :: SFGUI。当我尝试时,我收到以下错误:
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_link_script CMakeFiles/tilemap.dir/link.txt --verbose=1
/usr/bin/clang++ -std=c++11 -stdlib=libc++ -g -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/tilemap.dir/src/main.cpp.o CMakeFiles/tilemap.dir/src/Camera.cpp.o CMakeFiles/tilemap.dir/src/Player.cpp.o CMakeFiles/tilemap.dir/src/Tile.cpp.o CMakeFiles/tilemap.dir/src/TileMap.cpp.o -o tilemap /usr/local/lib/libsfml-system.dylib /usr/local/lib/libsfml-window.dylib /usr/local/lib/libsfml-graphics.dylib /usr/local/lib/libsfml-network.dylib /usr/local/lib/libsfml-audio.dylib
Undefined symbols for architecture x86_64:
"sfg::SFGUI::SFGUI()", referenced from:
MyInterface::MyInterface() in main.cpp.o
"sfg::SFGUI::~SFGUI()", referenced from:
MyInterface::~MyInterface() in main.cpp.o
ld: symbol(s) not found for architecture x86_64
这是我的" MyInterface.h":
#include <iostream>
#include <stdlib.h>
#include <SFGUI/SFGUI.hpp>
#include <SFGUI/Widgets.hpp>
#include <SFML/Graphics.hpp>
class MyInterface {
public:
void RunInterface();
void ButtonClick();
private:
sfg::SFGUI mysfgui;
// sfg::Window::Ptr m_window;
// sfg::Button::Ptr m_button;
};
void MyInterface::RunInterface() {
printf("Interface running!\n");
// m_window = sfg::Window::Create();
// auto box = sfg::Box::Create( sfg::Box::Orientation::VERTICAL, 5.f );
// m_button = sfg::Button::Create( "Click me" );
// box->Pack( m_button );
// m_button->GetSignal( sfg::Widget::OnLeftClick ).Connect( std::bind( &MyInterface::ButtonClick, this ) );
}
void MyInterface::ButtonClick() {
// m_button->SetLabel( "I was clicked" );
}
正如您所看到的,除了SFGUI实例化之外,我还评论了所有内容。
以下是我的CMake文件:
cmake_minimum_required(VERSION 3.5)
# Project Specific stuff
set(SOURCE_FILES src/main.cpp src/Camera.cpp src/Player.cpp src/Tile.cpp src/TileMap.cpp src/MyInterface.h)
set(PROJECT_NAME myproject)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
message("Building ${PROJECT_NAME}...")
project(${PROJECT_NAME})
# CMake Options
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")
if (APPLE)
message("Found Apple Machine!")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -stdlib=libc++")
set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
set(CMAKE_C_COMPILER "/usr/bin/clang")
endif (APPLE)
# SFML Stuff
find_package(SFML REQUIRED system window graphics network audio)
if (SFML_FOUND)
message("Found SFML...")
include_directories(${SFML_INCLUDE_DIR} ${SFML_INCLUDE_DIRS}) # Do I need dir and dirs?
target_link_libraries(${PROJECT_NAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
else ()
message(FATAL_ERROR "Could not locate SFML!")
endif (SFML_FOUND)
# SFGUI Stuff
find_package(SFGUI REQUIRED window button widget)
if (SFGUI_FOUND)
message("Found SFGUI...")
include_directories(${SFGUI_INCLUDE_DIR} ${SFGUI_INCLUDE_DIRS}) # Do I need dir and dirs?
target_link_libraries(${PROJECT_NAME} ${SFGUI_LIBRARIES} ${SFGUI_DEPENDENCIES})
else ()
message(FATAL_ERROR "Could not locate SFGUI!")
endif (SFGUI_FOUND)
最后,我使用以下选项编译了SFML:
cmake -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_C_COMPILER="/usr/bin/clang" -DCMAKE_CXX_COMPILER="/usr/bin/clang++" -DCMAKE_OSX_ARCHITECTURES="i386;x86_64"
和SFGUI:
cmake -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_C_COMPILER="/usr/bin/clang" -DCMAKE_CXX_COMPILER="/usr/bin/clang++" -DSFGUI_BUILD_EXAMPLES="false" -DSFGUI_BUILD_DOC="false" -DCMAKE_OSX_ARCHITECTURES="i386;x86_64"
我做错了什么?任何帮助表示赞赏。
答案 0 :(得分:-1)
感谢帮助人员,我想我弄清楚出了什么问题。虽然我不知道为什么这样有效......
我改变了:
target_link_libraries(${PROJECT_NAME} ${SFGUI_LIBRARIES} ${SFGUI_DEPENDENCIES})
为:
target_link_libraries(${PROJECT_NAME} -lsfgui)
我希望这有助于某些人下线。