gpt4 book ai didi

c++ - 无法在 Linux 上打开 QLibrary

转载 作者:太空宇宙 更新时间:2023-11-04 10:20:53 25 4
gpt4 key购买 nike

当我尝试加载与二进制文件存储在同一目录中的特定库时,出现错误:

Cannot load library uuirtdrv.so: (uuirtdrv.so: cannot open shared object file: No such file or directory)

但仅限于 linux,不适用于 windows。在 Windows 上,它就像一个魅力。

Q制作

QT += core serialport
QT -= gui

CONFIG += c++11

TARGET = serial-test
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app

SOURCES += main.cpp

win32 {
dll.files += $$PWD/uuirtdrv.dll
dll.path = $$OUT_PWD
INSTALLS += dll
}

unix {
so.files += $$PWD/uuirtdrv.so
so.path = $$OUT_PWD
INSTALLS += so
}

QMake 将库复制到目标目录。

主要.cpp

if (!QLibrary::isLibrary("uuirtdrv.so"))
{
qDebug() << "uuirtdrv does not exist.";
}

qDebug() << "Loading uuirtdrv";

QLibrary hinstLib;
hinstLib.setFileName("uuirtdrv.so");

if (hinstLib.load()) qDebug() << "uuirtdrv loaded.";
else qDebug() << hinstLib.errorString();

所有 main.cpp 所做的就是检查库是否存在,然后尝试加载它。不知道这里可能出了什么问题。我是否需要将 .so 放入特定目录? (文档在 linux 上提到了 LD_LIBRARY_PATH。)

编辑:当我添加绝对路径而不是相对路径时,会发生此错误:

Cannot load library /media/sf_Qt/build-serial-test-Desktop-Debug/uuirtdrv.so: (libstdc++.so.5: cannot open shared object file: No such file or directory)"

最佳答案

libstdc++.so.5: cannot open shared object file: No such file or directory

请安装 libstdc++5 : Fedora, CentOS → # yum install compat-libstdc++-33

新版 Fedora:# dnf install compat-libstdc++-33

Debian、Ubuntu:apt-get install libstdc++5

关于c++ - 无法在 Linux 上打开 QLibrary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43983501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com