# How do I add a lib library path to a subpart of LLVM?

**URL:** https://discourse.cmake.org/t/how-do-i-add-a-lib-library-path-to-a-subpart-of-llvm/8524
**Category:** Usage
**Created:** [July 15, 2023, 10:05am UTC](https://discourse.cmake.org/t/how-do-i-add-a-lib-library-path-to-a-subpart-of-llvm/8524 "2023-07-15T10:05:01Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![lifangyi01](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lifangyi01/32/3610_2.png) [@lifangyi01](https://discourse.cmake.org/u/lifangyi01)
#### Post date: [July 15, 2023, 10:05am UTC](https://discourse.cmake.org/t/how-do-i-add-a-lib-library-path-to-a-subpart-of-llvm/8524/1 "2023-07-15T10:05:01Z")

</div>

## Question

I tried compiling llvm15 on Ubuntu with AArch64 architecture. However, I encountered the following problems:

### 1. `/usr/bin/ld: cannot find -lgcc_s`, some of the errors are as follows:

```auto
[build] [73/4456 0% :: 1.026] Linking CXX static library lib/clang/15.0.1/lib/aarch64-unknown-linux-gnu/libclang_rt.fuzzer_no_main.a
[build] FAILED: lib/clang/15.0.1/lib/aarch64-unknown-linux-gnu/libclang_rt.fuzzer_no_main.a 
[build] : && /usr/bin/cmake -E remove lib/clang/15.0.1/lib/aarch64-unknown-linux- ........
[build] /usr/bin/ld: cannot find -lgcc_s
[build] /usr/bin/ld: cannot find -lgcc_s
[build] clang: error: linker command failed with exit code 1 (use -v to see invocation)
[build] [73/4456 0% :: 1.261] Linking CXX shared library lib/clang/15.0.1/lib/aarch64-unknown-linux-gnu/libclang_rt.asan.so
[build] [73/4456 0% :: 1.322] Linking CXX static library lib/clang/15.0.1/lib/aarch64-unknown-linux-gnu/libclang_rt.fuzzer_interceptors.a
[build] FAILED: lib/clang/15.0.1/lib/aarch64-unknown-linux-gnu/libclang_rt.fuzzer_interceptors.a 
[build] : && /usr/bin/cmake -E remove lib/clang/15.0.1/lib/aarch64-unknown-linux-gnu/libclang_rt.fuzzer_interceptors.a && /usr/bin/ar Dqc lib/clang/15.0.1/lib/
......

```

### 2. Modify the CMakeLists .txt

I tried adding something like the following to the CMakeLists .txt llvm, but configure didn’t work.

```cmake
link_directories("/usr/lib/gcc/aarch64-linux-gnu/9/" "/usr/lib/aarch64-linux-gnu/")

link_libraries("/usr/lib/gcc/aarch64-linux-gnu/9/libgcc_s.so")

```

The same problem in `1` will appear.

Maybe there is a problem with what I added, and the specific subproject is configured like this. I took a screenshot below.

```cmake
add_compiler_rt_object_libraries(RTfuzzer_interceptors
  OS ${FUZZER_SUPPORTED_OS}
  ARCHS ${FUZZER_SUPPORTED_ARCH}
  SOURCES FuzzerInterceptors.cpp
  CFLAGS ${LIBFUZZER_CFLAGS}
  DEPS ${LIBFUZZER_DEPS})

# Tries to add an "object library" target for a given list of OSs and/or
# architectures with name "<name>.<arch>" for non-Darwin platforms if
# architecture can be targeted, and "<name>.<os>" for Darwin platforms.
# add_compiler_rt_object_libraries(<name>
# OS <os names>
# ARCHS <architectures>
# SOURCES <source files>
# CFLAGS <compile flags>
# DEFS <compile definitions>
# DEPS <dependencies>
# ADDITIONAL_HEADERS <header files>)
function(add_compiler_rt_object_libraries name)
  cmake_parse_arguments(LIB "" "" "OS;ARCHS;SOURCES;CFLAGS;DEFS;DEPS;ADDITIONAL_HEADERS"
    ${ARGN})
  set(libnames)
  if(APPLE)
    foreach(os ${LIB_OS})
      set(libname "${name}.${os}")
      set(libnames ${libnames} ${libname})
      set(extra_cflags_${libname} ${DARWIN_${os}_CFLAGS})
      list_intersect(LIB_ARCHS_${libname} DARWIN_${os}_ARCHS LIB_ARCHS)
    endforeach()
  else()
    foreach(arch ${LIB_ARCHS})
      set(libname "${name}.${arch}")
      set(libnames ${libnames} ${libname})
      set(extra_cflags_${libname} ${TARGET_${arch}_CFLAGS})
      if(NOT CAN_TARGET_${arch})
        message(FATAL_ERROR "Architecture ${arch} can't be targeted")
        return()
      endif()
    endforeach()
  endif()

  # Add headers to LIB_SOURCES for IDEs
  compiler_rt_process_sources(LIB_SOURCES
    ${LIB_SOURCES}
    ADDITIONAL_HEADERS
      ${LIB_ADDITIONAL_HEADERS}
  )

  foreach(libname ${libnames})
    add_library(${libname} OBJECT ${LIB_SOURCES})
    if(LIB_DEPS)
      add_dependencies(${libname} ${LIB_DEPS})
    endif()

    # Strip out -msse3 if this isn't macOS.
    set(target_flags ${LIB_CFLAGS})
    if(APPLE AND NOT "${libname}" MATCHES ".*\.osx.*")
      list(REMOVE_ITEM target_flags "-msse3")
    endif()

    # Build the macOS sanitizers with Mac Catalyst support.
    if (APPLE AND
        "${COMPILER_RT_ENABLE_MACCATALYST}" AND
        "${libname}" MATCHES ".*\.osx.*")
      foreach(arch ${LIB_ARCHS_${libname}})
        list(APPEND target_flags
          "SHELL:-target ${arch}-apple-macos${DARWIN_osx_MIN_VER} -darwin-target-variant ${arch}-apple-ios13.1-macabi")
      endforeach()
    endif()

    set_target_compile_flags(${libname}
      ${extra_cflags_${libname}} ${target_flags})
    set_property(TARGET ${libname} APPEND PROPERTY
      COMPILE_DEFINITIONS ${LIB_DEFS})
    set_target_properties(${libname} PROPERTIES FOLDER "Compiler-RT Libraries")
    if(APPLE)
      set_target_properties(${libname} PROPERTIES
        OSX_ARCHITECTURES "${LIB_ARCHS_${libname}}")
    endif()
  endforeach()
endfunction()

```

### 3. Modify LD configuration - no permission

After a Google search, I found that I can modify the configuration file of LD, but the user I use does not have permission to modify the changed file and cannot execute `sudo`.

```auto
$ cat /etc/ld.so.conf.d/aarch64-linux-gnu.conf 
# Multiarch support
/usr/local/lib/aarch64-linux-gnu
/lib/aarch64-linux-gnu
/usr/lib/aarch64-linux-gnu

```

### 4. Modify the environment variables for the current user

I tried to add libgcc\_s directory where .so is located to my current user’s LD\_LIBRARY\_PATH, and I still got an error in 1 when compiling.

## I need help!

Is there any other way to enable the ld linker to find ‘libgcc\_s.so’ when I can’t use sudo, yes, when compiling llvm via cmake? Or do I have a problem with the above workaround?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [July 18, 2023, 12:10am UTC](https://discourse.cmake.org/t/how-do-i-add-a-lib-library-path-to-a-subpart-of-llvm/8524/2 "2023-07-18T00:10:05Z")

</div>

This seems like a question better suited for [LLVM directly](https://discourse.llvm.org/) to me.
