简体   繁体   English

如何以与Visual Studio中相同的方式在Qt Creator中生成dll?

[英]How to build dll in Qt creator the same way as in Visual Studio?

I have a project of a DLL in the Visual Studio written on pure C++ and STL. 我在Visual Studio中有一个用纯C ++和STL编写的DLL项目。 I have to migrate to the Qt Creator for adding some of Qt features. 我必须迁移到Qt Creator才能添加一些Qt功能。 For beginning I simply tried to do next steps: 1) Copy sources in a new folder 2) Manually make a .pro file with these sources 3) And add this preferences in .pro file: 首先,我只是尝试执行以下步骤:1)在新文件夹中复制源2)使用这些源手动制作.pro文件3)并在.pro文件中添加此首选项:

  1. TEMPLATE = lib 模板= lib
  2. TARGET = LogonProvider TARGET = LogonProvider
  3. DEFINES -= UNICODE 定义-= UNICODE
  4. DEFINES += LogonProvider_LIBRARY 定义+ = LogonProvider_LIBRARY
  5. CONFIG += dll 配置+ = dll
  6. LIBS += -lsecur32 -ladvapi32 -luser32 -lole32 -lshlwapi LIBS + = -lsecur32 -ladvapi32 -luser32 -lole32 -lshlwapi
  7. #<...> There is list of sources #<...>来源列表

It all seems good and the project has compiled and I get DLL... but DLL doesn't work and have size about 30Kb, when have to have about 1Mb (if I built it with the Visual Studio) As I can understand, linker can't assembly .obj files to DLL, that's why it is reduced (as a result I have much .obj files around my DLL). 一切似乎都很好,项目已经编译并且我得到了DLL ...但是DLL无法正常工作,并且大小大约为30Kb,当必须具有大约1Mb时(如果我是使用Visual Studio构建的),据我所知,链接器无法将.obj文件汇编为DLL,这就是为什么要减少它的原因(因此,我的DLL周围有很多.obj文件)。 But there were no errors or warnings during a linking proces in the Qt Creator. 但是在Qt Creator中的链接过程中没有错误或警告。 I think it is some of Qt options, but what can I do with it? 我认为这是Qt选项的一部分,但是我该怎么办? How can I get the same DLL from Qt as from Visual Studio? 如何从Qt和Visual Studio中获得相同的DLL?

PS. PS。 Sorry for bad english 对不起英语不好

Do you actually add sources and headers to your .pro file? 您是否确实将源文件和标头添加到了.pro文件中?

There are two easy ways to achieve what you want. 有两种简单的方法可以实现您想要的。 You can either create a new blank library project in Qt Creator (File > New File or Project > Libraries > C++ Library) which will setup the .pro file for you, and then add existing sources to the project. 您可以在Qt Creator中创建一个新的空白库项目(“文件”>“新文件”或“项目”>“库”>“ C ++库”),这将为您设置.pro文件,然后将现有源添加到项目中。 Or you can use Qt Visual Studio Add-in to generate the .pro file for you in Visual Studio. 或者,您可以使用Qt Visual Studio加载项在Visual Studio中为您生成.pro文件。

For reference, here is a valid project file for a library: 作为参考,这是一个有效的库项目文件:

QT       -= gui

TARGET = mylib
TEMPLATE = lib

DEFINES += MYLIB_LIBRARY

SOURCES += mylib.cpp

HEADERS += mylib.h\
        mylib_global.h

unix {
    target.path = /usr/lib
    INSTALLS += target
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM