我对QTCreator很新。我在Visual Studio中使用Dcmtk库创建了一个小程序,现在我正在尝试使用GUI来实现这一点,为此我尝试在QTCreator中创建相同的程序,以便我可以添加该GUI功能。但是当我尝试将头文件和.lib文件添加到QTCreator时会出现问题。在Visual Studio中执行该程序时,我添加了以下库库:
dcmdata.lib
oflog.lib
ofstd.lib
ws2_32.lib
netapi32.lib
使用调试模式的库目录:
D:\dcmtk-3.6.0\Lib files\Debug;
和发布模式是
D:\dcmtk-3.6.0\Lib files\Release;
为了在Visual Studio中添加头文件,我将include目录放在:
D:\dcmtk-3.6.0\Prefix Files\include;
因此,对于.pro文件中的QTCreator,我编辑并添加了lib文件和头文件目录,并指出了我需要的lib文件和.pro文件如下所示:
#-------------------------------------------------
#
# Project created by QtCreator 2013-05-02T10:59:41
#
#-------------------------------------------------
QT += core#adding the core framework
QT -= gui#removing the gui portion
TARGET = untitled#targetting the project
CONFIG += console#defining that it is console application
CONFIG -= app_bundle#
TEMPLATE = app
SOURCES += main.cpp#adding the main.cpp as source file
LIBS +="D:/dcmtk-3.6.0/Lib files/Release"
-ldcmdata\
-loflog\
-lofstd\
-lws2_32\
-lnetapi32\
-wsock32\
LIBS +="D:/dcmtk-3.6.0/Lib files/Debug"
-ldcmdata\
-loflog\
-lofstd\
-lws2_32\
-lnetapi32\
-lwsock32\
INCLUDEPATH += "D:/dcmtk-3.6.0/Prefix Files/include"
我还没有开始编程,但我只是使用#include指令添加了头文件的名称,代码如下:
#include <QCoreApplication>
#include <QDebug>
#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmdata/dctk.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString mystr="Hellow world";
qDebug() <<mystr;
return a.exec();
}
但是当我尝试构建它时会出错。错误如下:
D:\QtFiles\untitled\main.cpp:3: error: C1083: Cannot open include file: '/dcmtk/config/osconfig.h': No such file or directory
在将头文件和lib文件链接到程序时,我似乎犯了一些错误。编程代码中的两行
#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmdata/dctk.h"
在Visual Studio中没有出错,所以我确定它们没有任何问题。你能说我在连接外部头文件和lib文件时犯了什么错误吗?
解决方案:
我更改了.pro文件中将外部链接到以下内容的行,并且它起作用了:
LIBS += -L"D:/dcmtk-3.6.0/Lib files/Release" \
-ldcmdata\
-loflog\
-lofstd\
-lws2_32\
-lnetapi32\
-lwsock32\
LIBS += -L"D:/dcmtk-3.6.0/Lib files/Debug" \
-ldcmdata\
-loflog\
-lofstd\
-lws2_32\
-lnetapi32\
-lwsock32\
INCLUDEPATH += "D:/dcmtk-3.6.0/Prefix Files/include/"
答案 0 :(得分:1)
INCLUDEPATH
-L
LIBS
前缀
\
的路径后忘了LIBS
。CONFIG(debug, debug|release)
所以,你的项目看起来应该是
QT = core
TARGET = untitled#targetting the project
CONFIG += console#defining that it is console application
CONFIG -= app_bundle#
TEMPLATE = app
DCMTK="D:/dcmtk-3.6.0"
DCMTK_LIBS_PREFIX=$$DCMTK"/Lib files"
DCMTK_INCLUDE=$$DCMTK"/Prefix Files/include"
INCLUDEPATH+=$$DCMTK_INCLUDE
SOURCES += main.cpp#adding the main.cpp as source file
CONFIG(debug, debug|release) {
LIBS +=-L$$DCMTK_LIBS_PREFIX/Debug
} else {
LIBS +=-L$$DCMTK_LIBS_PREFIX/Release
}
LIBS+= -ldcmdata -loflog -lofstd -lws2_32 -lnetapi32 -wsock32