无法在Qt中设置库依赖
Unable to set library dependency in Qt
我有一个项目在Qt,与一个类定义的形式
Project MyP --- file p.h
#ifndef P_H
#define P_H
#include <QImage>
class PP
{
public:
static QImage P1(const QImage& a);
}
#endif
Project MyP --- file p.cpp
#include "p.h"
QImage PP::P1(const QImage& a)
{
QImage b;
return b;
}
I created a test project for the class above
project test, file test.h
#ifndef TEST_H
#define TEST_H
#include <QtTest/QtTest>
class Test : public QObject
{
Q_OBJECT
private slots:
void TestSomething();
};
#endif
#include "test.h"
#include "p.h"
void Test::TestSomething()
{
QImage sourceImage = QImage("source.png");
QImage newImage = PP::P1(sourceImage);
int result = 1*2;
QVERIFY(result == 2);
}
QTEST_MAIN(Test)
在c++中做同样的事情,但我可以很容易地添加一个lib依赖)…但在Qt我得到一个错误
error: undefined reference to `_imp___ZN6PPP1ENS_12P1MethodERK6QImage'
我试图添加库依赖,就像我在这里看到的
http://qt-project.org/wiki/How_to_create_a_library_with_Qt_and_use_it_in_an_application我添加了MyP头文件
#if defined MYP_LIB
#define MYP_COMMON_DLLSPEC Q_DECL_EXPORT
#else
#define MYP_COMMON_DLLSPEC Q_DECL_IMPORT
#endif
并将类声明更改为
class MYP_COMMON_DLLSPEC Dither
{
....
}
我添加了pro文件(为了方便,我将发布整个文件)
TEMPLATE = lib
VERSION = 1.0.0.0
CONFIG += staticlib debug
debug {
DESTDIR = bin/debug
}
release {
DESTDIR = bin/release
}
HEADERS +=
pp.h
SOURCES +=
pp.cpp
DEFINES += MYP_LIB
然后在测试项目中,我在概要文件中添加了
DEPENDPATH += . ../myp
INCLUDEPATH += ../myp
win32:LIBS += ../myp/bin/debug/libmyp.a
LIBS+= -L../myp/bin/debug -lmyp
我一直无法创建一个库文件,或一个dll文件,并已无法让项目一起工作。注意:它们都在同一个溶液中。
如何从单独的项目中正确运行测试?
您必须告诉链接器(分别)从DLL导入和导出符号,因此您必须声明您的类,如:
Project MyP --- file p.h
#ifndef P_H
#define P_H
#if defined(MyP_LIBRARY)
# define MyPSHARED_EXPORT Q_DECL_EXPORT
#else
# define MyPSHARED_EXPORT Q_DECL_IMPORT
#endif
#include <QImage>
MyPSHARED_EXPORT class PP
{
public:
...
并添加
DEFINES += MyP_LIBRARY
到您的MyP。箴文件
更多信息见http://qt project.org/doc/qt - 4.8 -/- sharedlibrary.html
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 在C++/Linux中设置单调时钟的一些技巧
- 如何从C++中的依赖类型中获得它所依赖的类型
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 嵌套在类中时无法设置成员数据
- 需要帮助设置在C++中使用的Potrace
- 如何在自删除后将对象设置为nullptr
- 将指针设置为"nullptr"并不能防止双重删除?
- 如何在Ubuntu中使用cmake设置qt4
- ld:bind_at_load和-bitcode_bundle(Xcode设置ENABLE_bitcode=YES)不能
- CMake 使用设置编译依赖项
- 如何设置二进制文件所依赖的 DLL 的名称
- 如何设置依赖于其他参数的参数默认值
- Heroku / Rails:无法设置供应商化依赖项的路径
- 无法在Qt中设置库依赖
- 设置库之间的依赖(CMake)
- 设置依赖于调用栈的条件断点
- CMake:如何设置源,库和CMakeLists.txt依赖关系
- 在ndk{}中使用moduleName时如何设置JNI依赖
- Clion mongodb依赖设置