我试图在Arch Linux上静态链接到SDL2,以便为游戏生成单一的、跨平台的可执行文件。包含头文件安装在/usr/ SDL2 /sdl2中,库安装在/usr/lib中。使用g++ -I/usr/include/SDL2 -lSDL2 hello.cpp动态编译是可行的,因为./a.out会产生一个空白窗口,但我无法将SDL2静态链接到可执行文件。
Hello.cpp的内容:
#include <iostream>
#include "SDL.h"
int main() {
bool quit{false};
SDL_Event inputEvent;
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* window = SDL_CreateWindow("Hello", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1280, 1280, 0);
while (!quit) {
SDL_WaitEvent(&inputEvent);
switch (inputEvent.type) {
case SDL_QUIT:
quit = true;
break;
}
}
SDL_Quit();
std::cout << "Bye!";
return 0;
}g++ -I/usr/include/SDL2 -static -lSDL2 hello.cpp返回/usr/bin/ld: cannot find -lSDL2,而g++ -I/usr/include/SDL2 -l:libSDL2 hello.cpp返回/usr/bin/ld: cannot find -l:libSDL2。
发布于 2019-10-15 23:56:35
事实证明,AUR中sdl2-hg的PKGBUILD将libSDL2.a重命名为libSDL2main.a,因此出现libSDL2.a not found错误。从PKGBUILD中删除有问题的行并重新编译SDL2可以缓解该问题。
https://stackoverflow.com/questions/58355561
复制相似问题