Reputation: 943
I tried to use include an own library in my Qt application.
The problem is that when I compile the application I get the following Linker-error:
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)" (??0?$_String_val@U?$_Simple_types@D@std@@@std@@QAE@XZ) 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)" (?_Myptr@?$_String_val@U?$_Simple_types@D@std@@@std@@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 " (?_Myptr@?$_String_val@U?$_Simple_types@D@std@@@std@@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)" (??1?$_String_val@U?$_Simple_types@D@std@@@std@@QAE@XZ) already defined in moc_mainwindow.obj
debug\qtQT.exe : fatal error LNK1169: one or more multiply defined symbols found
I compile using Visual Studio 2013 32 Bit and I have Qt 5.3.2 using Qt Creator 3.2.1.
This problem only occurs when I add a widget to the Qt application. I have tried various MSVC linker options without success. Most notably I have tried these /MT
and /MD
options. A problem there is that my libary uses other libraries for which I do not know how they were compiled.
Any ideas on how to fix this?
EDIT: As requested here is the mainwindow.h. It is the default header which Qt creator creates when you make a new main window (I just deleted the empty lines to save some space on 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
Upvotes: 1
Views: 490
Reputation: 1807
You link in the code of your library twice. I guess you added this library both implicitly (with VS depends on dialog) and explicitly (with command line additions) or something like this.
Or even more probably you put implementations of these functions in a header file outside of class definition and with no 'inline' keyword. Move you definitions to .cpp file then.
Upvotes: 1