繁体   English   中英

SDL2未定义对MinGW几个功能的引用

[英]SDL2 undefined reference to several functions with MinGW

我有以下项目目录结构:

/program1
  /bin
  /include
    /SDL2
  /lib
  /resources
  /source
    makefile

我在这里阅读了很多有关此问题的问答。 但是我真的不明白发生了什么。 我遵循了文章中的所有步骤。 我正在使用Windows 7 64位,并且从i686-w64-mingw32粘贴中获得了include和lib文件。 如上所述,我将这些文件放在目录中。

我在source目录中的简单main.cpp代码是:

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

int main( int argc, char* argv[ ] ) {
    if( SDL_Init( SDL_INIT_VIDEO ) != 0 ) {
        std::cout << "SDL_Init Error: " << SDL_GetError( ) << std::endl;
        return 1;
    }

    SDL_Quit( );
    return 0;
}

source目录中,我也有一个makefile ,与MSYS一起使用,这是makefile产生的编译命令:

g++ -Wall -c -std=c++11 -I../include -I../include/SDL2 main.cpp -o ../bin/main.o
g++ ../bin/main.o -L../lib -lmingw32 -lSDL2main -lSDL2 -mwindows -o ../bin/program1.exe

经过这两个命令,我有这个大错误:(

../lib/libSDL2.a(SDL_windows.o): In function `WIN_CoInitialize':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/core/windows/SDL_windows.c:73: undefined reference to `_imp__CoInitializeEx@8'
../lib/libSDL2.a(SDL_windows.o): In function `WIN_CoUninitialize':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/core/windows/SDL_windows.c:92: undefined reference to `_imp__CoUninitialize@0'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `IME_SetupAPI':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:617: undefined reference to `ImmGetIMEFileNameA@12'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:630: undefined reference to `ImmGetContext@4'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:633: undefined reference to `ImmReleaseContext@8'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `IME_GetId':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:551: undefined reference to `ImmGetIMEFileNameA@12'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:566: undefined reference to `GetFileVersionInfoSizeA@8'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:570: undefined reference to `GetFileVersionInfoA@16'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:571: undefined reference to `VerQueryValueA@16'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `UILess_GetCandidateList':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:984: undefined reference to `_imp__SysFreeString@4'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `IME_ClearComposition':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:683: undefined reference to `ImmGetContext@4'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:687: undefined reference to `ImmNotifyIME@16'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:691: undefined reference to `ImmNotifyIME@16'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:692: undefined reference to `ImmReleaseContext@8'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `IME_Disable':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:364: undefined reference to `ImmAssociateContext@8'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `IME_ClearComposition':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:689: undefined reference to `ImmSetCompositionStringW@24'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:683: undefined reference to `ImmGetContext@4'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:687: undefined reference to `ImmNotifyIME@16'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:691: undefined reference to `ImmNotifyIME@16'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:692: undefined reference to `ImmReleaseContext@8'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:689: undefined reference to `ImmSetCompositionStringW@24'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `UIElementSink_BeginUIElement@12':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:1051: undefined reference to `_imp__SysFreeString@4'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `UIElementSink_UpdateUIElement@8':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:1078: undefined reference to `_imp__SysFreeString@4'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `IME_Init':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:309: undefined reference to `_imp__CoCreateInstance@20'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:323: undefined reference to `ImmGetContext@4'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:324: undefined reference to `ImmReleaseContext@8'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `UILess_SetupSinks':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:1192: undefined reference to `_imp__CoCreateInstance@20'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `IME_GetId':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:551: undefined reference to `ImmGetIMEFileNameA@12'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:566: undefined reference to `GetFileVersionInfoSizeA@8'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:570: undefined reference to `GetFileVersionInfoA@16'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `IME_GetReadingString':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:423: undefined reference to `ImmGetContext@4'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:498: undefined reference to `ImmReleaseContext@8'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `IME_GetId':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:571: undefined reference to `VerQueryValueA@16'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `IME_Quit':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:378: undefined reference to `ImmAssociateContext@8'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `IME_Enable':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:349: undefined reference to `ImmAssociateContext@8'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `IME_ClearComposition':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:683: undefined reference to `ImmGetContext@4'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:687: undefined reference to `ImmNotifyIME@16'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:691: undefined reference to `ImmNotifyIME@16'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:692: undefined reference to `ImmReleaseContext@8'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `IME_Disable':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:364: undefined reference to `ImmAssociateContext@8'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `IME_ClearComposition':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:689: undefined reference to `ImmSetCompositionStringW@24'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `WIN_SetTextInputRect':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:202: undefined reference to `ImmGetContext@4'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:209: undefined reference to `ImmSetCompositionWindow@8'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:210: undefined reference to `ImmReleaseContext@8'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `IME_HandleMessage':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:852: undefined reference to `ImmGetContext@4'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `IME_GetCompositionString':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:699: undefined reference to `ImmGetCompositionStringW@16'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:704: undefined reference to `ImmGetCompositionStringW@16'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `IME_HandleMessage':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:890: undefined reference to `ImmReleaseContext@8'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `IME_ClearComposition':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:683: undefined reference to `ImmGetContext@4'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:687: undefined reference to `ImmNotifyIME@16'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:691: undefined reference to `ImmNotifyIME@16'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:692: undefined reference to `ImmReleaseContext@8'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `IME_HandleMessage':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:885: undefined reference to `ImmGetContext@4'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `IME_GetCandidateList':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:767: undefined reference to `ImmGetCandidateListW@16'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `IME_GetCompositionString':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:699: undefined reference to `ImmGetCompositionStringW@16'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:704: undefined reference to `ImmGetCompositionStringW@16'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `IME_ClearComposition':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:689: undefined reference to `ImmSetCompositionStringW@24'
../lib/libSDL2.a(SDL_windowskeyboard.o): In function `IME_GetCandidateList':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:771: undefined reference to `ImmGetCandidateListW@16'
../lib/libSDL2.a(SDL_xaudio2.o): In function `XAudio2Create':
/usr/local/cross-tools/i686-w64-mingw32/include/xaudio2.h:1273: undefined reference to `_imp__CoCreateInstance@20'
/usr/local/cross-tools/i686-w64-mingw32/include/xaudio2.h:1273: undefined reference to `_imp__CoCreateInstance@20'
/usr/local/cross-tools/i686-w64-mingw32/include/xaudio2.h:1273: undefined reference to `_imp__CoCreateInstance@20'
/usr/local/cross-tools/i686-w64-mingw32/include/xaudio2.h:1273: undefined reference to `_imp__CoCreateInstance@20'
../lib/libSDL2.a(SDL_dinputhaptic.o): In function `SDL_DINPUT_HapticInit':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/haptic/windows/SDL_dinputhaptic.c:98: undefined reference to `_imp__CoCreateInstance@20'
../lib/libSDL2.a(SDL_systimer.o): In function `SDL_SetSystemTimerResolution':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/timer/windows/SDL_systimer.c:57: undefined reference to `_imp__timeBeginPeriod@4'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/timer/windows/SDL_systimer.c:51: undefined reference to `_imp__timeEndPeriod@4'
../lib/libSDL2.a(SDL_systimer.o): In function `SDL_TicksInit':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/timer/windows/SDL_systimer.c:102: undefined reference to `_imp__timeGetTime@0'
../lib/libSDL2.a(SDL_systimer.o): In function `SDL_SetSystemTimerResolution':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/timer/windows/SDL_systimer.c:51: undefined reference to `_imp__timeEndPeriod@4'
../lib/libSDL2.a(SDL_systimer.o): In function `SDL_GetTicks_REAL':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/timer/windows/SDL_systimer.c:141: undefined reference to `_imp__timeGetTime@0'
../lib/libSDL2.a(SDL_systimer.o): In function `SDL_TicksInit':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/timer/windows/SDL_systimer.c:102: undefined reference to `_imp__timeGetTime@0'
../lib/libSDL2.a(SDL_winmm.o): In function `WINMM_CloseDevice':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/audio/winmm/SDL_winmm.c:170: undefined reference to `_imp__waveOutUnprepareHeader@12'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/audio/winmm/SDL_winmm.c:170: undefined reference to `_imp__waveOutUnprepareHeader@12'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/audio/winmm/SDL_winmm.c:182: undefined reference to `_imp__waveInClose@4'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/audio/winmm/SDL_winmm.c:187: undefined reference to `_imp__waveOutClose@4'
../lib/libSDL2.a(SDL_winmm.o): In function `WINMM_PlayDevice':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/audio/winmm/SDL_winmm.c:131: undefined reference to `_imp__waveOutWrite@12'
../lib/libSDL2.a(SDL_winmm.o): In function `SetMMerror':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/audio/winmm/SDL_winmm.c:106: undefined reference to `_imp__waveOutGetErrorTextW@12'
../lib/libSDL2.a(SDL_winmm.o): In function `WINMM_OpenDevice':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/audio/winmm/SDL_winmm.c:285: undefined reference to `_imp__waveOutOpen@24'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/audio/winmm/SDL_winmm.c:331: undefined reference to `_imp__waveOutPrepareHeader@12'
../lib/libSDL2.a(SDL_winmm.o): In function `PrepWaveFormat':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/audio/winmm/SDL_winmm.c:216: undefined reference to `_imp__waveOutOpen@24'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/audio/winmm/SDL_winmm.c:214: undefined reference to `_imp__waveInOpen@24'
../lib/libSDL2.a(SDL_winmm.o): In function `WINMM_OpenDevice':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/audio/winmm/SDL_winmm.c:281: undefined reference to `_imp__waveInOpen@24'
../lib/libSDL2.a(SDL_winmm.o): In function `DetectWaveInDevs':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/audio/winmm/SDL_winmm.c:57: undefined reference to `_imp__waveInGetNumDevs@0'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/audio/winmm/SDL_winmm.c:57: undefined reference to `_imp__waveInGetDevCapsW@12'
../lib/libSDL2.a(SDL_winmm.o): In function `DetectWaveOutDevs':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/audio/winmm/SDL_winmm.c:56: undefined reference to `_imp__waveOutGetNumDevs@0'
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/audio/winmm/SDL_winmm.c:56: undefined reference to `_imp__waveOutGetDevCapsW@12'
../lib/libSDL2.a(SDL_dinputjoystick.o): In function `SDL_DINPUT_JoystickInit':
/Users/slouken/release/SDL/SDL2-2.0.4-source/foo-x86/../src/joystick/windows/SDL_dinputjoystick.c:317: undefined reference to `_imp__CoCreateInstance@20'
collect2.exe: error: ld returned 1 exit status
make: *** [program1.exe] Error 1

我已经尝试将include切换为“ SDL2 / SDL.h”,并尝试将include和lib文件放入mingw文件夹中,并且产生相同的错误。 我的编译命令错误吗?

编辑 :奇怪的是:如果我将编译命令修改为绝对路径,例如F:/ APIs / SDL2 / include和lib,程序将进行编译。 为什么?

链接器使用了libSDL2.a (这是静态库)。 静态库缺少依赖项信息,因此所有其他依赖项都必须手动指定。 要使用动态库,您需要libSDL2.dll.a在你的库路径(新的gcc / MinGW的应该接受SDL2.dll为好,即使没有.dll.a ,虽然我从未使用过)。 当然,通过动态链接,您还需要将SDL2.dll与生成的.exe捆绑在一起或在系统目录中才能实际启动生成的程序。

您可以将这两个库都放在同一目录中,就像在SDL2发行版中一样。 缺省情况下,链接程序应优先使用动态库(如果它可以找到一个库),或者可以通过-Wl,-Bstatic-Wl,-Bdynamic开关手动控制(如果需要,请先阅读文档-这些标志会影响之后指定的所有库它)。

(仅涵盖mingw; msvc具有不同的库格式,而SDL2具有单独的下载文件)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM