question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect invocation of AppleClang compiler for detecting libcxx.

See original GitHub issue

The code

execute_process(
        COMMAND ${CMAKE_COMMAND} -E echo "#include <string>"
        COMMAND ${CMAKE_CXX_COMPILER} -x c++ ${compile_options} -E -dM -
        OUTPUT_VARIABLE string_defines
    )

causes the following output

-- Conan: Automatic detection of conan settings from cmake
In file included from <stdin>:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:504:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string_view:175:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__string:57:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:641:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstring:60:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string.h:60:15: fatal error: 'string.h' file not found
#include_next <string.h>
              ^~~~~~~~~~
1 error generated.
-- Conan: Settings= -s;build_type=Debug;-s;compiler=apple-clang;-s;compiler.version=12.0;-s;compiler.libcxx=libc++

-isysroot should be always specified for AppleClang, see also https://stackoverflow.com/a/63188875.

Fix:

    if(${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL AppleClang)
        set(compile_options -isysroot ${CMAKE_OSX_SYSROOT} ${compile_options})
    endif()
    execute_process(
        COMMAND ${CMAKE_COMMAND} -E echo "#include <string>"
        COMMAND ${CMAKE_CXX_COMPILER} -x c++ ${compile_options} -E -dM -
        OUTPUT_VARIABLE string_defines
    )

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
DmitrySokolovcommented, Nov 13, 2020

Hmm… macOS reguires CMAKE_OSX_SYSROOT, so the patch is

--- conan.cmake
+++ conan.cmake
@@ -264,6 +264,14 @@
         endif()
     endforeach()

+    if(${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL AppleClang)
+        if(${CMAKE_SYSTEM_NAME} STREQUAL iOS)
+            set(compile_options -isysroot ${CMAKE_SYSROOT} -target arm64-apple-ios${CMAKE_OSX_DEPLOYMENT_TARGET} ${compile_options})
+        else()
+            set(compile_options -isysroot ${CMAKE_OSX_SYSROOT} ${compile_options})
+        endif()
+    endif()
+
     execute_process(
         COMMAND ${CMAKE_COMMAND} -E echo "#include <string>"
         COMMAND ${CMAKE_CXX_COMPILER} -x c++ ${compile_options} -E -dM -
1reaction
DmitrySokolovcommented, Nov 13, 2020

Patch for macOS and iOS:

--- conan.cmake
+++ conan.cmake
@@ -264,6 +264,13 @@
         endif()
     endforeach()

+    if(${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL AppleClang)
+        set(compile_options -isysroot ${CMAKE_SYSROOT} ${compile_options})
+        if(${CMAKE_SYSTEM_NAME} STREQUAL iOS)
+            set(compile_options ${compile_options} -target arm64-apple-ios${CMAKE_OSX_DEPLOYMENT_TARGET})
+        endif()
+    endif()
+
     execute_process(
         COMMAND ${CMAKE_COMMAND} -E echo "#include <string>"
         COMMAND ${CMAKE_CXX_COMPILER} -x c++ ${compile_options} -E -dM -
Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem installing ROOT 6.14.06 on mac 10.13.6 with libcxx ...
gcc 8.2 just installed compiling with support for objc++ on macos 10.13.6 with xcode 10.1. I'm not asking for an immediate solution, I...
Read more >
Handling a version mismatch of the compiler version between ...
The first invocation has CMake think Apple-clang is my compiler while conan is configured to use the llvm version and on the second...
Read more >
Changelog — conan 1.45.0 documentation
Fix: Added a visible warning about libcxx compatibility and the detected one for the default profile. Fix: Wrong detection of compiler in OSX...
Read more >
Clang linking error MacOS Big Sur | Apple Developer Forums
Apple clang version 12.0.0 (clang-1200.0.32.27) ... clang: error: linker command failed with exit code 1 (use -v to see invocation).
Read more >
Getting Started with the LLVM System
Hardware; Software; Host C++ Toolchain, both Compiler and Standard Library ... For example, to build LLVM, Clang, libcxx, and libcxxabi, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found