SDL2未定义的函数引用
SDL2 Undefined references to functions
我正在尝试建立一个基于MinGW并使用SDL的C++项目。当我试图编译我的程序时,g++对我使用的每个SDL函数都说undefined reference to 'SDL_Function'
。
Lib/SDL2:SDL2-devel-2.0.0-mingw.tar.gz的内容来自SDL的网站
来源/Main.cpp:
#include "SDL.h"
int main(int argc, char *argv[]) {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window *window = SDL_CreateWindow(
"Hello World",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
640, 480, 0
);
SDL_Delay(3000);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
我使用Rake来稍微简化构建过程,它产生的命令是:
g++ -Wall -ILib/SDL2/i686-w64-mingw32/include/SDL2 -Dmain=SDL_main -LLib/SDL2/i686-w64-mingw32/lib -lmingw32 -lSDL2main -lSDL2 -mwindows Source/Main.cpp -o Build/sdltest.exe
下面是g++所说的:
Main.cpp:(.text+0xe): undefined reference to `SDL_Init'`
Main.cpp:(.text+0x42): undefined reference to `SDL_CreateWindow'`
Main.cpp:(.text+0x51): undefined reference to `SDL_Delay'`
Main.cpp:(.text+0x5c): undefined reference to `SDL_DestroyWindow'`
Main.cpp:(.text+0x61): undefined reference to `SDL_Quit'`
ld.exe: bad reloc address 0x20 in section `.eh_frame'`
ld.exe: final link failed: Invalid operation`
collect2.exe: error: ld returned 1 exit status`
这看起来像是一个常见的初学者问题,但我认为我通过了所有的故障排除要点:
- 主功能具有
int argc, char *argv[]
- 我使用sdl-config中的所有标志(-Dmain=sdl_main-lmingh32-lSDL2main-lSDL2-mwindows)
- 当使用32位MinGW时,我正在尝试使用"i686-w64-mingw32"版本
- 所有指定的路径似乎都是正确的
知道发生了什么事吗?
尝试更改输入参数的顺序:
我以前(在Linux上)偶然发现过这个:
此调用产生错误:
g++ $(pkg-config --cflags --libs sdl2) sdl2test.cpp
sdl2test.cpp:(.text+0x11): undefined reference to `SDL_Init'
sdl2test.cpp:(.text+0x20): undefined reference to `SDL_GetError'
sdl2test.cpp:(.text+0x34): undefined reference to `SDL_Quit'
这项工作:
g++ sdl2test.cpp $(pkg-config --cflags --libs sdl2)
我更改了输入参数的顺序,并将SDL2main放在SLD2之前。
相关文章:
- C++有什么方法可以在既不调用函数模板也不提供其模板参数的情况下引用函数模板?
- 无法将右值引用函数与 GCC 匹配
- C ++引用函数参数似乎包含原始对象的副本,而不是充当"real reference"
- 通过引用函数传递指针参数是什么意思?
- 常量引用函数参数的地址何时唯一?
- 我想了解为什么在这个例子中使用引用函数?或者引用在c++函数中的重要性
- C++ 通过引用函数传递数组,但内容保持不变
- 用数组或指针引用函数?
- 引用函数如何"int &foo();"工作?
- 常量引用函数参数:是否可以禁止临时对象?
- 计算在代码中引用函数的次数
- <initializer_list> 引用函数
- 字符串引用(函数)的差异
- 在类中引用函数时的"No Matching Function for Call"
- 无法通过引用函数"calcValues"中"firstNum"和"secondNum"变量来更改值
- 尝试引用已删除的函数(不引用函数)
- 引用函数指针
- 引用函数按值和自动返回
- 为什么我们可以取消引用函数指针
- 通过引用函数传递值的目的是什么