PDA

View Full Version : Linking Error when Creating DLL with Visual Studio



stretchtiberius
9th February 2009, 17:56
I am trying to create a windows library with Qt using Visual Studio 2008. To test this I used one of the very simple example programs for the Qt Tutorial. If I compile as a executable it will compile. However, under the same settings except creating a dll I receive the following error amongst others.

error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QApplication::~QApplication(void)" (__imp_??1QApplication@@UAE@XZ) referenced in function _main
I have search the Internet for a solution but haven't had any success. Let me know what you think. Also, I would be happy to provide additional information as needed. Note that Qt was statically compiled.

faldzip
9th February 2009, 18:28
executable is not the same as library. In your error, there's something about main() finction, so i can't imagine how this can work (main() function in dll?). Ok, there's something like DLLMain() in Windows, but I think it is not the case here. Try looking for some shared library creating tutorial, cause it's different than normal executable and it's not weird for me that this dont want to compile. You can use Qt Creator project template for creating library to see how it looks like. To run it you must have than other project which uses this library and compiled as an executable.

talk2amulya
10th February 2009, 08:47
hi,

there is never a main function in a dll file... u can NEVER run a dll file, but only executable..remove the main function.

stretchtiberius
10th February 2009, 14:32
Thank you for your help. That all makes since to me. However, the following code should be acceptable right?

int test()
{
int argc = 1;
char *arg[] = {"test"};
QApplication app(argc, argv);
QPushButton quit("Quit");
quit.resize(75, 30);
quit.setFont(QFont("Times", 18, QFont::Bold));
QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit()));
quit.show();
return app.exec();
}
I tried Qt Creator and this code did compile. However, when I run the project with Visual Studio (converting with qmake -t vclib), I receive the same linking errors. Another interesting discover is that if I point Qt Creator to the Qt files it came with, a .dll is produced. If I point it to the Qt files I compiled I only get a .lib file. Why is that? In any case I really need to be able to compile with Visual Studio. I have also discovered that a the above function will compile with Visual Studio if I make the function static. Naturally this also will not do. Any more ideas?

talk2amulya
10th February 2009, 17:52
I think u r doing it wrong..QApplication and QCoreApplication are only used in executables..when u r creating a dll or lib, u dont use them..I'd suggest u make two projects in Visual studio..one u set as a startup project which will produce an exe, in there, u create a QApplication..in other project u create a dll and u use it with the exe

stretchtiberius
10th February 2009, 18:55
Actually, really what I would like to do is create a dll from C++ containing the GUI and have a Java backend load the GUI via JNI. It would be great to keep all the Qt stuff in C++.

talk2amulya
10th February 2009, 19:31
then why r u tyring all that.. u should go ahead and create a container and put all the gui in it..export it..if u wanna see how its all going..u'll hv to create an exe and use QApplication..when u hv all u want..remove the main function part..create a dll out of all that and use JNI..i dont think it'll be a big issue