Qt-interest Archive, April 2007
How to use build and link qt dll using Vistual Studio 2005?
Message 1 in thread
I just want to build a library where containts some Class and a app use
those class in the library.
under *nix, i create two .pro file manualy for lib and app seperatly and
use qmake and gnu make to build them, they all works fine.
also On Windows 2003 server platform, the vs2005 only output .dll for
me, when i lets the app to link with the dll, the compiler
output error such as fatal error LNK1107 etc. the content of source code
and pro file and error list below, who can give a tutor
about how to export class from library and link them with app, the
contents of test code and pro file and error report list below,
addtest.h and addtest.cpp will build in LibTest.dll by LibTest.pro
and main.cpp will build in AppTest.exe by AppTest.pro
Thanks !
1.E:\PlatformTest\qtvs2005test\LibTest\addtest.h
class AddTest{
public:
AddTest();
int GetResult();
};
2.E:\PlatformTest\qtvs2005test\LibTest\addtest.cpp
#include "addtest.h"
AddTest::AddTest(){
}
int AddTest::GetResult(){
return 1000;
}
3. E:\PlatformTest\qtvs2005test\AppTest\main.cpp
#include "../LibTest/addtest.h"
#include <iostream>
int main()
{
AddTest a;
std::cout<<a.GetResult()<<std::endl;
}
4.E:\PlatformTest\qtvs2005test\LibTest\LibTest.pro
command line for LibTest.pro: qmake -project -t vclib
######################################################################
# Automatically generated by qmake (2.01a) ??? ?? 31 10:10:03 2007
######################################################################
TEMPLATE = vclib
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
HEADERS += addtest.h
SOURCES += addtest.cpp
5.E:\PlatformTest\qtvs2005test\LibTest\AppTest.pro
command line qmake -project -t vcapp
######################################################################
# Automatically generated by qmake (2.01a) ??? ?? 31 10:13:19 2007
######################################################################
TEMPLATE = vcapp
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
CONFIG += console
LIBS += E:\PlatformTest\qtvs2005test\LibTest\debug\LibTest.dll
CONFIG += embed_manifest_exe
# Input
HEADERS += ../LibTest/addtest.h
SOURCES += main.cpp
6. dll build report
------ Build started: Project: LibTest, Configuration: Debug Win32 ------
Compiling...
addtest.cpp
Linking...
LINK : debug\LibTest.dll not found or not built by the last incremental
link; performing full link
Embedding manifest...
Build log was saved at
"file://e:\PlatformTest\qtvs2005test\LibTest\debug\BuildLog.htm"
LibTest - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
7. app build report
------ Build started: Project: AppTest, Configuration: Debug Win32 ------
Linking...
E:\PlatformTest\qtvs2005test\LibTest\debug\LibTest.dll : fatal error
LNK1107: invalid or corrupt file: cannot read at 0x2C8
Build log was saved at
"file://e:\PlatformTest\qtvs2005test\AppTest\debug\BuildLog.htm"
AppTest - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
--
[ signature omitted ]
Message 2 in thread
postbeerliu wrote:
> 7. app build report
> ------ Build started: Project: AppTest, Configuration: Debug Win32 ------
> Linking...
> E:\PlatformTest\qtvs2005test\LibTest\debug\LibTest.dll : fatal error
> LNK1107: invalid or corrupt file: cannot read at 0x2C8
> Build log was saved at
> "file://e:\PlatformTest\qtvs2005test\AppTest\debug\BuildLog.htm"
> AppTest - 1 error(s), 0 warning(s)
> ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
>
Hi there,
if I understand you right you tried to link to a DLL, but it is usually a better idea to
link to the corresponding .lib
Hope this helps
--
[ signature omitted ]