This question already has an answer here:
这个问题在这里已有答案:
- Ubuntu 11.10: GCC/G++ won't link libraries 3 answers
Ubuntu 11.10:GCC / G ++不会链接库3的答案
I have a very simple C program that is taken from the SDL documentation:
我有一个非常简单的C程序,取自SDL文档:
#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;
}
I'm using sdl-config --cflags --libs
to provide the arguments to clang. It is able to link against the SDL headers, but fails to link against the SDL library:
我正在使用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)
I've tried to compile with gcc and get the same problem, so I feel I've missed something obvious. I'm running xubuntu 11.10 in case that's relevant.
我试图用gcc编译并得到同样的问题,所以我觉得我错过了一些明显的东西。我正在运行xubuntu 11.10,以防相关。
2 个解决方案
#1
0
try to install libraries. something like sudo apt-get install libsdl1.2-dev libsdl1.2debian
尝试安装库。像sudo apt-get install libsdl1.2-dev libsdl1.2debian
#2
0
First, you can always figure out the correct flags using pkg-config
, as shown here.
首先,您可以使用pkg-config始终找出正确的标志,如下所示。
Then you can use apt-file
and Google to figure out which packages you need installed via apt
. In this case, look in libsdl-*
-- you may want the base package, and the -dev
package.
然后你可以使用apt-file和Google来确定你需要通过apt安装哪些软件包。在这种情况下,查看libsdl- * - 您可能需要基本包和-dev包。
#1
0
try to install libraries. something like sudo apt-get install libsdl1.2-dev libsdl1.2debian
尝试安装库。像sudo apt-get install libsdl1.2-dev libsdl1.2debian
#2
0
First, you can always figure out the correct flags using pkg-config
, as shown here.
首先,您可以使用pkg-config始终找出正确的标志,如下所示。
Then you can use apt-file
and Google to figure out which packages you need installed via apt
. In this case, look in libsdl-*
-- you may want the base package, and the -dev
package.
然后你可以使用apt-file和Google来确定你需要通过apt安装哪些软件包。在这种情况下,查看libsdl- * - 您可能需要基本包和-dev包。