gpt4 book ai didi

c++ - 无法使用 Dev-C++ 编译简单的 SDL 程序

转载 作者:行者123 更新时间:2023-12-02 10:03:59 25 4
gpt4 key购买 nike

就在你阅读之前知道我不是英语,所以希望我不会在这里拼错我的写作。
反正。我试图编译我的第一个 SDL 程序,所以我按照在线教程安装 SDL2 库。我使用的代码(从 here 分钟 13:00 复制)是这样的:

#include <iostream>
#include <SDL2/SDL.h>
using namespace std;

int main(void){

if(SDL_Init(SDL_INIT_VIDEO) < 0) {
cout << "SDL init failed.\n";
return 1;
}

cout << "SDL init succeeded";
SDL_Quit();


return 0;
}

我得到的错误是这个
C:\Users\raffaele.ciotola\Desktop\Marco & Lory\Lorenzo\Dev-Cpp\SDL2-2.0.12\x86_64-w64-mingw32\lib\libSDL2main.a(SDL_windows_main.o) In function `main_getcmdline':
71 s:\rs\valve\release\SDL\SDL2-2.0.12-source\src\main\windows\SDL_windows_main.c undefined reference to `SDL_main'
C:\Users\raffaele.ciotola\Desktop\Marco & Lory\Lorenzo\Dev-Cpp\Programs\SDL_\collect2.exe [Error] ld returned 1 exit status
25 C:\Users\raffaele.ciotola\Desktop\Marco & Lory\Lorenzo\Dev-Cpp\Programs\SDL_\Makefile.win recipe for target 'SDL_.exe' failed

我尝试以管理员身份运行我的 Dev-Cpp.exe,因为安装文件夹在桌面上,但这并没有解决问题。

Makefile(不管它是什么,我没有最小的想法)就是这个。如果需要¯_(ツ)_/¯。
# Project: Progetto3
# Makefile created by Dev-C++ 5.11

CPP = g++.exe
CC = gcc.exe
WINDRES = windres.exe
OBJ = SDL_.o
LINKOBJ = SDL_.o
LIBS = -L"C:/Users/raffaele.ciotola/Desktop/Marco & Lory/Lorenzo/Dev-Cpp/MinGW64/lib" -L"C:/Users/raffaele.ciotola/Desktop/Marco & Lory/Lorenzo/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib" -L"C:/Users/raffaele.ciotola/Desktop/Marco & Lory/Lorenzo/Dev-Cpp/SDL2-2.0.12/x86_64-w64-mingw32/lib" -static-libgcc -mwindows -lmingw32 -lSDL2main -lSDL2 -lopengl32 -lglu32
INCS = -I"C:/Users/raffaele.ciotola/Desktop/Marco & Lory/Lorenzo/Dev-Cpp/MinGW64/include" -I"C:/Users/raffaele.ciotola/Desktop/Marco & Lory/Lorenzo/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Users/raffaele.ciotola/Desktop/Marco & Lory/Lorenzo/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include"
CXXINCS = -I"C:/Users/raffaele.ciotola/Desktop/Marco & Lory/Lorenzo/Dev-Cpp/MinGW64/include" -I"C:/Users/raffaele.ciotola/Desktop/Marco & Lory/Lorenzo/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Users/raffaele.ciotola/Desktop/Marco & Lory/Lorenzo/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -I"C:/Users/raffaele.ciotola/Desktop/Marco & Lory/Lorenzo/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++" -I"C:/Users/raffaele.ciotola/Desktop/Marco & Lory/Lorenzo/Dev-Cpp/SDL2-2.0.12/x86_64-w64-mingw32/include"
BIN = SDL_.exe
CXXFLAGS = $(CXXINCS)
CFLAGS = $(INCS)
RM = rm.exe -f

.PHONY: all all-before all-after clean clean-custom

all: all-before $(BIN) all-after

clean: clean-custom
${RM} $(OBJ) $(BIN)

$(BIN): $(OBJ)
$(CPP) $(LINKOBJ) -o $(BIN) $(LIBS)

SDL_.o: SDL_.cpp
$(CPP) -c SDL_.cpp -o SDL_.o $(CXXFLAGS)

如果您需要任何其他信息,请询问。谢谢你。

最佳答案

SDL 劫持 main具有自己的功能,以便进行一些初始设置。然后它将您编写的任何内容称为 main功能。因为它正在调用您的main它期望它以特定方式定义的函数。

试试这个,它应该可以解决您遇到的错误:

int main(int argc, char* args[])
{
// whatever
return 0;
}

关于c++ - 无法使用 Dev-C++ 编译简单的 SDL 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61164916/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com