首页 > 解决方案 > 加载共享库时出错:libSDL2-2.0.so.0

问题描述

我无法加载动态 SDL2 库。有这个简单的代码:

#include <iostream>
#include <SDL2/SDL.h>

using namespace std;

int main()
{
    if (!SDL_Init(SDL_INIT_VIDEO))
    {
        cout << "ok";
    }
}

并在此目录中有dll:

user@Host:~/Desktop/bin$ ls /usr/local/lib
cmake                  libSDL2.a      libSDL2main.la  libSDL2_test.la
libSDL2-2.0.so.0       libSDL2.la     libSDL2.so      pkgconfig
libSDL2-2.0.so.0.12.0  libSDL2main.a  libSDL2_test.a  python3.8

当编译为

user@Host:~/Desktop/bin$ g++ -I/usr/local/lib a.cpp -lSDL2 -lSDL2main
user@Host:~/Desktop/bin$ ./a.out 
./a.out: error while loading shared libraries: libSDL2-2.0.so.0: cannot open shared object file: No such file or directory

PS:我已经从 tar https://www.libsdl.org/download-2.0.php手动安装了 SDL2,而不是通过dpkg,所以我不得不./config; make all; make install在 untared 目录中。由于以下错误,该软件包libsdl2-dev无法安装:

Err http://cz.archive.ubuntu.com/ubuntu focal-updates/main amd64 libasound2-dev amd64 1.2.2-2.1ubuntu2
  404  Not Found [IP: 2001:67c:1360:8001::24 80]
Err http://cz.archive.ubuntu.com/ubuntu focal-updates/main amd64 zlib1g-dev amd64 1:1.2.11.dfsg-2ubuntu1.1
  404  Not Found [IP: 2001:67c:1360:8001::24 80]
Err http://cz.archive.ubuntu.com/ubuntu focal-updates/main amd64 libudev-dev amd64 245.4-4ubuntu3.2
  404  Not Found [IP: 2001:67c:1360:8001::24 80]
98% [Working]E: Failed to fetch http://cz.archive.ubuntu.com/ubuntu/pool/main/a/alsa-lib/libasound2-dev_1.2.2-2.1ubuntu2_amd64.deb: 404  Not Found [IP: 2001:67c:1360:8001::24 80]
E: Unable to fetch some packages; try '-o APT::Get::Fix-Missing=true' to continue with missing packages

但是现在手动安装了库和头文件,我怎样才能将它们从/usr/local/lib?

PS2:

user@Host:~/Desktop/script$ uname -a
Linux Host 5.4.0-52-generic #57-Ubuntu SMP Thu Oct 15 10:57:00 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

标签: c++ubuntugccsdl-2

解决方案


推荐阅读