c++ - 如何使用 Eclipse ubuntu 设置 SDL2

标签 c++ linux eclipse ubuntu sdl

我一直在尝试让 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

GCC C++ Linker Libraries

#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;
}

`

最佳答案

  1. 这将安装构建使用 SDL 的程序所需的一切:sudo apt-get install libsdl2-dev
  2. 创建一个新的 Eclipse 项目。
  3. 转到项目属性
  4. C/C++ 构建
  5. 设置
  6. GCC C++ 链接器 -> 库
  7. 点击添加...并输入SDL2
  8. 应用项目并重新索引

我用了this文档。使用 SDL CreateWindow 进行测试.

关于c++ - 如何使用 Eclipse ubuntu 设置 SDL2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47211510/

相关文章:

linux - 从 osx 守护进程运行 selenium bash 脚本

linux - 如何将 .Net 核心 docker 应用程序从 Windows 发布到 Linux 机器?

android - 逐帧动画

c++ - 通过父类(super class)的引用访问派生类

linux - 如何让 cURL 不显示进度条?

c++ - 处理 0.0 和 -0.0,如何正确比较值

android - 无法使用 Android-NDK 编译外部预编译共享库

android - AVD 管理器将不再在 Eclipse 中启动

c++ - 使用指针跨越 INTEGER 数组中的所有元素

c++ - 读取RAW音频文件