如何在Visual Studio系列中自己解决错误LNK2019

时间:2018-04-03 14:25:24

标签: lnk2019 dcmtk

在我的dcmtk学习期间,我遇到了数百个错误“LNK2019”。每次我只能谷歌搜索,搜索有人告诉我应该添加哪个库。我想知道我是否能找到自己需要的lib。

我的工作IDE是Visual Studio 2015,今天的代码如下。

#include <dcmtk\config\osconfig.h>
#include <dcmtk\dcmdata\dcdatset.h>
#include <dcmtk\dcmdata\dctk.h>
#include <dcmtk\dcmjpeg\djcodecd.h>
#include <dcmtk\dcmjpls\djdecode.h>
#include <dcmtk\dcmjpeg\djdecode.h>



int main() {
    DJDecoderRegistration::registerCodecs(); // register JPEG codecs
    DcmFileFormat fileformat;
    if (fileformat.loadFile("1").good())
    {
        DcmDataset *dataset = fileformat.getDataset();
        // decompress data set if compressed
        dataset->chooseRepresentation(EXS_LittleEndianExplicit, NULL);
        // check if everything went well
        if (dataset->canWriteXfer(EXS_LittleEndianExplicit))
        {
            fileformat.saveFile("2", EXS_LittleEndianExplicit);
        }
    }
    DJDecoderRegistration::cleanup(); // deregister JPEG codecs
    return 0;
}

error in this code this is my additional Linker

实际上这个问题已经解决了,我只是在代码中添加了大量额外的lib。

#pragma comment(lib,"ofstd")
#pragma comment(lib,"dcmdata")
#pragma comment(lib,"dcmtls")
#pragma comment(lib,"dcmnet")
#pragma comment(lib,"dcmqrdb")
#pragma comment(lib,"dcmimgle")
#pragma comment(lib,"dcmimage")
#pragma comment(lib,"dcmjpeg")
#pragma comment(lib,"ijg8")
#pragma comment(lib,"ijg12")
#pragma comment(lib,"ijg16")
#pragma comment(lib,"dcmdsig")
#pragma comment(lib,"dcmsr")
#pragma comment(lib,"dcmpstat")
#pragma comment(lib,"dcmwlm")
#pragma comment(lib,"netapi32")
#pragma comment(lib,"wsock32")

我曾经发现有人在stackoverflow中提出了一个方法来解决这个问题。但是他的方法是使用bash或Visual Studio无法做的其他事情。所以这就是我在这里寻求帮助的原因。谢谢,任何人都可以来帮助!!

1 个答案:

答案 0 :(得分:0)

根据您使用的DCMTK版本以及您的程序包含哪些DCMTK模块,您必须链接所需的DCMTK库。在你的情况下,&#34; ofstd,oflog,dcmdata,dcmimgle,dcmimage,dcmjpeg,ijg8,ijg12,ijg16&#34;将是必需的。

对于DCMTK 3.6.0,有一个图表以图形方式显示依赖关系:https://support.dcmtk.org/redmine/projects/dcmtk/wiki/Modules

另外,常见问题解答#26可能会有所帮助:https://forum.dcmtk.org/viewtopic.php?f=4&t=36

对于较新的DCMTK版本(例如3.6.2或3.6.3),我建议使用CMake Export功能。将DCMTK安装到单独的目录中后,以下CMakeLists.txt文件可用于您的示例程序:

# DCMTK Demo Project

# declare project
PROJECT(DCMTK_DEMO)

# minimum CMake version required
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.3)

# specify DCMTK's (default) installation directory
SET(DCMTK_DIRECTORY "C:/Users/dicom/dcmtk-3.6.3-install" CACHE PATH "Directory where DCMTK library is installed.")

# approach #1: use FIND_PACKAGE() to search for installed DCMTK
#FIND_PACKAGE(DCMTK REQUIRED CONFIG PATHS ${DCMTK_DIRECTORY} NO_DEFAULT_PATH)

# approach #2: include DCMTK's CMake configuration directly
INCLUDE(${DCMTK_DIRECTORY}/cmake/DCMTKConfig.cmake)

# declare include directories
INCLUDE_DIRECTORIES(${DCMTK_INCLUDE_DIRS})

# declare executable and link required libraries
ADD_EXECUTABLE(demo demo.cc)
TARGET_LINK_LIBRARIES(demo ${DCMTK_LIBRARIES})