对TTF_INIT的未定义引用
Undefined reference to TTF_Init
我使用sdl2 lib制作一个简单的游戏。成功测试了SDL窗口和键盘处理。问题是我无法使用TTF将一些文本放在窗口中,找不到TTF_Init
(对TTF_Init()
的未定义引用(
cmake文件:
cmake_minimum_required(VERSION 3.6)
project(untitled17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lmingw32")
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
include_directories(${PROJECT_SOURCE_DIR}/include)
link_directories(${PROJECT_SOURCE_DIR}/lib)
set(SOURCE_FILES main.cpp)
add_executable(untitled17 ${SOURCE_FILES})
target_link_libraries(untitled17 mingw32 SDL2main SDL2)
main.cpp
#include "include/SDL2/SDL.h"
#include "include/SDL2/SDL_ttf.h"
using namespace std;
int main(int argc, char* argv []) {
SDL_Init(SDL_INIT_EVERYTHING);
TTF_Init();
TTF_Quit();
return 0;
}
clion构建输出:
[ 50%] Building CXX object CMakeFiles/untitled17.dir/main.cpp.obj
[100%] Linking CXX executable untitled17.exe
CMakeFilesuntitled17.dir/objects.a(main.cpp.obj): In function `SDL_main':
C:/Users/1/ClionProjects/untitled17/main.cpp:14: undefined reference to `TTF_Init'
C:/Users/1/ClionProjects/untitled17/main.cpp:15: undefined reference to `TTF_Quit'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [untitled17.exe] Error 1
CMakeFilesuntitled17.dirbuild.make:96: recipe for target 'untitled17.exe' failed
mingw32-make.exe[2]: *** [CMakeFiles/untitled17.dir/all] Error 2
CMakeFilesMakefile2:66: recipe for target 'CMakeFiles/untitled17.dir/all' failed
CMakeFilesMakefile2:78: recipe for target 'CMakeFiles/untitled17.dir/rule' failed
mingw32-make.exe[1]: *** [CMakeFiles/untitled17.dir/rule] Error 2
Makefile:117: recipe for target 'untitled17' failed
mingw32-make.exe: *** [untitled17] Error 2
您需要针对SDL_TTF库链接。(需要添加到target_link_libraries(
target_link_libraries(untitled17 mingw32 SDL2main SDL2 SDL_ttf)
相关文章:
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- 使用mysql c++连接器的未定义引用
- 对 Scalar ::Scalar() 的未定义引用
- 对复制 CTOR 和 CTOR 的未定义引用
- 对显式实例化的模板函数的未定义引用
- TensorRT (C++ API) 对"createNvOnnxParser_INTERNAL"的未定义引用
- 2个模板化类的非模板友元函数未定义引用错误
- 编译 libfluid 样本控制器时对"event_base_del_virtual"的未定义引用
- 获取对function_name的未定义引用
- 对 'std::thread::_M_start_thread CMake 的未定义引用进行基准测试
- 对结构方法的未定义引用
- 使用内联函数 c++ 的未定义引用
- 对 CMake 中'cudaRegisterLinkedBinary'链接错误的未定义引用?
- 对 DLOPEN 的未定义引用
- QT C++中对全局变量的未定义引用
- 快速数学导致对"__pow_finite"的未定义引用
- 对 boost::system::d etail::system_category_instance 的未定义引用,从
- OpenCV 3.4.3 中对 'cv::String::d eallocate()' 错误的未定义引用