Mingw32中对"SDL_main"的未定义引用
Undefined reference to `SDL_main' in Mingw32
我正在尝试在我的 Windows 10 64 位机器上编译我的 SDL 项目。不幸的是,在使用 mingw32-make 编译时。我的编译在完成链接之前失败,抛出旧的"对'SDL_main'的未定义引用"。我已经确保我使用mingw开发库"i686-w64-mingw32"。(我也切换到"x86_64-w64-mingw32",但结果相同。在我包含 SDL 之后 #undef 主要内容。
这是运行mingw32-make后的控制台输出...
g++ ./neo/engine/gamesys/EngineCore.cpp ./neo/engine/gamesys/Logger.cpp ./neo/engine/gamesys/EventDispatcher.cpp ./neo/engine/renderer/Renderer.cpp ./neo/engine/renderer/RendererSetup.cpp -IC:\mingw_dev_lib\SDL2-2.0.4i686\include -LC:mingw_dev_lib\SDL2-2.0.4i686lib -w -Wl,-subsystem,windows -lmingw32 -lSDL2main -lSDL2 -lopengl32 -lglu32 -o pixelHell
C:mingw_dev_libSDL2-2.0.4i686lib/libSDL2main.a(SDL_windows_main.o): In function `main_utf8':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/main/windows/SDL_windows_main.c:126: undefined reference to `SDL_main'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/main/windows/SDL_windows_main.c:126: undefined reference to `SDL_main'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/main/windows/SDL_windows_main.c:126: undefined reference to `SDL_main'
collect2.exe: error: ld returned 1 exit status
Makefile:29: recipe for target 'all' failed
mingw32-make: *** [all] Error 1
生成文件
#OBJS specifies which files to compile as part of the project
OBJS = $(wildcard ./neo/engine/**/*.cpp)
#CC specifies which compiler we're using
CC = g++
#INCLUDE_PATHS specifies the additional include paths we'll need
INCLUDE_PATHS = -IC:\mingw_dev_lib\SDL2-2.0.4i686\include
#LIBRARY_PATHS specifies the additional library paths we'll need
LIBRARY_PATHS = -LC:mingw_dev_lib\SDL2-2.0.4i686lib
#COMPILER_FLAGS specifies the additional compilation options we're using
# -w suppresses all warnings
# -Wl,-subsystem,windows gets rid of the console window
COMPILER_FLAGS = -w -Wl,-subsystem,windows
SDL_LIBS = sdl-config --libs
#LINKER_FLAGS specifies the libraries we're linking against
LINKER_FLAGS = -lmingw32 -lSDL2main -lSDL2 -lopengl32 -lglu32
#OBJ_NAME specifies the name of our exectuable
OBJ_NAME = pixelHell
#This is the target that compiles our executable
all : $(OBJS)
$(CC) $(OBJS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o $(OBJ_NAME)
clean:
rm -f $(OBJ_NAME).exe
主.cpp
#include "gamesys/EngineCore.hpp"
extern "C" //<---- Thought that would help...
int main(int argc, char *argv[])
{
phEngineCore* engine = new phEngineCore();
engine->setWindowTitle("Pixel Hell Engine 0.0.1");
/* Initalize the game engine. */
if(!engine->initalize())
return 1;
/* Run framework. */
engine->run();
/* Clean up memory when finished! */
engine->clearAll();
delete engine;
return 0;
}
引擎核心.hpp 顶部
#ifndef ENGINE_CORE_HPP
#define ENGINE_CORE_HPP
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
#include <stdio.h>
#include <string>
#include <vector>
#undef main //....
根据文档:
确保将 main() 声明为:
#include "SDL.h" int main(int argc, char *argv[])
您的main.cpp
文件看起来确实不正确.
有关更多详细信息,请参阅上述链接。
啊需要将 3 月的行更改为:
OBJS = $(wildcard ./neo/engine/*.cpp) $(wildcard ./neo/engine/**/*.cpp)
我会假设/**/*.cpp会解决这个问题......
相关文章:
- C++/生成文件错误:未定义对"main"的引用
- 在 Linux 上编译 - 在函数 '_start' 中:(.text+0x20):对 'main' 的未定义引用
- crt1.o:在函数"_start"中:(.text+0x20):对"main"的未定义引用
- main.cpp:(.text+0x8ea):在C++中未定义的引用
- main.cpp:(.text+0x8f):对[对象方法]的未定义引用
- 从 crt1.o 对 main 的未定义引用
- 对"main"的未定义引用 - 但包括 main 函数
- main.cpp :(.text 0x5f):未定义的引用
- 尝试使用 MinGW 编译 Assembly + C++:ccqKAvXJ.o:main.cpp:(.text+0x18):对 'GetMagicNumber' 的未定义引用
- 在Linux上使用makefile,使用Boost和MPI对"main"的未定义引用
- QT Subdir-未定义对main的引用-错误
- 为什么在包含类头的情况下,我的数组在main中未定义
- 生成文件错误:未定义对 main 的引用
- 代码块中对 main 的未定义引用
- OpenCV, XCode 中的链接错误, 架构的未定义符号 x86_64: "_cvHaarDetectObjects" , 引用自: _main in main.o
- main.c:(.text+0x30):对"互惠"的未定义引用
- 未能创建第一个库`对“main”的未定义引用
- g++ 链接问题:在函数 '_start' 中: (.text+0x20):对 'main' 的未定义引用
- LoopFillZerobss对main有一个未定义的引用
- 编译时对"main"的 C++ 未定义引用