手动编辑 CMakeLists.txt,在末尾添加以下行,并为您的系统提供正确的路径和正确的 ProjectName。此配置适用于 Ubuntu 17.04 工作站。
include_directories("/usr/include/SDL2")
target_link_libraries(ProjectName "/usr/lib/x86_64-linux-gnu/libSDL.so")
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助。
您可以使用以下方法对其进行测试:
#include <iostream>
#include <SDL.h>
using namespace std;
int main() {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
cout << "SDL Init failed" << endl;
return 1;
}
cout << "SDL Init succeeded" << endl;
SDL_Quit();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在CMakeLists.txt,添加外部库信息。首先,您可以为外部库定义一个逻辑名称,例如我们想要链接一个共享库,该库已在系统上某处安装了.so文件,
add_library(myLogicalExtLib SHARED IMPORTED)
IMPORTED表示该库已经存在,我们不需要在此项目中构建它。
然后,我们可以提供关于这个逻辑库的位置信息,如下所示,
set_target_properties(myLogicalExtLib PROPERTIES IMPORTED_LOCATION "/usr/lib/x86_64-linux-gnu/my_logical_ext_lib.so")