# Linking LLVM fails with target\_link\_libraries()

**URL:** <https://discourse.cmake.org/t/linking-llvm-fails-with-target-link-libraries/15852>\
**Category:** Code\
**Tags:** os:linux\
**Created:** [September 24, 2026, 8:23am UTC](https://discourse.cmake.org/t/linking-llvm-fails-with-target-link-libraries/15852 "2026-09-24T08:23:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheShiningBoots](https://discourse.cmake.org/user_avatar/discourse.cmake.org/theshiningboots/32/6256_2.png) [@TheShiningBoots](https://discourse.cmake.org/u/TheShiningBoots)\
**Post date:** [September 24, 2026, 8:23am UTC](https://discourse.cmake.org/t/linking-llvm-fails-with-target-link-libraries/15852/1 "2026-09-24T08:23:46Z")

</div>

```cmake
find_package(LLVM REQUIRED CONFIG)

llvm_map_components_to_libnames(llvm_libs
  core
  support
  target
  irreader
)

target_include_directories(catguy PRIVATE ${LLVM_INCLUDE_DIRS})
target_compile_definitions(catguy PRIVATE ${LLVM_DEFINITIONS})
target_link_libraries(catguy PRIVATE ${llvm_libs})

```

The above fails with:

```bash
[50%] Linking CXX executable catguy
/usr/bin/ld: cannot find -lLLVMCore: No such file or directory
/usr/bin/ld: cannot find -lLLVMTarget: No such file or directory
/usr/bin/ld: cannot find -lLLVMIRReader: No such file or directory
collect2: error: ld returned 1 exit status

```

But if I change the `target_link_libraries` to just `link_libraries` it builds successfully. Can somebody please explain why this happens? and how to fix it?  
The above code is mostly from the llvm docs: [Building LLVM with CMake - LLVM](https://llvm.org/docs/CMake.html)

---

<div class="post-metadata">

**Author:** ![stephan-cr](https://discourse.cmake.org/user_avatar/discourse.cmake.org/stephan-cr/32/5947_2.png) [@stephan-cr](https://discourse.cmake.org/u/stephan-cr)\
**Post date:** [September 26, 2026, 7:55pm UTC](https://discourse.cmake.org/t/linking-llvm-fails-with-target-link-libraries/15852/2 "2026-09-26T19:55:44Z")

</div>

Not sure if the LLVM build instructions are up-to-date. Most of the code predates modern CMake. None of the libraries mentioned in your error message exist on my system, while something like `libLLVMSupport.a` exists. I’m on Arch Linux (if that even matters).

But, it looks like they have imported targets these days (at least for LLVM 22) for certain libraries.

So, what works for me is:

```cmake
find_package(LLVM REQUIRED CONFIG)

add_executable(foo foo.cpp)
target_link_libraries(foo PRIVATE LLVM)

```

`LLVM` is defined as `add_library(LLVM SHARED IMPORTED)` (in LLVMExports.cmake) and therefore a shared library, which is fine for me, but not sure if you need the static libraries.

Maybe [https://discourse.llvm.org/](https://discourse.llvm.org/) is a better place to ask for help in your specific situation.
