如何将SDL.a文件与GCC链接?
不重复;各种论坛上的答案并没有解决这个问题。 我通过命令运行GCC,并且从SDL获取未定义的引用,即使看起来我正确链接了SDL,如何停止获取这些未定义的引用? 我没有从mingw获得未定义的引用,只有SDL 这是我的命令:(据我所知,GCC正在查找所有库) 这是输出:如何将SDL.a文件与GCC链接?,gcc,sdl,Gcc,Sdl,不重复;各种论坛上的答案并没有解决这个问题。 我通过命令运行GCC,并且从SDL获取未定义的引用,即使看起来我正确链接了SDL,如何停止获取这些未定义的引用? 我没有从mingw获得未定义的引用,只有SDL 这是我的命令:(据我所知,GCC正在查找所有库) 这是输出: C:...\main.c:(.text+0xe): undefined reference to 'SDL_Init' C:...\main.c:(.text+0x13): undefined reference to 'SDL_
C:...\main.c:(.text+0xe): undefined reference to 'SDL_Init'
C:...\main.c:(.text+0x13): undefined reference to 'SDL_Quit'
c:/__coding/tools/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccqsLSRk.o: bad reloc address 0x20 in section '.eh_frame'
c:/__coding/tools/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
c包括SDL.h,只运行SDL_Init()和SDL_Quit()。
当我删除SDL_Init()和SDL_Quit()时,我还得到了对“winmain”的经典的未定义引用。
感谢alot.
mingw32
建议您使用32位编译器,但尝试将64位二进制文件(如x86\u 64-w64
)链接到它。如果是这种情况,它不能工作,它们都应该使用相同的“比特数”@UnholySheep是“SDL2\i686-w64-mingw32\”32位?使用“SDL2\i686-w64-mingw32\”文件。错误仍然相同。我认为您不需要所有这些-l
和-l
s。这些是动态链接所必需的(当以这种方式链接库时,也可以在名称中省略“lib”部分;lib已经隐含)。相反,只需像传递任何其他源文件一样,将要使用的.a文件传递到gcc命令中。我不确定-l“libmingw32.a”
(和其他文件)是否有效,通常您会将其作为-lmmingw32
@christiangibons来编写,如果我不放-l,它就是找不到文件,但我可以缩短库名,谢谢。
C:...\main.c:(.text+0xe): undefined reference to 'SDL_Init'
C:...\main.c:(.text+0x13): undefined reference to 'SDL_Quit'
c:/__coding/tools/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\...\AppData\Local\Temp\ccqsLSRk.o: bad reloc address 0x20 in section '.eh_frame'
c:/__coding/tools/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status