首先,我知道这个问题已被问到(see here),但这些解决方案对我不起作用。
我正在尝试在ubuntu 14.04上安装opencv以与Qt Creator一起使用。
我完全按照this教程确认它是通过运行facedetect示例来确定的。
然后我开始使用this教程将Qt创建者与opencv一起使用。我完全按照视频中的步骤操作,但是当我构建并运行示例时,我收到以下错误:
/usr/bin/ld: cannot find -lopencv_core
/usr/bin/ld: cannot find -lopencv_imgcodecs
/usr/bin/ld: cannot find -lopencv_highgui
完整编译输出:
g++ -Wl,-rpath,/home/tpst/Program_Files/Qt-5.3.1/5.3/gcc_64 -Wl,-rpath,/home/tpst/Program_Files/Qt-5.3.1/5.3/gcc_64/lib -o test main.o -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui -L/home/tpst/Program_Files/Qt-5.3.1/5.3/gcc_64/lib -lQt5Core -lpthread
/usr/bin/ld: cannot find -lopencv_core
/usr/bin/ld: cannot find -lopencv_imgcodecs
/usr/bin/ld: cannot find -lopencv_highgui
collect2: error: ld returned 1 exit status
make: *** [test] Error 1
23:02:50: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project test (kit: Desktop Qt 5.3 GCC 64bit)
When executing step 'Make'
以下是我的.pro文件的内容:
QT += core
QT -= gui
TARGET = test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui
SOURCES += main.cpp
我也尝试使用终端进行编译并获得相同的结果(/ usr / bin / ld:找不到-llib)
我不明白为什么Qt无法找到这些库。您可以看到它们存在于目录
中一些帮助将不胜感激。我是linux和Qt的新手,我真的不理解发布到类似问题的解决方案,但我自己也无法解决这个问题。
答案 0 :(得分:2)
afaik您的链接库必须看起来像#include <memory>
using namespace std;
class Data {
public:
void update() {} // non-const method which modifies internal state of Data
};
//Basic wrapper
template <typename D>
class BaseWrapper {
public:
BaseWrapper(shared_ptr<D> data) : myData(data) {}
protected:
shared_ptr<D> myData;
};
template <typename D, bool const = std::is_const<D>::value>
class Wrapper : public BaseWrapper<D>
{
};
//Const-Version
template <typename D>
class Wrapper<D, true> : public BaseWrapper<D>
{
public:
Wrapper(shared_ptr<D> data) : BaseWrapper(data) {}
};
//Non-Const-Version
template <typename D>
class Wrapper<D, false> : public BaseWrapper<D>
{
public:
Wrapper(shared_ptr<D> data) : BaseWrapper(data) {}
void updateData() { myData->update(); }
};
int main()
{
Wrapper<Data> a(nullptr);
Wrapper<const Data> b(nullptr);
a.updateData();
b.updateData();//error C2039: 'updateData': is not a member of 'Wrapper<const Data,true>'
}
,但您的库名为libName.so
,因此链接器找不到它们。尝试创建符号链接:
libName.so.version