PDA

View Full Version : Creating a dll file under windows



schall_l
27th March 2008, 18:36
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


TEMPLATE = lib
CONFIG += dll qt thread

# DEFINES only for Windows
win32 {
CONFIG(dll) {
DEFINES += BUILD_DLL
}
}

# Input
HEADERS += src/qtestdll.h
SOURCES += src/qtestdll.cpp

qtestdll.h

#ifndef QTTESTDLL_H
#define QTTESTDLL_H

#ifdef BUILD_DLL
#define EXPORT_DLL Q_DECL_EXPORT // for Windows
#else
#define EXPORT_DLL
#endif

#include <QtGui>
#include <QObject>

class EXPORT_DLL myTestLib : public QObject {
Q_OBJECT
public:
myTestLib() {};
~myTestLib(){};
void printOut();
};
#endif


qtestdll.cpp

#include "qtestdll.h"

void myTestLib::printOut() {
QMessageBox::information (
NULL,
QObject::tr("Yeahh"),
QObject::tr("This message box comes"
" from my dynamic library") );
}

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

spud
27th March 2008, 18:52
Nothing wrong with the code you've posted:

1>------ Build started: Project: dll_test, Configuration: Debug Win32 ------
1>MOC src\qtestdll.h
1>Compiling...
1>moc_qtestdll.cpp
1>qtestdll.cpp
1>Generating Code...
1>Linking...
1> Creating library debug\dll_test.lib and object debug\dll_test.exp
1>Embedding manifest...
1>Build Time 0:11
1>Build log was saved at "file://c:\...\BuildLog.htm"
1>dll_test - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

The following line tells me you are using a different .pro file:

1> Creating library ..\..\libs\dll_test.lib and object ..\..\libs\dll_test.exp
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.

schall_l
27th March 2008, 19:28
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.

spud
28th March 2008, 11:55
So did the problem go away? The attached example works for me.