我一直在尝试让 SDL2 在 Ubuntu 上与 Eclipse 一起工作。
我尝试过关注 this , this ,和this但我就是无法让它工作。
如何让 SDL2 与 Eclipse 一起工作并将所有内容正确链接在一起?
编辑: 当我编译程序时,它返回说 SDL.h 丢失或没有这样的目录,即使我可以在项目列表的包含中看到 SDL。
编译时我尝试使用:
gcc SDLTest.cpp
g++ SDLTest.cpp
gcc -o test SDLTest.cpp `sdl-config --cflags --libs`
我不确定使用 GCC 或 G++ 之间的区别,并且我从 here. 进行了第三次编译。
我已将 SDL include 文件夹添加到项目中,但仍然没有任何内容
Image Project Explorer and Code
#include <SDL2/SDL.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
SDL_Window *window;
SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow(
"an SDL2 Window",
20,
20,
640,
480,
SDL_WINDOW_OPENGL);
if (window == NULL)
{
printf("Could not create window: %s\n", SDL_GetError());
return 1;
}
SDL_Delay(3000);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
`
最佳答案
- 这将安装构建使用 SDL 的程序所需的一切:
sudo apt-get install libsdl2-dev
- 创建一个新的 Eclipse 项目。
- 转到项目属性
- C/C++ 构建
- 设置
- GCC C++ 链接器 -> 库
- 点击
添加...
并输入SDL2
- 应用项目并重新索引
我用了this文档。使用 SDL CreateWindow 进行测试.
关于c++ - 如何使用 Eclipse ubuntu 设置 SDL2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47211510/