title: ld cannot find -latomic or -lstdc++
body: <p>When trying to compile my project using the toolchain provided by the manufacturer of the hardware I'm developing for, compilation succeeds, however linking fails with the following error messages:</p>
  <blockquote>
  <p>/media/xxx/Data/toolchains/sysroots/x86_64-xxx-linux/usr/bin/arm-xxx-linux-gnueabi/../../libexec/arm-xxx-linux-gnueabi/gcc/arm-xxx-linux-gnueabi/4.8.4/ld: cannot find -latomic</p>
  </blockquote>
  <blockquote>
  <p>/media/xxx/Data/toolchains/sysroots/x86_64-xxx-linux/usr/bin/arm-xxx-linux-gnueabi/../../libexec/arm-xxx-linux-gnueabi/gcc/arm-xxx-linux-gnueabi/4.8.4/ld: cannot find -lstdc++</p>
  </blockquote>
  <p>However, when building a small test program using the same compiler and linker, everything works.</p>
  <p>Below is an excerpt of the important parts of my CMake toolchain file:</p>
  <pre><code>set(CMAKE_SYSTEM_NAME Linux)
  set(CMAKE_SYSTEM_PROCESSOR arm)
  
  ###
  # Get $CROSS
  ###
  if (NOT $ENV{CROSS_COMPILE} STREQUAL &quot;&quot;)
      set(cross $ENV{CROSS_COMPILE}) # WARNING: Ends with a - (minus)
  else()
      set(cross &quot;arm-xxx-linux-gnueabi-&quot;)
  endif()
  
  ###
  # Set CMake sysroot
  ###
  set(CMAKE_SYSROOT $ENV{SDKTARGETSYSROOT})
  set(CMAKE_SYSROOT_LINK $ENV{SDKTARGETSYSROOT})
  set(CMAKE_SYSROOT_COMPILE $ENV{SDKTARGETSYSROOT})
  
  set(CMAKE_C_COMPILER $ENV{TOOLCHAIN_TOOLSDIR}/${cross}gcc)
  set(CMAKE_CXX_COMPILER $ENV{TOOLCHAIN_TOOLSDIR}/${cross}g++)
  set(CMAKE_LD $ENV{TOOLCHAIN_TOOLSDIR}/${cross}ld)
  set(CMAKE_STRIP $ENV{TOOLCHAIN_TOOLSDIR}/${cross}strip)
  set(CMAKE_AR $ENV{TOOLCHAIN_TOOLSDIR}/${cross}ar)
  
  include_directories($ENV{SDKTARGETSYSROOT}/usr/include)
  </code></pre>
  <p>I'm not at liberty to disclose source code, but the source code isn't the issue here as it compiles correctly.</p>
  <p>Here's another MWE of the CMakeLists.txt file:</p>
  <pre><code>cmake_minimum_required(VERSION 3.10)
  
  project(xxx LANGUAGES CXX VERSION 2.0.0)
  set(CMAKE_CXX_STANDARD 11)
  set(CMAKE_CXX_STANDARD_REQUIRED True)
  set(TARGET_NAME xxx.bin)
  
  include_directories(
      include/
      ${INCLUDE_DIRS}
  )
  
  file(GLOB_RECURSE FILES ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS src/*.cpp)
  
  if (xxx_DEBUG)
    add_compile_options(
        -Wpedantic
        -DDDC_STUB
        -fabi-version=6
        -Wno-format-security
        -Wno-reorder
        -ggdb3
        -O0
        -fpermissive # Test
        -fPIC
  
        #-static-libstdc++ # with or without, doesn't change the behaviour
        #-static-libgcc # with or without, doesn't change the behaviour
    )
  else()
    add_compile_options(
      -Wpedantic
      -fabi-version=6
      -Wno-format-security
      -Wno-reorder
      -O3
      -fpermissive # Test
      -fPIC
  
      #-static-libstdc++ # with or without, doesn't change the behaviour
      #-static-libgcc # with or without, doesn't change the behaviour
  )
  endif()
  
  add_executable(${TARGET_NAME} ${FILES} ${MEMWATCH_FILES})
  </code></pre>
  <p>I've tried setting the sysroot-argument for ld, I've tried manually specifying the link (search) path <code>-L$ENV{SDKTARGETSYSROOT}/usr/lib/.debug</code>, and I've also tried hard-wiring the path to the library in question: <code>$ENV{SDKTARGETSYSROOT}/usr/lib/.debug/libatomic.so.1.0.0</code></p>
  <p>Is there another way I can tell ld what libraries to use?
  This works perfectly with standard toolchains!</p>
  <hr />
  <p>EDIT:</p>
  <p>I've now also tried brute-forcing it by creating a symlink from the .debug/libatomic to usr/lib/libatomic. That also hasn't had the desired effect.</p>