Results 1 to 7 of 7

Thread: Linking Error when Creating DLL with Visual Studio

  1. #1
    Join Date
    Feb 2009
    Posts
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Linking Error when Creating DLL with Visual Studio

    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.

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Linking Error when Creating DLL with Visual Studio

    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.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  3. #3
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Linking Error when Creating DLL with Visual Studio

    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.

  4. #4
    Join Date
    Feb 2009
    Posts
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: Linking Error when Creating DLL with Visual Studio

    Thank you for your help. That all makes since to me. However, the following code should be acceptable right?
    Qt Code:
    1. int test()
    2. {
    3. int argc = 1;
    4. char *arg[] = {"test"};
    5. QApplication app(argc, argv);
    6. QPushButton quit("Quit");
    7. quit.resize(75, 30);
    8. quit.setFont(QFont("Times", 18, QFont::Bold));
    9. QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit()));
    10. quit.show();
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 
    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?

  5. #5
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Linking Error when Creating DLL with Visual Studio

    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

  6. #6
    Join Date
    Feb 2009
    Posts
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Linking Error when Creating DLL with Visual Studio

    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++.

  7. #7
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Linking Error when Creating DLL with Visual Studio

    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

Similar Threads

  1. Qt 4.4.1 Compile Error with MS Visual C++ 2008 Express SP1
    By BrainB0ne in forum Installation and Deployment
    Replies: 3
    Last Post: 19th August 2008, 15:49
  2. qtgui4.dll error in visual c++ 2005
    By Comptrol in forum Installation and Deployment
    Replies: 33
    Last Post: 19th June 2008, 07:18
  3. Qt configure with msvc.net
    By jivanr in forum Installation and Deployment
    Replies: 1
    Last Post: 11th June 2007, 08:17
  4. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 13:15
  5. problem with linking
    By mickey in forum Qt Programming
    Replies: 49
    Last Post: 12th August 2006, 21:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.