【发布时间】:2020-05-18 08:44:02
【问题描述】:
我正在尝试在 ubuntu 上使用 sdl。根据这个指令(https://gist.github.com/BoredBored/3187339a99f7786c25075d4d9c80fad5),我安装了 sdl2、sdl image 和 sdl 混合器。现在我必须在构建时链接它们。下面举例说明我应该怎么做。
g++ myProgram.cpp -o myProgram `sdl2-config --cflags --libs` -lSDL2 -lSDL2_mixer -lSDL2_image -lSDL2_ttf
我正在使用 Cmake,但我不知道如何链接它们...
下面的代码仅用于测试 sdl 是否工作。
//MAIN
#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_mixer.h>
#include <SDL2/SDL_ttf.h>
int main(int argc, char*args[])
{
SDL_Init(SDL_INIT_EVERYTHING);
}
下面的CMakeList
# Set the minimum version of CMake that can be used
# To find the cmake version run
# $ cmake --version
cmake_minimum_required(VERSION 3.5)
# Set the project name
project (sdl)
# Create a sources variable with a link to all cpp files to compile
set(SOURCES
src/main.cpp
)
# Add an executable with the above sources
add_executable(${PROJECT_NAME} ${SOURCES})
# Set the directories that should be included in the build command for this target
# when running g++ these will be included as -I/directory/path/
target_include_directories(sdl
PRIVATE
${PROJECT_SOURCE_DIR}/inc
)
如何在 Cmake 中链接它们?感谢您的宝贵时间。
【问题讨论】: