1

This is not a new question but the solutions haven't worked for me. I want to read dicom files using C++. I have 32-bit Windows PC with VS 2013 community edition.

This post and other answers therein suggested using DCMTK. I installed DCMTK (using CMake followed by VS) and configured it for use with VS using guidelines and links provided in this post. Then I wrote a simple test program and tried to compile it:

#include "stdafx.h"
#include "dcmtk\dcmdata\dctk.h"
#include "dcmtk\config\osconfig.h"
#include "dcmtk\dcmimgle\dcmimage.h"
#include <iostream>
using namespace std;

int main()
{
    DicomImage *image = new DicomImage("test.dcm");
    if (image != NULL)
    {
        if (image->getStatus() == EIS_Normal)
        {
            if (image->isMonochrome())
            {
                image->setMinMaxWindow();
                Uint8 *pixelData = (Uint8 *)(image->getOutputData(8 /* bits */));
                if (pixelData != NULL)
                {
                    /* do something useful with the pixel data */
                }
            }
        }
        else
            cerr << "Error: cannot load DICOM image (" << DicomImage::getString(image->getStatus()) << ")" << endl;
    }
    delete image; 
    return 0;
}

Upon compilation, it gives the following error:

dcmdata.lib(dcuid.obj) : error LNK2019: unresolved external symbol _Netbios@4 referenced in function "unsigned char * __cdecl getMACAddress(unsigned char * const)" (?getMACAddress@@YAPAEQAE@Z)

This error seems to be common but none of the following solutions work for me:

  1. FAQ#27 and another post of DCMTK forum: It suggests using particular order of lib files to be included. My order of including files is as follows (I tried the reverse order as well but it didn't work):

    enter image description here

All of this doesn't work. In fact, I'm not sure which lib files are supposed to be included? How to decide that?

I've also included "C:\Program Files\DCMTK\lib" under additional library directories and "C:\Program Files\DCMTK\include" under additional include directories in project properties.

  1. Another similar question at stackoverflow has not been answered. Comments suggest to re-run CMake by disabling DCMTK_OVERWRITE_WIN32_COMPILER_FLAGS. I didn't do it because the DCMTK help page says don't disable this unless you really know what you're doing.

Can someone please guide?

Community
  • 1
  • 1
Ruchir
  • 845
  • 2
  • 10
  • 24

6 Answers6

1

I had the same error. You can go to project properties-> linker -> input -> Additional Dependencies-> Edit -> add these two libraries-( netapi32.lib,wsock32.lib) before all other libraries . This solved the error for me .

0

The NetBios function resides in NETAPI32.LIB, so you can try moving NetAPI32.lib (which is in your list) to the top of that list.

Zuppa
  • 467
  • 5
  • 16
0

Not sure which version of the DCMTK you use, but for the current development snapshot you need the following standard libraries (on Windows): "ws2_32 netapi32 wsock32". This information can be found in DCMTK's CMake files. By the way, you don't seem to use CMake for your project, right?

J. Riesmeier
  • 1,641
  • 10
  • 14
  • I use DCMTK 3.6.0 and I am using CMake. I tried including ws2_32 as well but it still doesn't work. (I looked into CmakeLists.txt to find this information, thanks.) – Ruchir Nov 23 '16 at 10:08
0

I think you misspelled dcmsign.lib as dcmsig.lib.

If changing that doesn't fix it, I would suggest the following order based on the support page that you linked to: NetAPI32.lib WSock32.lib ofstd.lib oflog.lib dcmdata.lib dcmsign.lib dcmnet.lib dcmsr.lib dcmqrdb.lib dcmtls.lib dcmwlm.lib dcmimgle.lib dcmpstat.lib dcmjpls.lib dcmjpeg.lib dcmimage.lib ijg16.lib ijg12.lib ijg8.lib

I think that in this list, each library has to come after all the libraries that it depends on.

  • In fact, I don't have any such file, dcmsign.lib. Instead I have dcmdsig.lib which is what I've mentioned. I also tried the order you've suggested and also included ws2_32.lib as suggested by @J. Riesmeier but it still doesn't work. For the order I followed this post: http://stackoverflow.com/a/798086/5022962 but it seems to suggest the other way (as compared to what you say). I'm not sure which one is the correct so I've tried the reverse order as well but it doesn't work. – Ruchir Nov 23 '16 at 10:17
  • 1
    Yes, the library name is actually "dcmdsig.lib", i.e. not identical to the name of DCMTK's module directory because of conflicts with the command line tool "dcmsign". Regarding the library order: as far as I know, Visual Studio is not that picky about it as gcc (or its linker) is. @ruchir Did you already enable the verbose mode of your linker? – J. Riesmeier Nov 23 '16 at 11:05
  • @J.Riesmeier I've now enabled the verbose mode. Now I see over 3000 lines of output. Can this be used to locate the source of error? – Ruchir Nov 24 '16 at 01:56
  • @Ruchir Usually, yes. That's why I recommended it :) In the verbose output of the linker, you should be able to see which libraries are linked to your program from which directories, and of course, more details on your linker error. As you've said: the output is quite verbose, so you either need some experience or some patience in order to find the relevant lines. – J. Riesmeier Nov 24 '16 at 10:18
0

check your .lib and vs platform if the same ,such lib for x64, then your vs platform must be x64.

0

I resolved this error by adding the additional dependency iphlpapi.lib in

Project Properties-> Linker -> Input -> Additional Dependencies-> Edit -> add iphlpapi.lib

He3lixxx
  • 3,263
  • 1
  • 12
  • 31