【发布时间】:2020-03-14 08:03:18
【问题描述】:
我正在尝试使用 QT 创建一个共享(动态)c++ 库,但是在将使用此库的客户端应用程序中,不会有任何 qt 库链接。
我已经按照关于 qt 的教程创建了一个 pro 文件和头文件,如下例所示。
专业档案:
QT -= gui
TEMPLATE = lib
CONFIG += dynamiclib
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has 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, MAITSCHSDK_LIBRARY
# You can also make your code fail to compile if it uses 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 += \
maitchsdk.cpp
HEADERS += \
maitchsdk.h
# Default rules for deployment.
unix {
target.path = $$[QT_INSTALL_PLUGINS]/generic
}
!isEmpty(target.path): INSTALLS += target
头文件:
#ifndef MAITCHSDK_H
#define MAITCHSDK_H
#include <QtCore/QtGlobal>
#if defined(MAITSCHSDK_LIBRARY)
# define MAITSCHSDK_EXPORT Q_DECL_EXPORT
#else
# define MAITSCHSDK_EXPORT Q_DECL_IMPORT
#endif
class MAITSCHSDK_EXPORT MAItchSDK
{
public:
MAITSCHSDK_EXPORT MAItchSDK(const char *glimpseIp,int glimpsePort,const char *itchIp,int itchPort);
};
#endif // MAITCHSDK_H
但是当我这样实现它时,头文件包含 qt 依赖项,因此客户端应用程序也需要具有此依赖项,这不是我们想要的。 我的另一个要求是,这个库也可以用 golang 调用(通过使用 cgo)所以我需要用一些 extern "C" 方法为这个库项目创建一个 c 包装器,我浏览了所有文档和教程,但无法找到合适的解决方案。
有人知道如何使用 QT 创建基本的 C 共享库吗?
谢谢
【问题讨论】: