问题描述
在Windows 10的Clion中使用此CMAKE文件(使用MinGW 5.0):
cmake_minimum_required(VERSION 3.3)
project(ClionProjects)
#配置SDL(cf.SDL2-2.0.3\i686-w64-mingw32\lib\pkgconfig\sdl2.pc)
#C ++ flags
set(SDL2_Flags-mwindows -Wl, - no-undefined -static-libgcc)
#库路径
set(SDL2_ROOTC:/ SDL2 / i686-
set(SDL2_Includes$ {SDL2_ROOT} / include)
set(SDL2_LibDir$ {SDL2_ROOT} / lib)
#导入CMake目标(cf. https ://cmake.org/Wiki/CMake/Tutorials/Exporting_and_Importing_Targets)
add_library(SDL2 STATIC IMPORTED)
add_library(SDL2main STATIC IMPORTED)
add_library(SDL2_image STATIC IMPORTED)
add_library (SDL2_ttf STATIC IMPORTED)
set_property(TARGET SDL2 PROPERTY IMPORTED_LOCATION$ {SDL2_LibDir} /libSDL2.a)
set_property(TARGET SDL2main PROPERTY IMPORTED_LOCATION$ {SDL2_LibDir} /libSDL2main.a)
set_property(TARGET SDL2_image PROPERTY IMPORTED_LOCATION$ {SDL2_LibDir} /libSDL2_image.a)
set_property(TARGET SDL2_ttf PROPERTY IMPORTED_LOCATION$ {SDL2_LibDir} /libSDL2_ttf.a)
# b $ b#注意:和gcc一样,顺序很重要...
set(SDL2_Libs mingw32 SDL2 SDL2main m SDL2_image SDL2_ttf dinput8 dxguid dxerr8 user32 gdi32 winmm imm32 ole32 oleaut32 shell32 version uuid)
#配置项目
#包含SDL标志
设置(CMAKE_CXX_FLAGS$ {CMAKE_CXX_FLAGS} -std = c ++ 11 $ {SDL2_Flags})
#收集源
set(SOURCE_FILES
Kod / Graphics / Graphics.cc
Kod / Graphics / Graphics.h
Kod / Game / Game.cc
Kod / Game / Game.h
Kod / Gameboard / Gameboard.cc
Kod / Gameboard / Gameboard.h
Kod / Meeple / Meeple.cc
Kod / Meeple / Meeple.h
Kod / Player /Player.cc
Kod / Player / Player.h
Kod / Resource / Resource.cc
Kod / Resource / Resource.h
Kod / Tile / Tile.cc
Kod / Tile / Tile.h
Kod / Carcassonne.cc)
#定义目标
add_executable(ClionProjects $ {SOURCE_FILES} Kod / Carcassonne.cc)
#include SDL头
target_include_directories(ClionProjects SYSTEM PRIVATE $ {SDL2_Includes})
#链接SDL(及其依赖项)
target_link_libraries(ClionProjects $ {SDL2_Libs})
#set(CMAKE_CXX_FLAGS$ {CMAKE_CXX_FLAGS} -std = c ++ 11 -lSDL2 -lSDL2-image)
#add_executable(ClionProjects $ {SOURCE_FILES} Kod /Carcassonne.cc)
#target_link_libraries(ClionProjects SDL2main SDL2 SDL2_image)
:
C:/SDL2/i686-w64-mingw32/lib/libSDL2_ttf.a(SDL_ttf.o) Load_Glyph':
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:609:未定义引用`FT_Load_Glyph'
/ Users / slouken / release / SDL_ttf / SDL2_ttf-2.0.12-source / foo-x86 /../ SDL_ttf.c:671:未定义的引用`FT_Outline_Transform'
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0。 12-source / foo-x86 /../ SDL_ttf.c:677:未定义的引用`FT_Get_Glyph'
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/ .. /SDL_ttf.c:678:未定义引用`FT_Stroker_New'
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:694:未定义的引用`FT_Render_Glyph'
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:895:未定义的引用`FT_Done_Glyph'
/ Users / slouken / release / SDL_ttf / SDL2_ttf-2.0.12-source / foo-x86 /../ SDL_ttf.c:607:未定义的引用`FT_Get_Char_Index'
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0。 12-source / foo-x86 /../ SDL_ttf.c:682:未定义的引用`FT_Stroker_Set'
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/ .. /SDL_ttf.c:683:未定义引用`FT_Glyph_Stroke'
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:684:未定义的引用`FT_Stroker_Done'
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:686:未定义的引用`FT_Glyph_To_Bitmap'
/ Users / slouken / release / SDL_ttf / SDL2_ttf-2.0.12-source / foo-x86 /../ SDL_ttf.c:688:未定义引用`FT_Done_Glyph'
C:/ SDL2 / i686-w64-mingw32 / lib / libSDL2_ttf.a(SDL_ttf.o):在函数`TTF_Init'中:
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:340:undefined引用'FT_Init_FreeType'
C:/SDL2/i686-w64-mingw32/lib/libSDL2_ttf.a(SDL_ttf.o):在函数`TTF_CloseFont'中:
/ Users / slouken / release / SDL_ttf / SDL2_ttf-2.0.12-source / foo-x86 /../ SDL_ttf.c:927:未定义引用`FT_Done_Face'
C:/SDL2/i686-w64-mingw32/lib/libSDL2_ttf.a(SDL_ttf。 o):在函数`TTF_OpenFontIndexRW'中:
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:432:undefined reference to`FT_Open_Face'
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:460:未定义的引用`FT_Set_Char_Size'
/ Users / slouken / release / SDL_ttf / SDL2_ttf-2.0.12-source / foo-x86 /../ SDL_ttf.c:454:未定义的引用`FT_Set_Charmap'
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/ foo-x86 /../ SDL_ttf.c:484:未定义的引用`FT_Set_Pixel_Sizes'
C:/SDL2/i686-w64-mingw32/lib/libSDL2_ttf.a(SDL_ttf.o):在函数`TTF_SizeUTF8' :
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:1241:未定义的引用`FT_Get_Kerning'
C:/ SDL2 / i686-w64-mingw32 / lib / libSDL2_ttf.a(SDL_ttf.o):在函数`TTF_RenderUTF8_Solid'中:
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/ .. /SDL_ttf.c:1429:未定义的引用`FT_Get_Kerning'
C:/SDL2/i686-w64-mingw32/lib/libSDL2_ttf.a(SDL_ttf.o):在函数`TTF_RenderUTF8_Shaded'中:
/用户/ slouken / release / SDL_ttf / SDL2_ttf-2.0.12-source / foo-x86 /../ SDL_ttf.c:1610:未定义引用`FT_Get_Kerning'
C:/ SDL2 / i686-w64-mingw32 / lib / libSDL2_ttf.a(SDL_ttf.o):在函数`TTF_RenderUTF8_Blended':
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:1780 :未定义的引用`FT_Get_Kerning'
C:/SDL2/i686-w64-mingw32/lib/libSDL2_ttf.a(SDL_ttf.o):在函数`TTF_RenderUTF8_Blended_Wrapped'中:
/ Users / slouken / release / SDL_ttf / SDL2_ttf-2.0.12-source / foo-x86 /../ SDL_ttf.c:2048:未定义的引用`FT_Get_Kerning'
C:/SDL2/i686-w64-mingw32/lib/libSDL2_ttf.a SDL_ttf.o):在函数`TTF_Quit'中:
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:2196:未定义对`FT_Done_FreeType的引用'
C:/SDL2/i686-w64-mingw32/lib/libSDL2_ttf.a(SDL_ttf.o):在函数`TTF_GetFontKerningSize'中:
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0。 12-source / foo-x86 /../ SDL_ttf.c:2209:未定义的引用`FT_Get_Kerning'
C:/SDL2/i686-w64-mingw32/lib/libSDL2_ttf.a(SDL_ttf.o):In函数`TTF_GlyphIsProvided':
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:1138:未定义的引用`FT_Get_Char_Index'
collect2 .exe:错误:ld返回1退出状态
CMakeFiles\ClionProjects.dir\build.make:289:目标'ClionProjects.exe'的食谱失败
mingw32-make.exe [3]: *** [ClionProjects.exe]错误1
mingw32-make.exe [2]:*** [CMakeFiles / ClionProjects.dir / all]错误2
CMakeFiles\Makefile2:66:recipe for目标'CMakeFiles / ClionProjects.dir / all'失败
CMakeFiles\Makefile2:78:配方目标'CMakeFiles / ClionProjects.dir /规则'失败
mingw32-make.exe [1]:** * [CMakeFiles / ClionProjects.dir / rule]错误2
mingw32-make.exe:*** [ClionProjects]错误2
makefile:117:目标'ClionProjects'失败的食谱
我已经将SDL2_ttf.dll添加到system32和可执行文件所在的文件夹,将SDL2_ttf.h添加到/ include其中all SDL2的其他.h文件是并且也将libSDL2_ttf.a添加到/ lib。我不明白为什么我会得到这些错误...我的标志的顺序有问题?
下面是我如何使用SDL2,SDL2_ttf,SDL2_mixer等与CLION。这是非常不同于你迄今为止做的方法,所以请记住这一点。我将使用MSYS2作为类POSIX环境(而不是您正在使用的MINGW / MSYS)。
首先,我将开始安装MSYS2。从
那么一切都应该准备好了。
我将使用 FindPkgConfig
模块来获取我使用的每个库的链接器标记和包含标记。这个模块回复我们以前安装的pkg-config命令。在 CMakeList.txt
中,添加以下行:
INCLUDE(FindPkgConfig )
pkg_check_modules(SDL2必填SDL2)
pkg_check_modules(SDL2_IMG必填SDL2_image)
pkg_check_modules(SDL2_TTF必填SDL2_ttf)
pkg_check_modules(SDL2_MIX必填SDL2_mixer)
include_directories($ {SDL2_INCLUDE_DIRS}
$ {SDL2_IMG_INCLUDE_DIRS}
$ {SDL2_TTF_INCLUDE_DIRS}
$ {SDL2_MIX_INCLUDE_DIRS})
link_directories($ {SDL2_LIBRARY_DIRS}
$ {SDL2_IMG_LIBRARY_DIRS}
$ {SDL2_TTF_LIBRARY_DIRS}
$ {SDL2_MIX_LIBRARY_DIRS})
target_link_libraries(TestSDL2
$ {SDL2_LIBRARIES}
$ {SDL2_IMG_LIBRARIES}
$ {SDL2_TTF_LIBRARIES}
$ {SDL2_MIX_LIBRARIES})
更改TestSDL2到您的可执行文件。您可能必须删除现有的FindSDL或任何寻找SDL库的命令。
这种方法比自定义模块清洁得多。缺点是它几乎绑定到系统的库文件(特别是如果你使用Linux)。此外,如果你必须打包的exe文件,你将不得不手动查找MSYS2 / mingw64 / bin里面的dll文件(这不是很困难的方式)。
另一种可能的方法是将SDL作为子项目。我以前没有这样做,所以我不能解释。
我想在你熟悉这个工作后,你可以对其他库使用相同的方法(例如box2d)。您可以访问 https://github.com/Alexpux/MINGW-packages查看可用软件包列表a>,包名称必须通过在库名称前添加一个小的名称(例如 mingw-w64-x86_64-box2d
$ c> mingw-w64-box2d 包)。
Using this CMAKE-file in Clion on Windows 10 (using MinGW 5.0):
cmake_minimum_required(VERSION 3.3)
project(ClionProjects)
# configure the SDL (cf. "SDL2-2.0.3\i686-w64-mingw32\lib\pkgconfig\sdl2.pc")
# C++ flags
set(SDL2_Flags "-mwindows -Wl,--no-undefined -static-libgcc")
# library paths
set(SDL2_ROOT "C:/SDL2/i686-w64-mingw32")
set(SDL2_Includes "${SDL2_ROOT}/include")
set(SDL2_LibDir "${SDL2_ROOT}/lib")
# imported targets for CMake (cf. https://cmake.org/Wiki/CMake/Tutorials/Exporting_and_Importing_Targets)
add_library(SDL2 STATIC IMPORTED)
add_library(SDL2main STATIC IMPORTED)
add_library(SDL2_image STATIC IMPORTED)
add_library(SDL2_ttf STATIC IMPORTED)
set_property(TARGET SDL2 PROPERTY IMPORTED_LOCATION "${SDL2_LibDir}/libSDL2.a")
set_property(TARGET SDL2main PROPERTY IMPORTED_LOCATION "${SDL2_LibDir}/libSDL2main.a")
set_property(TARGET SDL2_image PROPERTY IMPORTED_LOCATION "${SDL2_LibDir}/libSDL2_image.a")
set_property(TARGET SDL2_ttf PROPERTY IMPORTED_LOCATION "${SDL2_LibDir}/libSDL2_ttf.a")
# the libs to link against
# note: as always with gcc, the order is important...
set(SDL2_Libs mingw32 SDL2 SDL2main m SDL2_image SDL2_ttf dinput8 dxguid dxerr8 user32 gdi32 winmm imm32 ole32 oleaut32 shell32 version uuid)
# configure the project
# include the SDL flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ${SDL2_Flags}")
# collect the sources
set(SOURCE_FILES
Kod/Graphics/Graphics.cc
Kod/Graphics/Graphics.h
Kod/Game/Game.cc
Kod/Game/Game.h
Kod/Gameboard/Gameboard.cc
Kod/Gameboard/Gameboard.h
Kod/Meeple/Meeple.cc
Kod/Meeple/Meeple.h
Kod/Player/Player.cc
Kod/Player/Player.h
Kod/Resource/Resource.cc
Kod/Resource/Resource.h
Kod/Tile/Tile.cc
Kod/Tile/Tile.h
Kod/Carcassonne.cc)
# define the target
add_executable(ClionProjects ${SOURCE_FILES} Kod/Carcassonne.cc)
# include the SDL headers
target_include_directories(ClionProjects SYSTEM PRIVATE ${SDL2_Includes})
# link against the SDL (and its dependencies)
target_link_libraries(ClionProjects ${SDL2_Libs})
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lSDL2 -lSDL2-image")
#add_executable(ClionProjects ${SOURCE_FILES} Kod/Carcassonne.cc)
#target_link_libraries(ClionProjects SDL2main SDL2 SDL2_image)
I get this error:
C:/SDL2/i686-w64-mingw32/lib/libSDL2_ttf.a(SDL_ttf.o): In function `Load_Glyph':
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:609: undefined reference to `FT_Load_Glyph'
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:671: undefined reference to `FT_Outline_Transform'
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:677: undefined reference to `FT_Get_Glyph'
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:678: undefined reference to `FT_Stroker_New'
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:694: undefined reference to `FT_Render_Glyph'
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:895: undefined reference to `FT_Done_Glyph'
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:607: undefined reference to `FT_Get_Char_Index'
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:682: undefined reference to `FT_Stroker_Set'
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:683: undefined reference to `FT_Glyph_Stroke'
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:684: undefined reference to `FT_Stroker_Done'
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:686: undefined reference to `FT_Glyph_To_Bitmap'
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:688: undefined reference to `FT_Done_Glyph'
C:/SDL2/i686-w64-mingw32/lib/libSDL2_ttf.a(SDL_ttf.o): In function `TTF_Init':
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:340: undefined reference to `FT_Init_FreeType'
C:/SDL2/i686-w64-mingw32/lib/libSDL2_ttf.a(SDL_ttf.o): In function `TTF_CloseFont':
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:927: undefined reference to `FT_Done_Face'
C:/SDL2/i686-w64-mingw32/lib/libSDL2_ttf.a(SDL_ttf.o): In function `TTF_OpenFontIndexRW':
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:432: undefined reference to `FT_Open_Face'
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:460: undefined reference to `FT_Set_Char_Size'
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:454: undefined reference to `FT_Set_Charmap'
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:484: undefined reference to `FT_Set_Pixel_Sizes'
C:/SDL2/i686-w64-mingw32/lib/libSDL2_ttf.a(SDL_ttf.o): In function `TTF_SizeUTF8':
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:1241: undefined reference to `FT_Get_Kerning'
C:/SDL2/i686-w64-mingw32/lib/libSDL2_ttf.a(SDL_ttf.o): In function `TTF_RenderUTF8_Solid':
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:1429: undefined reference to `FT_Get_Kerning'
C:/SDL2/i686-w64-mingw32/lib/libSDL2_ttf.a(SDL_ttf.o): In function `TTF_RenderUTF8_Shaded':
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:1610: undefined reference to `FT_Get_Kerning'
C:/SDL2/i686-w64-mingw32/lib/libSDL2_ttf.a(SDL_ttf.o): In function `TTF_RenderUTF8_Blended':
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:1780: undefined reference to `FT_Get_Kerning'
C:/SDL2/i686-w64-mingw32/lib/libSDL2_ttf.a(SDL_ttf.o): In function `TTF_RenderUTF8_Blended_Wrapped':
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:2048: undefined reference to `FT_Get_Kerning'
C:/SDL2/i686-w64-mingw32/lib/libSDL2_ttf.a(SDL_ttf.o): In function `TTF_Quit':
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:2196: undefined reference to `FT_Done_FreeType'
C:/SDL2/i686-w64-mingw32/lib/libSDL2_ttf.a(SDL_ttf.o): In function `TTF_GetFontKerningSize':
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:2209: undefined reference to `FT_Get_Kerning'
C:/SDL2/i686-w64-mingw32/lib/libSDL2_ttf.a(SDL_ttf.o): In function `TTF_GlyphIsProvided':
/Users/slouken/release/SDL_ttf/SDL2_ttf-2.0.12-source/foo-x86/../SDL_ttf.c:1138: undefined reference to `FT_Get_Char_Index'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\ClionProjects.dir\build.make:289: recipe for target 'ClionProjects.exe' failed
mingw32-make.exe[3]: *** [ClionProjects.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/ClionProjects.dir/all] Error 2
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/ClionProjects.dir/all' failed
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/ClionProjects.dir/rule' failed
mingw32-make.exe[1]: *** [CMakeFiles/ClionProjects.dir/rule] Error 2
mingw32-make.exe: *** [ClionProjects] Error 2
makefile:117: recipe for target 'ClionProjects' failed
I have added SDL2_ttf.dll to system32 and the folder where the executable will be, added SDL2_ttf.h to /include where all the other .h-files for SDL2 is and also added libSDL2_ttf.a to /lib. I don't understand why I would get those errors... I there a problem with the order of my flags?
Below is how I work with SDL2, SDL2_ttf, SDL2_mixer, etc. with CLion. This is quite different approache than what you've been doing so far, so please keep that in mind. I'll be using MSYS2 for the POSIX-like environment (instead of MINGW/MSys you are using).
First of, I would start with installing MSYS2. Grab it from http://msys2.github.io/ . Then, depends on the version you have installed, you will get 2 or 3 shortcuts in the start menu.
From now on I'd stick with MINGW-W64-x86_64
version of the toolchain. If you are using the i686
one, replace x86_64
with i686
(and mingw64
with mingw32
).
Open the MinGW-w64 Win64 shell
shortcut from the start menu. You will be welcome with a bash shell. At this point I'd start with installing the toolchain first. At the prompt, input the below command
pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-pkg-config mingw-w64-x86_64-make mingw-w64-x86_64-gdb
The package manager will then install gcc, cmake, pkg-config, make and gdb for you. This includes all of the dependencies of these tool, so it would take quite a bit.
Then install the libraries by calling below commands at the prompt.:
pacman -S mingw-w64-x86_64-SDL2 mingw-w64-x86_64-SDL2_ttf mingw-w64-x86_64-SDL2_mixer mingw-w64-x86_64-SDL2_image
pacman (package manager) will download and install these 3 libraries, along with their dependencies.
The steps above is on top of my head. I haven't retested it yet (as I already have working environment). If you run into problems let me know. I might retest it later. Also the step above is applicable for the Arch Linux users too, just replace the package name and you'll be good.
Next up, open the CLion. Go to File->Settings. Choose toolchains under Build, Execution, and Deployment. Then change the MinGW home to the mingw64 under your MSYS2 installation path.
Then everything should be ready.
I will use the FindPkgConfig
module to get the linker flags and include flags of each library I use. This module replies on pkg-config command we've installed earlier. In CMakeList.txt
, add the following line :
INCLUDE(FindPkgConfig)
pkg_check_modules(SDL2 REQUIRED sdl2)
pkg_check_modules(SDL2_IMG REQUIRED SDL2_image)
pkg_check_modules(SDL2_TTF REQUIRED SDL2_ttf)
pkg_check_modules(SDL2_MIX REQUIRED SDL2_mixer)
include_directories(${SDL2_INCLUDE_DIRS}
${SDL2_IMG_INCLUDE_DIRS}
${SDL2_TTF_INCLUDE_DIRS}
${SDL2_MIX_INCLUDE_DIRS})
link_directories (${SDL2_LIBRARY_DIRS}
${SDL2_IMG_LIBRARY_DIRS}
${SDL2_TTF_LIBRARY_DIRS}
${SDL2_MIX_LIBRARY_DIRS})
target_link_libraries (TestSDL2
${SDL2_LIBRARIES}
${SDL2_IMG_LIBRARIES}
${SDL2_TTF_LIBRARIES}
${SDL2_MIX_LIBRARIES})
Change the TestSDL2 to your executable. You probably have to remove the existing FindSDL or any commands that looks for SDL libraries.
This approach is much cleaner than the custom module. The downside is it is pretty much tied to the system's libraries file (especially if you are using Linux). Also if you have to package the exe file, you will have to look for the dll files inside the MSYS2/mingw64/bin manually (it's not very difficult by the way).
Another possible approach is to include the SDL as subproject. I haven't done this before so I cannot explain.
I think after you're familliar with how this work, you can applies the same approaches to other libraries as well (box2d, for example). You can see the list of available packages at https://github.com/Alexpux/MINGW-packages , the package names have to be modified a little bit by insterting the arch name just before the library names (eg. mingw-w64-x86_64-box2d
for mingw-w64-box2d
package).
这篇关于“未定义对”FT_Load_Glyph“的引用和其他SDL2_ttf函数使用CMAKE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!