我在QtCeator&amp ;;中编译了动态链接库。 MinGW编译器:
.pro文件
#-------------------------------------------------
#
# Project created by QtCreator 2018-04-01T04:51:46
#
#-------------------------------------------------
QT -= gui
TARGET = kuins_method
TEMPLATE = lib
DEFINES += KUAINRULE_EXPORTS
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
../kuins_method_file/abstractnormalform.cpp \
../kuins_method_file/abstractobject.cpp \
../kuins_method_file/constituent.cpp \
../kuins_method_file/expression.cpp \
../kuins_method_file/initkuainrule.cpp \
../kuins_method_file/kuainrule.cpp \
../kuins_method_file/normalform.cpp \
../kuins_method_file/perfectnormalform.cpp \
../kuins_method_file/shortnormalform.cpp
HEADERS += \
../kuins_method_file/abstractnormalform.h \
../kuins_method_file/abstractobject.h \
../kuins_method_file/constituent.h \
../kuins_method_file/defines.h \
../kuins_method_file/expression.h \
../kuins_method_file/global.h \
../kuins_method_file/initkuainrule.h \
../kuins_method_file/kuainrule.h \
../kuins_method_file/normalform.h \
../kuins_method_file/perfectnormalform.h \
../kuins_method_file/shortnormalform.h
unix {
target.path = /usr/lib
INSTALLS += target
}
连接到整个项目的全局文件:
#ifndef GLOBAL_H
#define GLOBAL_H
#ifdef _MSC_VER
#ifdef KUAINRULE_EXPORTS
#define KUAINRULE_API __declspec(dllexport)
#else
#define KUAINRULE_API __declspec(dllimport)
#endif
#elif __MINGW32__
#include <QtCore/qglobal.h>
#ifdef KUAINRULE_EXPORTS
# define KUAINRULE_API Q_DECL_EXPORT
#else
# define KUAINRULE_API Q_DECL_IMPORT
#endif
#else
#error MSVC or Qt + MinGW compiler required.
#endif
#endif // GLOBAL_H
我在每个导入的函数旁边添加了一个宏
以下是一个例子:
namespace nsKuainRule {
class NormalForm : public AbstractNormalForm, public AbstractObject
{
std::vector <Expression> _expressionNFs;
public:
/**** CONSTRUCTOR & DESTRUCTOR ****/
KUAINRULE_API NormalForm();
KUAINRULE_API ~NormalForm();
/**** OVERRIDE FUNCTIONS ****/
/*!
* \brief Get all expressions from the NF class
* \return Vector of \a Expression objects
*/
KUAINRULE_API std::vector<Expression> &getAllExpr() override;
KUAINRULE_API std::string print() const override;
};
}
发布和调试编译没有错误
之后,我尝试将库连接到一个新项目。 新的Qt控制台应用程序项目已创建。 所有* .h文件都作为现有文件添加到项目中。 我点击了“添加库...”并选择了选项
.pro文件
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += main.cpp
HEADERS += \
abstractnormalform.h \
abstractobject.h \
constituent.h \
defines.h \
expression.h \
global.h \
initkuainrule.h \
kuainrule.h \
normalform.h \
perfectnormalform.h \
shortnormalform.h
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/./ -lkuins_metho
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/./ -lkuins_method
INCLUDEPATH += $$PWD/.
DEPENDPATH += $$PWD/.
所有文件* .a,*。dll,*。h,我已复制到根目录
编译错误:未定义引用...
请帮我解决这个问题。 我做错了什么? 如果您想查看整个项目,请点击链接:https://github.com/OleksandrMyronchuk/minimize-logical-functions
错误:
A:\qtProject\build-del3-Desktop_Qt_5_10_0_MinGW_32bit-Debug\debug\main.o:-1: In function `main':
A:\qtProject\del3\main.cpp:21: error: undefined reference to `_imp___ZN11nsKuainRule13InitKuainRuleD1Ev'
A:\qtProject\del3\main.cpp:21: error: undefined reference to `_imp___ZN11nsKuainRule13InitKuainRuleD1Ev'
collect2.exe:-1: error: error: ld returned 1 exit status
答案 0 :(得分:0)
这是Qt Creator的一个错误。我点击“Build” - &gt;在此之后,“全部清除”错误消失。
谢谢你,Selbie和其他人! 问题解决了