我试图在我的Qt应用程序中使用包含自己的库。使用自己的库编译Qt GUI时的链接器错误
的问题是,当我编译我得到下面的连接错误的应用:
MyTestLib_debug.lib(MyTestLib_debug.dll) : error LNK2005: "public: __thiscall std::_String_val<struct std::_Simple_types<char> >::_String_val<struct std::_Simple_types<char> >(void)" ([email protected][email protected]@[email protected]@@[email protected]@[email protected]) already defined in moc_mainwindow.obj
MyTestLib_debug.lib(MyTestLib_debug.dll) : error LNK2005: "public: char * __thiscall std::_String_val<struct std::_Simple_types<char> >::_Myptr(void)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@QAEPADXZ) already defined in moc_mainwindow.obj
MyTestLib_debug.lib(MyTestLib_debug.dll) : error LNK2005: "public: char const * __thiscall std::_String_val<struct std::_Simple_types<char> >::_Myptr(void)const " ([email protected][email protected][email protected]@[email protected]@@[email protected]@QBEPBDXZ) already defined in moc_mainwindow.obj
MyTestLib_debug.lib(MyTestLib_debug.dll) : error LNK2005: "public: __thiscall std::_String_val<struct std::_Simple_types<char> >::~_String_val<struct std::_Simple_types<char> >(void)" ([email protected][email protected]@[email protected]@@[email protected]@[email protected]) already defined in moc_mainwindow.obj
debug\qtQT.exe : fatal error LNK1169: one or more multiply defined symbols found
我编译使用Visual Studio 2013 32位和我的Qt 5.3.2使用Qt Creator的3.2.1。 只有在向Qt应用程序添加小部件时才会出现此问题。我已经尝试过各种MSVC链接器选项,但没有成功。最值得注意的是我尝试了这些/MT
和/MD
选项。有一个问题,就是我的库文库使用其他库,我不知道它们是如何编译的。
有关如何解决此问题的任何想法?
编辑: 按照要求这里是mainwindow.h。这是Qt创建者创建新主窗口时创建的默认标题(我刚刚删除了空行以在SO上节省一些空间)。
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
向我们展示您的'mainwindow'标题。 – cmannett85 2014-10-06 13:26:09
我不是mvsc的专家,但我想如果你插入了你使用过的编译和链接选项,并尝试在你的问题中,这将是一件好事。 – Theolodis 2014-10-06 13:27:03