【问题标题】:SDL Addon Libraries not Linking CorrectlySDL 插件库未正确链接
【发布时间】:2012-09-09 16:20:11
【问题描述】:

我尝试将 SDL_mixer、SDL_ttf 和 SDL_image 链接到我的项目,但由于某种原因,在编译我的代码时会弹出这些错误。我包含的头文件取决于它上面的库。我按以下顺序链接到我的图书馆:

MinGW32 OpenGL32 SDLmain SDL SDL_image SDL_ttf SDL_mixer

#include <map>
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include <GL/gl.h>
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_mixer.h>
#include <SDL/SDL_ttf.h>

using namespace std;

#include "include_file.h"
#include "structure.h"
#include "player.h"
#include "healthclass.h"
#include "items.h"
#include "loadfiles.h"
#include "init_game.h"
#include "missions.h"

然后报错:

obj\Release\main.o:main.cpp:(.text+0x16e): undefined reference to `Mix_LoadMUS'
obj\Release\main.o:main.cpp:(.text+0x197): undefined reference to `Mix_LoadWAV_RW'
obj\Release\main.o:main.cpp:(.text+0x1c0): undefined reference to `Mix_LoadWAV_RW'
obj\Release\main.o:main.cpp:(.text+0x1e9): undefined reference to `Mix_LoadWAV_RW'
obj\Release\main.o:main.cpp:(.text+0x7cd): undefined reference to `IMG_Load'
obj\Release\main.o:main.cpp:(.text+0x996): undefined reference to `TTF_RenderUTF8_Shaded'
obj\Release\main.o:main.cpp:(.text+0x20ca): undefined reference to `Mix_CloseAudio'
obj\Release\main.o:main.cpp:(.text+0x20cf): undefined reference to `TTF_Quit'
obj\Release\main.o:main.cpp:(.text+0x2f7b): undefined reference to `IMG_Load'
obj\Release\main.o:main.cpp:(.text+0x3788): undefined reference to `TTF_Init'
obj\Release\main.o:main.cpp:(.text+0x37ac): undefined reference to `Mix_OpenAudio'
obj\Release\main.o:main.cpp:(.text+0x3914): undefined reference to `TTF_OpenFont'
obj\Release\main.o:main.cpp:(.text+0x3983): undefined reference to `Mix_PlayMusic'
obj\Release\main.o:main.cpp:(.text+0x61f0): undefined reference to `Mix_PlayChannelTimed'
obj\Release\main.o:main.cpp:(.text+0x6330): undefined reference to `Mix_Playing'

【问题讨论】:

  • 你是如何链接到图书馆的?在大多数情况下,您可以将静态 LIB 文件包含在项目中,将 DLL 文件包含在结果中,或者您可以动态链接(使用 sdl-config 的 Windows 等效项)。
  • 我使用了lazyfoo 的教程,在那里我链接到了lib 文件。 lazyfoo.net/SDL_tutorials/lesson01/windows/codeblocks/index.php

标签: c++ mingw sdl linker-errors codeblocks


【解决方案1】:

我发现我试图用 64 位版本的 SDL_image、SDL_mixer 和 SDL_ttf 编译 32 位版本的 SDL。因此,在安装附加库时,请在安装库文件时使用 x86 文件夹而不是 x64 文件夹。如果你有一台 64 位的计算机并不重要,如果 SDL 是 32 位,则使用 x86 lib 文件夹,除非你知道自己在做什么,而我不知道。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多