# link error. ld: symbol(s) not found for architecture x86\_64

**URL:** https://discourse.itk.org/t/link-error-ld-symbol-s-not-found-for-architecture-x86-64/3554
**Category:** Beginner Questions
**Created:** [October 19, 2020, 12:36pm UTC](https://discourse.itk.org/t/link-error-ld-symbol-s-not-found-for-architecture-x86-64/3554 "2020-10-19T12:36:35Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![kaiyan\_liu](https://discourse.itk.org/user_avatar/discourse.itk.org/kaiyan_liu/32/1687_2.png) [@kaiyan\_liu](https://discourse.itk.org/u/kaiyan_liu)
#### Post date: [October 19, 2020, 12:36pm UTC](https://discourse.itk.org/t/link-error-ld-symbol-s-not-found-for-architecture-x86-64/3554/1 "2020-10-19T12:36:35Z")

</div>

I’m learning the examples provided by ITK([https://itk.org/ITKExamples/src/index.htm](https://itk.org/ITKExamples/src/index.htm))  
when I’m trying the first example( Convert An itk::Image To vtkImageData)([https://itk.org/ITKExamples/src/Bridge/VtkGlue/ConvertAnitkImageTovtkImageData/Documentation.html](https://itk.org/ITKExamples/src/Bridge/VtkGlue/ConvertAnitkImageTovtkImageData/Documentation.html))  
there is no CMakeLists.txt in this web page, but I have found one in [https://github.com/InsightSoftwareConsortium/ITKExamples/blob/master/src/Bridge/VtkGlue/ConvertAnitkImageTovtkImageData/CMakeLists.txt](https://github.com/InsightSoftwareConsortium/ITKExamples/blob/master/src/Bridge/VtkGlue/ConvertAnitkImageTovtkImageData/CMakeLists.txt)  
so I wrote my own CMakeLists.txt like this

```
cmake_minimum_required(VERSION 3.17)
project(ConvertAnitkImageTovtkImageData)
set(CMAKE_CXX_STANDARD 11)
# and I add the next two lines , otherwise it told me can't find .h files
include_directories("/usr/local/include/ITK-5.1")
include_directories("/usr/local/include/vtk-9.0")
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
add_executable(ConvertAnitkImageTovtkImageData Code.cxx)
target_link_libraries(ConvertAnitkImageTovtkImageData ${ITK_LIBRARIES})

```

It’s Ok when I ran cmake. But an error occurred just like the title.

 ![截屏2020-10-18 下午11.43.42](https://discourse.itk.org/uploads/default/original/2X/7/715e94941376e729d424a98430aadaf6d79e7c6e.png)  
 ![截屏2020-10-18 下午11.44.13](https://discourse.itk.org/uploads/default/original/2X/6/6bde721e867372d70b534c2a759a66ae154caa25.png)  
hope the image is useful.

Also I wanna ask , I have tried the helloWorld project like this  
[https://itk.org/ITKExamples/src/Core/Common/BuildAHelloWorldProgram/Documentation.html](https://itk.org/ITKExamples/src/Core/Common/BuildAHelloWorldProgram/Documentation.html)  
it works good with the “raw” CMakeLists.txt (without include\_directories(XXX) )  
but when I try to compile it without cmake , just like this  
" g++ helloWorld.cxx -o helloWorld -std=c++11 "  
an error occurred that “itkImage.h not found”  
and I tried again " g++ helloWorld.cxx -o HelloWorld -std=c++11 -I /usr/local/include/ITK-5.1 "  
there is the same error as the images show

---

<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 19, 2020, 1:32pm UTC](https://discourse.itk.org/t/link-error-ld-symbol-s-not-found-for-architecture-x86-64/3554/2 "2020-10-19T13:32:27Z")

</div>

Did you try adding find/link VTK?

```auto
cmake_minimum_required(VERSION 3.17)
project(ConvertAnitkImageTovtkImageData)
set(CMAKE_CXX_STANDARD 11)
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
add_executable(ConvertAnitkImageTovtkImageData Code.cxx)
target_link_libraries(ConvertAnitkImageTovtkImageData ${ITK_LIBRARIES} ${VTK_LIBRARIES})

```

---

<div class="post-metadata">

### Author: ![kaiyan\_liu](https://discourse.itk.org/user_avatar/discourse.itk.org/kaiyan_liu/32/1687_2.png) [@kaiyan\_liu](https://discourse.itk.org/u/kaiyan_liu)
#### Post date: [October 19, 2020, 1:52pm UTC](https://discourse.itk.org/t/link-error-ld-symbol-s-not-found-for-architecture-x86-64/3554/3 "2020-10-19T13:52:36Z")

</div>

Yeah I have tried it. And it makes no difference  
I’m now thinking about whether it’s because cmake has found a wrong path(for I have ever installed vmtk which uses VTK-8.1 and I compiled VTK-9.0)  
Did you know how to assign a fixed path?  
I have tried to use like these  
set(VTK\_DIR , “XXX”)  
set(CMAKE\_INCLUDE\_PATH “XXX”)  
find\_package(ITK PATH\_SUFFIXES “XXX”)  
but it seems that cmake always first find VTK from vmtk , only if I do this  
find\_package(VTK 9.0 XXXX)  
can cmake find the right one

Well…After I typed the words above I tried again with adding find/link VTK and set it’s VERSION , and it worked. Thanks a lot for your help !

---

<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 19, 2020, 2:56pm UTC](https://discourse.itk.org/t/link-error-ld-symbol-s-not-found-for-architecture-x86-64/3554/4 "2020-10-19T14:56:10Z")

</div>

Maybe include the final code which worked for you, in case someone has a similar problem in the future?

---

<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 19, 2020, 2:58pm UTC](https://discourse.itk.org/t/link-error-ld-symbol-s-not-found-for-architecture-x86-64/3554/5 "2020-10-19T14:58:49Z")

</div>

You should do find ITK first, because it should get the correct version of VTK it was built against. Then do find VTK - it should get the same version from ITK. I think this is the correct order. The order was important some years ago, and might still be.

---

<div class="post-metadata">

### Author: ![kaiyan\_liu](https://discourse.itk.org/user_avatar/discourse.itk.org/kaiyan_liu/32/1687_2.png) [@kaiyan\_liu](https://discourse.itk.org/u/kaiyan_liu)
#### Post date: [October 22, 2020, 1:13pm UTC](https://discourse.itk.org/t/link-error-ld-symbol-s-not-found-for-architecture-x86-64/3554/6 "2020-10-22T13:13:22Z")

</div>

> [@dzenanz](#):
>
> Maybe include the final code which worked for you, in case someone has a similar problem in the future?

Yeah it will be good if I can help somebody else , while I’m not good at using cmake so this may not be a good example , but anyway , here is my “CMakeLists.txt”

```
# CMakeLists.txt
cmake_minimum_required(VERSION 3.17)
project(ConvertAnitkImageTovtkImageData)
set(CMAKE_CXX_STANDARD 11)
find_package(ITK 5.1 REQUIRED)
include("${ITK_USE_FILE}")
find_package(VTK 9.0 REQUIRED)
add_executable(ConvertAnitkImageTovtkImageData ConvertAnitkImageTovtkImageData.cxx)
target_link_libraries(ConvertAnitkImageTovtkImageData ${ITK_LIBRARIES})
# VTK 9.0 recommend this , instead of (include("${VTK_USE_FILE}"))
vtk_module_autoinit(TARGETS ConvertAnitkImageTovtkImageData 
                                 MODULES ${VTK_LIBRARIES})

```

I just figure out the VERSION , but I think this will be a better way to figure out the path of the package

```
 find_package(ITK 
    PATHS "/usr/local/XXXXX"
    NO_DEFAULT_PATH)

```
