Results 1 to 4 of 4

Thread: Creating a dll file under windows

  1. #1
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Creating a dll file under windows

    Hello,

    I am trying to create a simple dll containing some qt code.
    I thought that this would be easy, but somehow I am getting a compiler error telling me:

    1>------ Build started: Project: dll_test, Configuration: Debug Win32 ------
    1>Compiling...
    1>moc_qtestdll.cpp
    1>qtestdll.cpp
    1>Generating Code...
    1>Linking...
    1> Creating library ..\..\libs\dll_test.lib and object ..\..\libs\dll_test.exp
    1>qtmaind.lib(qtmain_win.obj) : error LNK2019: unresolved external symbol _main referenced in function _WinMain@16
    1>..\..\libs\dll_test.exe : fatal error LNK1120: 1 unresolved externals
    1>Build log was saved at "file://c:\tmp\project\lab\dll_test\debug\BuildLog.htm"
    1>dll_test - 2 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


    It looks like that my Visual C++ compiler is trying to compile this as an apllication.

    This is my code:

    dll_test.pro

    Qt Code:
    1. TEMPLATE = lib
    2. CONFIG += dll qt thread
    3.  
    4. # DEFINES only for Windows
    5. win32 {
    6. CONFIG(dll) {
    7. DEFINES += BUILD_DLL
    8. }
    9. }
    10.  
    11. # Input
    12. HEADERS += src/qtestdll.h
    13. SOURCES += src/qtestdll.cpp
    To copy to clipboard, switch view to plain text mode 

    qtestdll.h
    Qt Code:
    1. #ifndef QTTESTDLL_H
    2. #define QTTESTDLL_H
    3.  
    4. #ifdef BUILD_DLL
    5. #define EXPORT_DLL Q_DECL_EXPORT // for Windows
    6. #else
    7. #define EXPORT_DLL
    8. #endif
    9.  
    10. #include <QtGui>
    11. #include <QObject>
    12.  
    13. class EXPORT_DLL myTestLib : public QObject {
    14. Q_OBJECT
    15. public:
    16. myTestLib() {};
    17. ~myTestLib(){};
    18. void printOut();
    19. };
    20. #endif
    To copy to clipboard, switch view to plain text mode 

    qtestdll.cpp
    Qt Code:
    1. #include "qtestdll.h"
    2.  
    3. void myTestLib::printOut() {
    4. QMessageBox::information (
    5. NULL,
    6. QObject::tr("Yeahh"),
    7. QObject::tr("This message box comes"
    8. " from my dynamic library") );
    9. }
    To copy to clipboard, switch view to plain text mode 

    As usual I did qmake dll_test.pro and qmake -t vcapp to generate the Makefile and the Visual Studio project.

    If anyone has an idea...

  2. #2
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating a dll file under windows

    Nothing wrong with the code you've posted:
    Qt Code:
    1. 1>------ Build started: Project: dll_test, Configuration: Debug Win32 ------
    2. 1>MOC src\qtestdll.h
    3. 1>Compiling...
    4. 1>moc_qtestdll.cpp
    5. 1>qtestdll.cpp
    6. 1>Generating Code...
    7. 1>Linking...
    8. 1> Creating library debug\dll_test.lib and object debug\dll_test.exp
    9. 1>Embedding manifest...
    10. 1>Build Time 0:11
    11. 1>Build log was saved at "file://c:\...\BuildLog.htm"
    12. 1>dll_test - 0 error(s), 0 warning(s)
    13. ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
    To copy to clipboard, switch view to plain text mode 

    The following line tells me you are using a different .pro file:
    Qt Code:
    1. 1> Creating library ..\..\libs\dll_test.lib and object ..\..\libs\dll_test.exp
    To copy to clipboard, switch view to plain text mode 
    Why don't you post a minimal compilable example in a zip archive which we can just compile and run? Then we don't have to do the copy and paste, and we are sure to both test the same version.

  3. #3
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Creating a dll file under windows

    Yes, your're right.
    I removed the following line from the .pro file: DESTDIR=$$(CPPLIBS)

    I have attached the zip archive from the dll_test directory.
    Attached Files Attached Files

  4. #4
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating a dll file under windows

    So did the problem go away? The attached example works for me.

Similar Threads

  1. Set up the Qt4.3.2 with Visual Studio 2005
    By lamoda in forum Installation and Deployment
    Replies: 6
    Last Post: 30th January 2008, 06:51
  2. file renaming on windows
    By jdd81 in forum Qt Programming
    Replies: 9
    Last Post: 2nd October 2007, 19:41
  3. Draging a non-existing file to the Windows Desktop
    By klaus1111 in forum Qt Programming
    Replies: 13
    Last Post: 20th September 2007, 11:47
  4. Replies: 3
    Last Post: 4th September 2007, 14:40
  5. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21

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
  •  
Qt is a trademark of The Qt Company.