Simultaneously use of Itk and Elastix in Visual Studio

173 views
Skip to first unread message

maryam nasr

unread,
Sep 30, 2021, 3:04:28 AM9/30/21
to elastix-imageregistration
Hi Everyone

I am a new user to Elastix. I want to use elastix and itk in my c++ code (visual studio 2015). I built ITK 2.5.0 and elastix (with cmake & VS2015), then include their header files to my project. While I just use elastix, every thing works fine. But when I use itk functions (for example to read images), I get these errors:

LNK2001 unresolved external symbol gethostbyname (itksys-5.2.lib(SystemInformation.obj))
LNK2001 unresolved external symbol gethostname (itksys-5.2.lib(SystemInformation.obj))
LNK2001 unresolved external symbol gethostname (itkgdcmCommon-5.2.lib(gdcmSystem.obj))
LNK2001 unresolved external symbol WSAStartup (itksys-5.2.lib(SystemInformation.obj))
LNK2001 unresolved external symbol WSAStartup (itkgdcmCommon-5.2.lib(gdcmSystem.obj))
LNK2001 unresolved external symbol WSACleanup (itksys-5.2.lib(SystemInformation.obj))
LNK2001 unresolved external symbol WSACleanup (itkgdcmCommon-5.2.lib(gdcmSystem.obj))
LNK2001 unresolved external symbol GetProcessMemoryInfo (itkgdcmCommon-5.2.lib(gdcmSystem.obj))
LNK2001 unresolved external symbol __imp_SymGetLineFromAddr64 (itksys-5.2.lib(SystemInformation.obj))
LNK2001 unresolved external symbol __imp_SymInitialize (itksys-5.2.lib(SystemInformation.obj))
LNK2001 unresolved external symbol __imp_SymFromAddr (itksys-5.2.lib(SystemInformation.obj))
LNK2001 unresolved external symbol __imp_UuidCreate (itkgdcmMSFF-5.2.lib(gdcmUIDGenerator.obj))

I appreciate  if you could help me.
Thanks in advance.

Best Regards 
Maryam

Niels Dekker

unread,
Sep 30, 2021, 3:54:07 AM9/30/21
to elastix-imageregistration
Hi Maryam,

Thank you for your post. I did encounter similar error messages in the past, with some other libraries. It appears that on Windows, you may need to add some  target_link_libraries to your CMakeLists.txt for some Windows specific libraries. Please try the following:

target_link_libraries( <your-executable-or-library-target-name>
    Ws2_32.lib  # For  gethostbyname, WSACleanup, etc
     Dbghelp.lib  #  For SymGetLineFromAddr64, etc
     Rpcrt4.lib  # For UuidCreate
)

The target_link_libraries call must be placed after your add_library or add_executable call.

Hope that helps, Niels

Niels Dekker

unread,
Sep 30, 2021, 5:58:59 AM9/30/21
to elastix-imageregistration
P.S. You wrote: "I built ITK 2.5.0 and elastix (with cmake & VS2015)".

I assume you mean ITK 5.2.0, right? ITK 5.2.0 still supports VS2015, but ITK 5.3.0 will require at least VS2017. Would it be possible for you to upgrade your Visual Studio to either VS2017 or VS2019? Otherwise I guess you would have to stick with ITK 5.2.

maryam nasr

unread,
Sep 30, 2021, 8:27:44 AM9/30/21
to elastix-imageregistration
Hi Neils,
Thanks for your help.
Yes I mean ITK 5.2.0.
I add the *.lib files you said (and psapi.lib for GetProcessMemoryInfo) to properties  > linker > input > additional dependencies. It works and there is no error after building.
 But now there is a runtime error. I read images with ITK and parameter file with Elastix. Then I use the following code to start registration:
registration.RegisterImages(fix_image, move_image, param, save_path , 0, 0);

But It does not work because of this error:
the code execution cannot proceed because ANNlib-5.0.dll was not found.

I would be grateful if you could help me.

Niels Dekker

unread,
Sep 30, 2021, 10:31:24 AM9/30/21
to elastix-imageregistration
Hi Maryam,

Glad to hear your build errors are fixed now  :-)

You wrote: "I add the *.lib files you said (and psapi.lib for GetProcessMemoryInfo) to properties  > linker > input > additional dependencies. It works and there is no error after building"

Do you have a CMakeLists.txt for your own application (executable)?  Then the changes you made by Visual Studio properties  > ... > additional dependencies may be reset, the next time you run CMake. If that happens, you may still need to solve the problem by target_link_librarie, as I suggested.

"...the code execution cannot proceed because ANNlib-5.0.dll was not found".

Do you have ANNlib-5.0.dll somewhere on your harddisk? For example at <elastix-build-directory>\bin\Release  ?  If so, then you may either copy ANNlib-5.0.dll to the same directory as your executable, OR make sure that the directory of  ANNlib-5.0.dll  is in your path (Windows set PATH).

Hope that helps, Niels

maryam nasr

unread,
Oct 2, 2021, 3:14:18 AM10/2/21
to elastix-imageregistration
Hi Neils, 

To be honest, I am a beginner with cmake. I don't know what is the  target name in "target_link_libraries" and how should I use "add_executable"  or "add_library".  I just use Elastix cmakeList.txt to create elastix.sln file, then build this project to create *.h and *.lib files.  

" make sure that the directory of  ANNlib-5.0.dll  is in your path (Windows set PATH)": It was the solution. :)

Thanks so much for these helpful answers, they save me a lot of time.

Wish you bests :)
Maryam

Niels Dekker

unread,
Oct 2, 2021, 10:22:41 AM10/2/21
to elastix-imageregistration
You're welcome Maryam! It's also OK if you edit the compilation settings of your own project directly in Visual Studio, and just use CMake for elastix and ITK. Especially when you only need to support Visual Studio + Windows. As long as it works, it should be fine  :-)

Kind regards, Niels
Reply all
Reply to author
Forward
0 new messages