Я пытаюсь скомпилировать простую программу для тестирования SDL2, но по какой-то причине, когда я пытаюсь это сделать, компилятор говорит о том, что SDL_Window является типом unkown. . Я был бы признателен, если кто-то может сказать мне, что я делаю неправильно (Моя операционная система Ubuntu Linux) Вот полный выход:Проблемы с компиляцией с SDL2 в C
thin.c: In function ‘main’:
thin.c:9:5: error: unknown type name ‘SDL_Window’
SDL_Window *window; // Declare a pointer
^
thin.c:14:5: warning: implicit declaration of function ‘SDL_CreateWindow’ [-Wimplicit-function-declaration]
window = SDL_CreateWindow(
^
thin.c:16:9: error: ‘SDL_WINDOWPOS_UNDEFINED’ undeclared (first use in this function)
SDL_WINDOWPOS_UNDEFINED, // initial x position
^
thin.c:16:9: note: each undeclared identifier is reported only once for each function it appears in
thin.c:20:9: error: ‘SDL_WINDOW_OPENGL’ undeclared (first use in this function)
SDL_WINDOW_OPENGL // flags - see below
^
thin.c:35:5: warning: implicit declaration of function ‘SDL_DestroyWindow’ [-Wimplicit-function-declaration]
SDL_DestroyWindow(window);
Здесь также исходный код. Его из документации API:
// Example program:
// Using SDL2 to create an application window
#include "SDL/SDL.h"
#include <stdio.h>
int main(int argc, char* argv[]) {
SDL_Window *window; // Declare a pointer
SDL_Init(SDL_INIT_VIDEO); // Initialize SDL2
// Create an application window with the following settings:
window = SDL_CreateWindow(
"An SDL2 window", // window title
SDL_WINDOWPOS_UNDEFINED, // initial x position
SDL_WINDOWPOS_UNDEFINED, // initial y position
640, // width, in pixels
480, // height, in pixels
SDL_WINDOW_OPENGL // flags - see below
);
// Check that the window was successfully created
if (window == NULL) {
// In the case that the window could not be made...
printf("Could not create window: %s\n", SDL_GetError());
return 1;
}
// The window is open: could enter program loop here (see SDL_PollEvent())
SDL_Delay(3000); // Pause execution for 3000 milliseconds, for example
// Close and destroy the window
SDL_DestroyWindow(window);
// Clean up
SDL_Quit();
return 0;
}
наконец вот команда я издал для компиляции кода:
gcc thin.c -o test -Wall -lSDL2
Спасибо
На совершенно несвязанной ноте не пишите комментарии к очевидным вещам. «Объявить указатель»? Да, мы действительно можем видеть это. Вместо этого сохраните комментарии для вещей, которые * не * очевидны или для того, чтобы говорить * почему * вы что-то делаете, а не что-то еще. –
Что касается вашей проблемы, вы получаете сообщение об ошибке, не находящее заголовочный файл 'SDL/SDL.h'? –
Кажется, что нет проблем с поиском фактического файла заголовка. – user2255893