# error building an external module: cannot open input file 'ITKCommon.lib'

**URL:** https://discourse.itk.org/t/error-building-an-external-module-cannot-open-input-file-itkcommon-lib/1346
**Category:** Engineering
**Tags:** external-module, cmake
**Created:** [October 11, 2018, 2:14pm UTC](https://discourse.itk.org/t/error-building-an-external-module-cannot-open-input-file-itkcommon-lib/1346 "2018-10-11T14:14:57Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![ebennink](https://discourse.itk.org/user_avatar/discourse.itk.org/ebennink/32/527_2.png) [@ebennink](https://discourse.itk.org/u/ebennink)
#### Post date: [October 11, 2018, 2:14pm UTC](https://discourse.itk.org/t/error-building-an-external-module-cannot-open-input-file-itkcommon-lib/1346/1 "2018-10-11T14:14:57Z")

</div>

Dear all,

I am trying to build an external ITK module, but linking the new module to the ITK libraries fails. It appears that CMake added the dependent ITK libraries as ITKCommon.lib and ITKSpatialObjects.lib to the link command, whereas these should have had the ITK version number included, i.e. ITKCommon-4.13.lib and ITKSpatialObjects-4.13.lib.

I am using ITK 4.13, built in Release mode and BUILD\_SHARED\_LIBS=ON. Windows 10, MSVC 2015, CMake version 3.10.2.

My itk-module.cmake looks like:

```
get_filename_component(MY_CURRENT_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
file(READ "${MY_CURRENT_DIR}/README.rst" DOCUMENTATION)

itk_module(IsiToolkitLabelModule
  DEPENDS
    ITKCommon
	ITKSpatialObjects
  DESCRIPTION
    "${DOCUMENTATION}"
  EXCLUDE_FROM_DEFAULT
  ENABLE_SHARED
)

```

Any thoughts on what could go wrong?

Cheers,  
Edwin

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [October 11, 2018, 2:27pm UTC](https://discourse.itk.org/t/error-building-an-external-module-cannot-open-input-file-itkcommon-lib/1346/2 "2018-10-11T14:27:18Z")

</div>

Hi Edwin,

Do `ITKCommon.lib` and `ITKSpatialObjects.lib` have full paths on the link line?

Does the external module have the following code in its top level _CMakeLists.txt_ file?

> <https://github.com/InsightSoftwareConsortium/ITKModuleTemplate/blob/e3c91172b23109e5b41f8c826772c9cf8d7fa77a/%7B%7Bcookiecutter.project_name%7D%7D/CMakeLists.txt#L6-L13>

Thanks,  
Matt

---

<div class="post-metadata">

### Author: ![ebennink](https://discourse.itk.org/user_avatar/discourse.itk.org/ebennink/32/527_2.png) [@ebennink](https://discourse.itk.org/u/ebennink)
#### Post date: [October 11, 2018, 2:38pm UTC](https://discourse.itk.org/t/error-building-an-external-module-cannot-open-input-file-itkcommon-lib/1346/3 "2018-10-11T14:38:39Z")

</div>

Hi Matt,

> Do `ITKCommon.lib` and `ITKSpatialObjects.lib` have full paths on the link line?

No, the link line looks like this:

`C:\PROGRA~2\MICROS~2.0\VC\bin\amd64\link.exe @CMakeFiles\IsiToolkitLabelModule.dir\objects1.rsp /out:D:\develop\isitk-core-new\build\ITK\build\bin\itkIsiToolkitLabelModule-4.13.dll /implib:D:\develop\isitk-core-new\build\ITK\build\lib\itkIsiToolkitLabelModule-4.13.lib /pdb:D:\develop\isitk-core-new\build\ITK\build\bin\itkIsiToolkitLabelModule-4.13.pdb /dll /version:1.0 /machine:x64 /INCREMENTAL:NO ITKCommon.lib ITKSpatialObjects.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:D:\develop\isitk-core-new\build\ITK\build\bin\itkIsiToolkitLabelModule-4.13.dll.manifest`

The compile lines, however, do include the full paths (compiling works).

> Does the external module have the following code in its top level _CMakeLists.txt_ file?

Yes, the CMakeLists.txt file looks like this:

```
cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)
cmake_policy(VERSION 3.10.2)

project(IsiToolkitLabelModule)

if(NOT ITK_SOURCE_DIR)
  find_package(ITK REQUIRED)
  list(APPEND CMAKE_MODULE_PATH ${ITK_CMAKE_DIR})
  include(ITKModuleExternal)
else()
  itk_module_impl()
endif()

```

---

<div class="post-metadata">

### Author: ![jhlegarreta](https://discourse.itk.org/user_avatar/discourse.itk.org/jhlegarreta/32/476_2.png) [@jhlegarreta](https://discourse.itk.org/u/jhlegarreta)
#### Post date: [October 11, 2018, 2:44pm UTC](https://discourse.itk.org/t/error-building-an-external-module-cannot-open-input-file-itkcommon-lib/1346/4 "2018-10-11T14:44:03Z")

</div>

> I am using ITK 4.13, built in Release mode and BUILD\_SHARED\_LIBS=ON.

Is it an issue of mixing dynamic and static linking? If you built ITK with `BUILD_SHARED_LIBS=ON`, then your module should link against the `.dll` files, instead of the `.lib` files.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [October 11, 2018, 2:52pm UTC](https://discourse.itk.org/t/error-building-an-external-module-cannot-open-input-file-itkcommon-lib/1346/5 "2018-10-11T14:52:42Z")

</div>

> [@jhlegarreta](#):
>
> then your module should link against the `.dll` files, instead of the `.lib` files.

I don’t think this is the case. Even when needing to use DLLs, you need to link against their import libraries, `.lib` files.

I remember this problem of missing version number occurring before, but I don’t remember either the cause or the solution ☹

**Edit:** trying a clean build of both ITK and the external module might help.

---

<div class="post-metadata">

### Author: ![ebennink](https://discourse.itk.org/user_avatar/discourse.itk.org/ebennink/32/527_2.png) [@ebennink](https://discourse.itk.org/u/ebennink)
#### Post date: [October 11, 2018, 2:55pm UTC](https://discourse.itk.org/t/error-building-an-external-module-cannot-open-input-file-itkcommon-lib/1346/6 "2018-10-11T14:55:27Z")

</div>

Ok. I will try a clean build of ITK and the module.

---

<div class="post-metadata">

### Author: ![ebennink](https://discourse.itk.org/user_avatar/discourse.itk.org/ebennink/32/527_2.png) [@ebennink](https://discourse.itk.org/u/ebennink)
#### Post date: [October 12, 2018, 2:57pm UTC](https://discourse.itk.org/t/error-building-an-external-module-cannot-open-input-file-itkcommon-lib/1346/7 "2018-10-12T14:57:45Z")

</div>

Now, after a clean build of ITK, something different happened. Both ITK and my external module were build with BUILD\_SHARED\_LIBS=ON, but my external module was statically linked to ITK. The resulting external module library has no dependencies on any ITK shared libraries, such as ITKCommon-4.13.dll, whereas the internal ITK module libraries do have these dependencies.  
FYI: I also built SimpleITK and those libraries DO depend on the ITK shared libraries.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [October 12, 2018, 3:50pm UTC](https://discourse.itk.org/t/error-building-an-external-module-cannot-open-input-file-itkcommon-lib/1346/8 "2018-10-12T15:50:00Z")

</div>

> [@ebennink](#):
>
> The resulting external module library has no dependencies on any ITK shared libraries

Why do you think this? Have you examined the external module’s DLLs using [Dependency Walker](http://www.dependencywalker.com/)?

---

<div class="post-metadata">

### Author: ![ebennink](https://discourse.itk.org/user_avatar/discourse.itk.org/ebennink/32/527_2.png) [@ebennink](https://discourse.itk.org/u/ebennink)
#### Post date: [October 13, 2018, 10:11am UTC](https://discourse.itk.org/t/error-building-an-external-module-cannot-open-input-file-itkcommon-lib/1346/9 "2018-10-13T10:11:26Z")

</div>

Hi Dzenan,  
Yes, I indeed used Dependency Walker to check it because the build output doesn’t show the full link command when there are no errors.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [October 13, 2018, 2:16pm UTC](https://discourse.itk.org/t/error-building-an-external-module-cannot-open-input-file-itkcommon-lib/1346/10 "2018-10-13T14:16:41Z")

</div>

Is your external module’s library big, file size wise? Does it appear as a static or dynamic library (.lib or .lib+.dll)? Have you tried linking a simple application to it and invoking some function, .e.g construct a class from the library? Does that work?

**Edit:** turn on showing full paths in Dependency Walker, different DLLs might be picked up than what you thought.

---

<div class="post-metadata">

### Author: ![ebennink](https://discourse.itk.org/user_avatar/discourse.itk.org/ebennink/32/527_2.png) [@ebennink](https://discourse.itk.org/u/ebennink)
#### Post date: [October 15, 2018, 9:17am UTC](https://discourse.itk.org/t/error-building-an-external-module-cannot-open-input-file-itkcommon-lib/1346/11 "2018-10-15T09:17:48Z")

</div>

I have a feeling that I’m beginning to understand what’s going on here. As my external module is made up of templated code only (just a .hxx file), the DLL is just an empty shell. I expected that the ITK build process would pre-process all templated code, compile all of it, and put it into a shared library, but this is apparently not the case.  
So, correct me if I’m wrong, but for compiling the ITK Python package (for example) there is no benefit in building shared libraries, is there? The collection of ITK shared libraries has a size of just 20 MB, whereas the Python ITK libraries are 467 MB in total.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [October 15, 2018, 1:03pm UTC](https://discourse.itk.org/t/error-building-an-external-module-cannot-open-input-file-itkcommon-lib/1346/12 "2018-10-15T13:03:43Z")

</div>

> [@ebennink](#):
>
> pre-process all templated code, compile all of it, and put it into a shared library

This is called explicit template instantiation. You can read more about it [here](https://itk.org/Wiki/Proposals:Explicit_Instantiation). Enabling this requires extra work on the developer’s side.

@matt.mccormick or @blowekamp would be better able to answer the part of the question about Python packages.

---

<div class="post-metadata">

### Author: ![ebennink](https://discourse.itk.org/user_avatar/discourse.itk.org/ebennink/32/527_2.png) [@ebennink](https://discourse.itk.org/u/ebennink)
#### Post date: [October 15, 2018, 1:39pm UTC](https://discourse.itk.org/t/error-building-an-external-module-cannot-open-input-file-itkcommon-lib/1346/13 "2018-10-15T13:39:21Z")

</div>

Thanks! Good to know 🙂
