# Unable to run vtk example in clion

**URL:** https://discourse.vtk.org/t/unable-to-run-vtk-example-in-clion/11857
**Category:** Support
**Created:** [July 1, 2023, 5:45pm UTC](https://discourse.vtk.org/t/unable-to-run-vtk-example-in-clion/11857 "2023-07-01T17:45:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![gongwaner](https://discourse.vtk.org/user_avatar/discourse.vtk.org/gongwaner/32/6996_2.png) [@gongwaner](https://discourse.vtk.org/u/gongwaner)
#### Post date: [July 1, 2023, 5:45pm UTC](https://discourse.vtk.org/t/unable-to-run-vtk-example-in-clion/11857/1 "2023-07-01T17:45:46Z")

</div>

I installed vtk on my Mac using  
`brew install vtk`

then for testing purpose, I download a random example [https://examples.vtk.org/site/Cxx/GeometricObjects/Cube/](https://examples.vtk.org/site/Cxx/GeometricObjects/Cube/)  
then using the instruction as mentioned in the page to run example, it ran successfully.

Then when I opened the project using Clion, I encountered build error.

```auto
[1/1] Linking CXX executable Cube.app/Contents/MacOS/Cube
FAILED: Cube.app/Contents/MacOS/Cube 
: && /Library/Developer/CommandLineTools/usr/bin/c++ -O3 -DNDEBUG -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names @CMakeFiles/Cube.rsp -o Cube.app/Contents/MacOS/Cube && :
ld: warning: ignoring file /opt/homebrew/lib/libvtkRenderingFreeType-9.2.9.2.6.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/lib/libvtkRenderingOpenGL2-9.2.9.2.6.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/lib/libvtkRenderingContext2D-9.2.9.2.6.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/lib/libvtkRenderingHyperTreeGrid-9.2.9.2.6.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/lib/libvtkRenderingUI-9.2.9.2.6.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/lib/libvtkRenderingContextOpenGL2-9.2.9.2.6.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/lib/libvtkInteractionStyle-9.2.9.2.6.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/lib/libvtkRenderingCore-9.2.9.2.6.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/lib/libvtkCommonColor-9.2.9.2.6.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/lib/libvtkCommonExecutionModel-9.2.9.2.6.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/lib/libvtkCommonTransforms-9.2.9.2.6.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/lib/libvtkRenderingGL2PSOpenGL2-9.2.9.2.6.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/lib/libvtkFiltersGeneral-9.2.9.2.6.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/lib/libvtkFiltersCore-9.2.9.2.6.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/lib/libvtkCommonDataModel-9.2.9.2.6.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/lib/libvtkCommonMisc-9.2.9.2.6.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/lib/libvtksys-9.2.9.2.6.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/lib/libvtkfreetype-9.2.9.2.6.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/lib/libvtkkissfft-9.2.9.2.6.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/lib/libvtkCommonMath-9.2.9.2.6.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/lib/libGLEW.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/lib/libvtkCommonCore-9.2.9.2.6.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
Undefined symbols for architecture x86_64:
  "vtkInteractionStyle_AutoInit_Construct()", referenced from:
      __GLOBAL__ sub_I_Cube.cxx in Cube.cxx.o
  "vtkRenderingOpenGL2_AutoInit_Construct()", referenced from:
      __GLOBAL__ sub_I_Cube.cxx in Cube.cxx.o
  "vtkRenderingFreeType_AutoInit_Construct()", referenced from:
      __GLOBAL__ sub_I_Cube.cxx in Cube.cxx.o
  "vtkDataSet::GetScalarRange()", referenced from:
      _main in Cube.cxx.o
  "vtkPolyData::New()", referenced from:
      _main in Cube.cxx.o
  "vtkPolyData::SetPolys(vtkCellArray*)", referenced from:
      _main in Cube.cxx.o
  "vtkRenderer::SetActiveCamera(vtkCamera*)", referenced from:
      _main in Cube.cxx.o
  "vtkRenderer::New()", referenced from:
      _main in Cube.cxx.o
  "vtkRenderer::AddActor(vtkProp*)", referenced from:
      _main in Cube.cxx.o
  "vtkCellArray::New()", referenced from:
      _main in Cube.cxx.o
  "vtkDataArray::InsertTuple1(long long, double)", referenced from:
      _main in Cube.cxx.o
  "vtkFloatArray::New()", referenced from:
      _main in Cube.cxx.o
  "vtkNamedColors::GetColor3d(vtkStdString const&)", referenced from:
      _main in Cube.cxx.o
  "vtkNamedColors::New()", referenced from:
      _main in Cube.cxx.o
  "vtkRenderWindow::New()", referenced from:
      _main in Cube.cxx.o
  "vtkPolyDataMapper::SetInputData(vtkPolyData*)", referenced from:
      _main in Cube.cxx.o
  "vtkPolyDataMapper::New()", referenced from:
      _main in Cube.cxx.o
  "vtkDataSetAttributes::SetScalars(vtkDataArray*)", referenced from:
      _main in Cube.cxx.o
  "vtkDebugLeaksManager::vtkDebugLeaksManager()", referenced from:
      __GLOBAL__ sub_I_Cube.cxx in Cube.cxx.o
  "vtkDebugLeaksManager::~vtkDebugLeaksManager()", referenced from:
      __GLOBAL__ sub_I_Cube.cxx in Cube.cxx.o
  "vtkRenderWindowInteractor::SetRenderWindow(vtkRenderWindow*)", referenced from:
      _main in Cube.cxx.o
  "vtkRenderWindowInteractor::New()", referenced from:
      _main in Cube.cxx.o
  "vtkObjectFactoryRegistryCleanup::vtkObjectFactoryRegistryCleanup()", referenced from:
      __GLOBAL__ sub_I_Cube.cxx in Cube.cxx.o
  "vtkObjectFactoryRegistryCleanup::~vtkObjectFactoryRegistryCleanup()", referenced from:
      __GLOBAL__ sub_I_Cube.cxx in Cube.cxx.o
  "vtksys::SystemToolsManager::SystemToolsManager()", referenced from:
      __GLOBAL__ sub_I_Cube.cxx in Cube.cxx.o
  "vtksys::SystemToolsManager::~SystemToolsManager()", referenced from:
      __GLOBAL__ sub_I_Cube.cxx in Cube.cxx.o
  "vtkActor::New()", referenced from:
      _main in Cube.cxx.o
  "vtkCamera::SetPosition(double, double, double)", referenced from:
      _main in Cube.cxx.o
  "vtkCamera::SetFocalPoint(double, double, double)", referenced from:
      _main in Cube.cxx.o
  "vtkCamera::New()", referenced from:
      _main in Cube.cxx.o
  "vtkPoints::New()", referenced from:
      _main in Cube.cxx.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

```

I don’t understand what went wrong.

```auto
ld: symbol(s) not found for architecture x86_64

```

this is a very general error and could be caused by a lot of reasons.  
I’ve searched through and didn’t find anyone who has the same problem.

My configuration:  
macOS 13.4.1 (22F82)

vtk info:  
 ![image](https://discourse.vtk.org/uploads/default/original/2X/2/2021596d16994234221995b6b79e6dbc54796a4b.png)

Any help is appreciated!

---

<div class="post-metadata">

### Author: ![gongwaner](https://discourse.vtk.org/user_avatar/discourse.vtk.org/gongwaner/32/6996_2.png) [@gongwaner](https://discourse.vtk.org/u/gongwaner)
#### Post date: [July 2, 2023, 12:32am UTC](https://discourse.vtk.org/t/unable-to-run-vtk-example-in-clion/11857/2 "2023-07-02T00:32:11Z")

</div>

after some desperate searches I’ve found the solution. The error occurs because Mac M2 chip uses arm64 architecture while clion tries to build using x86. So the solution is to add

```auto
if (APPLE)
    SET(CMAKE_OSX_ARCHITECTURES arm64)
endif ()

```

these 3 lines into CMakeLists.txt  
and now it builds without any error.

for anyone who needs reference, my Mac is Mac mini m2(2023)

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [July 20, 2023, 7:38pm UTC](https://discourse.vtk.org/t/unable-to-run-vtk-example-in-clion/11857/3 "2023-07-20T19:38:38Z")

</div>

Note that `x86_64` processes will only launch the Intel “half” of universal binaries, so if CLion is not arm64-enabled yet, CMake and `ninja` will execute as Intel binaries and the compilers _they_ launch will see an “Intel” machine as being native.

---

<div class="post-metadata">

### Author: ![gongwaner](https://discourse.vtk.org/user_avatar/discourse.vtk.org/gongwaner/32/6996_2.png) [@gongwaner](https://discourse.vtk.org/u/gongwaner)
#### Post date: [July 21, 2023, 4:57am UTC](https://discourse.vtk.org/t/unable-to-run-vtk-example-in-clion/11857/4 "2023-07-21T04:57:13Z")

</div>

thanks for pointing out!  
Also when downloading clion, there’s an option to download intel or m1 version.  
It would be nice if there’s a way to differenciate between x86\_64 architecture(Intel chip) and arm64(M1/M2) in CMake.  
There’s actually a discussion about this in CMake forum: [https://discourse.cmake.org/t/how-to-determine-which-architectures-are-available-apple-m1/2401/9](https://discourse.cmake.org/t/how-to-determine-which-architectures-are-available-apple-m1/2401/9)
