gpt4 book ai didi

c++ - 在 Linux 上构建 Qt 共享库

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

我已按照以下链接中的说明进行操作(以及此处的一些主题) http://qt-project.org/doc/qt-4.8/sharedlibrary.html

我正在成功构建一个项目,但我只看到了通常的对象和编译后的最终二进制文件。一点都不像图书馆。

想法?

MyWidget_global.h

#ifndef MY_WIDGET_GLOBAL_H
#define MY_WIDGET_GLOBAL_H

#include <QtCore/qglobal.h>

#if defined(MY_WIDGET_LIBRARY)
# define MY_WIDGET_EXPORT Q_DECL_EXPORT
#else
# define MY_WIDGET_IMPORT Q_DECL_IMPORT
#endif

#endif

项目文件

DEFINES += MY_WIDGET_LIBRARY

# Input
HEADERS += MyWidget_global.h \
MyWidget.h
# Input
SOURCES += main.cpp \
MyWidget.cpp

最后是实际类的标题

#ifndef MY_WIDGET_H
#define MY_WIDGET_H

#include "MyWidget_global.h"

class MY_WIDGET_EXPORT MyWidget
{
public:
MyWidget();
// Snip
};

#endif

最佳答案

Qt 带有一系列预定义的项目模板。直接来自文档 here :

The TEMPLATE variable is used to define the type of project that will be built. If this is not declared in the project file, qmake assumes that an application should be built, and will generate an appropriate Makefile (or equivalent file) for the purpose.

因此,在您的情况下,QMake 假定要构建一个应用程序。添加正确的模板可以解决问题,即

TEMPLATE = lib

是解决方案。事实上,lib 是为库创建输出 makefile 的正确模板。

参见 here用于正确创建库并将其添加到项目中。

关于c++ - 在 Linux 上构建 Qt 共享库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27195757/

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