我意識到Linux下的應用程序的DLL導出符號:使用Qt的大多爲圖書館無法從那個是完全有效的,否則
- ;
- 由幾個庫和一個主要的gui應用程序組成。
當我正在做我的代碼兼容到Visual Studio 2015年的編譯器我以下DLLEXPORT問題跌跌撞撞(它實際上是一個剪斷代碼):
#include <QVariant>
#include <QList>
class SNIPPEDSHARED_EXPORT Snipped : public QList<QVariant>
{
public:
Snipped();
};
SNIPPEDSHARED_EXPORT是經典:
#if defined(SNIPPED_LIBRARY)
# define SNIPPEDSHARED_EXPORT __declspec(dllexport)
#else
# define SNIPPEDSHARED_EXPORT __declspec(dllimport)
#endif
即碼生成:
C:\Qt\5.7\msvc2015_64\include\QtCore\qhashfunctions.h:110: erreur : C2665: 'qHash': none of the 22 overloads could convert all the argument types
C:\Qt\5.7\msvc2015_64\include\QtCore\qhashfunctions.h:110: erreur : C2056: illegal expression
錯誤信息是不夠明確的,我甚至發現,定義自己的qHash人:
- http://www.qtforum.org/article/19733/qmultihash-qvariant-compiler-error-c2665.html
- qvariant as key in qhash
是什麼困擾着我:
- 我m使用QList而不是qHash直接;我很清楚QList可以在內部使用qHash,但代碼可以順利運行gcc:所以Qt似乎提供了所需的東西;
- 當我建立在一個普通的二進制文件(不是一個庫)的確切類,所有運行完美(無論是Windows或Linux)。
- 當我刪除了
__declspec
,則該庫正在建設完全
我花時間來閱讀,因爲它似乎真正的問題(我甚至花時間閱讀的Qt源代碼(嘿導出模板文檔,其使用顯式模板實例
- :here和here
- 發現了一些歷史位:How to export an instantiation of a Standard Template Library (STL) class and a class that contains a data member that is an STL object 代碼運行:-)))
但是所描述的問題似乎並不適用。我嘗試了所有的組合,但沒有一個是這樣的(這本來就是一種僥倖)。代碼太簡單了,我認爲我錯過了一些基本的東西(對不起:這不是一個真正有意思的問題,而是非常令人討厭)。
有人想法嗎?
P.S:完整的技術數據:
- 的Visual Studio 2015年社區版,與上次更新:14.0.25424。00更新3
- 的Visual C++ 2015年00322-20000-00000-AA285
- 使用Windows套件10:通過QtCreator
snipped.pro
QT -= gui TARGET = snipped TEMPLATE = lib DEFINES += SNIPPED_LIBRARY SOURCES += snipped.cpp
10.0.10586.0
- 建立一個庫項目
snipped.cpp
#include "snipped.h" #include <QDebug> Snipped::Snipped() { qDebug("Coucou !");/*some code is required otherwise the build will generate nothing*/ }
剪斷.H
#ifndef SNIPPED_H #define SNIPPED_H #include "snipped_global.h" #include <QVariant> #include <QList> class SNIPPEDSHARED_EXPORT Snipped : public QList<QVariant> { public: Snipped(); }; #endif // SNIPPED_H
snipped_global.h
#ifndef SNIPPED_GLOBAL_H #define SNIPPED_GLOBAL_H #include <QtCore/qglobal.h> #if defined(SNIPPED_LIBRARY) # define SNIPPEDSHARED_EXPORT __declspec(dllexport) #else # define SNIPPEDSHARED_EXPORT __declspec(dllimport) #endif #endif // SNIPPED_GLOBAL_H
已解決。 解釋在原始問題中。 – lemmel
您可以從問題中刪除答案,並將其作爲單獨的答案創建嗎?注意:回答你自己的問題是完全可以接受的 - 事實上它是被鼓勵的。 –