本文介绍了未定义对SDL_Init的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天开始使用SDL,之前遇到了一些麻烦,现在我可以运行它了,但是它不允许我初始化它。

I started using SDL today and had some trouble before, now I got it running but it won't let me init it.

这是我的代码:

#include <iostream>
#include "SDL.h"
#undef main

using namespace std;

int main(){
    if(SDL_Init(SDL_INIT_EVERYTHING)<0){
        cout << "error starting sdl" << endl;
    }
    return 0;
}

此构建日志:

-------------- Build: Debug in Graphics (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall -g -std=c++11 -IC:\Users\73638G75MA\Documents\SDL2-2.0.3\x86_64-w64-mingw32\include\SDL2 -I"C:\Users\73638G75MA\Documents\C++ projects\Graphics" -c "C:\Users\73638G75MA\Documents\C++ projects\Graphics\main.cpp" -o obj\Debug\main.o
mingw32-g++.exe -LC:\Users\73638G75MA\Documents\SDL2-2.0.3\x86_64-w64-mingw32\lib -o bin\Debug\Graphics.exe obj\Debug\main.o  -lmingw32 -lSDL2main -lSDL2
obj\Debug\main.o: In function `main':
C:/Users/73638G75MA/Documents/C++ projects/Graphics/main.cpp:8: undefined reference to `SDL_Init'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))

我会很感激所有可能的帮助,一开始的#undef主要是因为它不允许我以其他方式运行它。如果不存在,则在创建控制台应用程序时会给我未定义的winmain @ 16引用。

I would apreciate all possible help in this, the #undef main at the start is because it won't let me run it otherwise. If it isn't there it gives me a "undefined reference to winmain@16" While I am creating a console application.

推荐答案

根据包含和库搜索路径 ... \SDL2-2.0.3\x86_64-w64-mingw32\ ... ,您正在尝试使用64位SDL2构建。 根据和我对codeblocks-13.12mingw-setup.exe内容的检查,其中包括仅32位,并且不能创建64位二进制文​​件,也不能使用64位库。

According to the include and library search paths ...\SDL2-2.0.3\x86_64-w64-mingw32\..., you're trying to build with a 64-bit SDL2. According to the Code::Blocks download page and my inspection of the contents of codeblocks-13.12mingw-setup.exe, the included toolchain is 32-bit only and can't create 64-bit binaries nor use 64-bit libraries.

如果要使用预构建的SDL2,则需要下载匹配的工具链(64位mingw-w64)并使用它,或更改构建参数以使用SDL2的32位构建(它在)。

If you want to use a pre-built SDL2, you either need to download the matching toolchain (64-bit mingw-w64) and use that, or change your build parameters to use the 32-bit build of SDL2 (it's present in the development libraries archive in the i686-w64-mingw32 directory).

这篇关于未定义对SDL_Init的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 21:36