【问题标题】:Linking Against SDL From a C Program [duplicate]从 C 程序链接 SDL [重复]
【发布时间】:2013-03-10 19:20:28
【问题描述】:

我有一个非常简单的 C 程序是 taken from the SDL documentation:

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

int main() {
    if (SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0) {
        return EXIT_FAILURE;
    }
    atexit(SDL_Quit);
    return EXIT_SUCCESS;
}

我使用sdl-config --cflags --libs 为clang 提供参数。它能够链接到 SDL 标头,但无法链接到 SDL 库:

/tmp/example-f2Tgg6.o: In function `main':
example.c:7: undefined reference to `SDL_Init'
example.c:8: undefined reference to `SDL_Quit'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我尝试用 gcc 编译并遇到同样的问题,所以我觉得我错过了一些明显的东西。我正在运行 xubuntu 11.10,以防万一。

【问题讨论】:

  • 找不到库 -> SDL.lib 和 sdlmain.lib
  • 我应该在哪里寻找 SDL.lib 和 sdlmain.lib?这些是 .a 文件的 Windows 等价物吗?因为我相当确定 ld 正在找到 SDL 库,因为如果我将 -lSDL 更改为 -lrubbish 我会得到 /usr/bin/ld: cannot find -lrubbish
  • 将您的 SDL.dll 放在可执行文件夹中,并将 SDL.lib 放在您告诉 IDE/编译器它们应该放在的位置。

标签: c sdl


【解决方案1】:

尝试安装库。类似sudo apt-get install libsdl1.2-dev libsdl1.2debian

【讨论】:

  • 我已经有了。而且,就像我在上面的评论中所说的那样,我很确定 ld 正在寻找 SDL 库。
  • 这个链接可能有用:stackoverflow.com/questions/8498899/…
  • 好的,已经解决了,谢谢。
【解决方案2】:

首先,您始终可以使用pkg-config 找出正确的标志,如here 所示。

然后您可以使用apt-file 和Google 来确定您需要通过apt 安装哪些软件包。在这种情况下,请查看libsdl-*——您可能需要基本包和-dev 包。

【讨论】:

  • 您的pkg-config 示例的链接现已损坏。如果您可以在答案正文中包含一个示例,那将会很有帮助。 =]
  • 以下是在 Mac 上使用 pkg-config 编译 SDL 2.0 的方法:gcc example.c $(pkg-config --cflags --libs sdl2)
猜你喜欢
  • 1970-01-01
  • 2016-01-10
  • 1970-01-01
  • 1970-01-01
  • 2015-05-17
  • 2019-01-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多