LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 19071 - [cmake] check_cxx_compiler_flag test for -std=c++11 fails to use linker flags, unable to find nonstandard location of libc++
Summary: [cmake] check_cxx_compiler_flag test for -std=c++11 fails to use linker flags...
Status: NEW
Alias: None
Product: Build scripts
Classification: Unclassified
Component: cmake (show other bugs)
Version: trunk
Hardware: All All
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-06 18:06 PST by David Fang
Modified: 2015-08-10 00:38 PDT (History)
4 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Fang 2014-03-06 18:06:59 PST
On a system where libc++ is installed in a nonstandard location, the test for -std=c++11 fails when trying to link the test executable, even when -L is passed to linker flags:

-- Target triple: powerpc-apple-darwin8.11.0
-- Host OS X version: 10.4
-- Native target architecture is PowerPC
-- Threads enabled.
-- Doxygen disabled.
-- Building with -fPIC
CMake Error at cmake/modules/HandleLLVMOptions.cmake:298 (message):
  LLVM requires C++11 support but the '-std=c++11' flag isn't supported.
Call Stack (most recent call first):
  CMakeLists.txt:301 (include)


-- Configuring incomplete, errors occurred!
make: *** [cmake_check_build_system] Error 1

from CMakeFiles/CMakeError.log:
Performing C++ SOURCE FILE Test CXX_SUPPORTS_CXX11 failed with the following output:
Change Dir: /Users/fang/local/src/LLVM-svn/clang34-stage1-build/CMakeFiles/CMakeTmp

Run Build Command:/sw/bin/make "cmTryCompileExec1310359099/fast"
make[1]: Entering directory `/Volumes/Isolde/builds/LLVM/clang34-stage1-build/CMakeFiles/CMakeTmp'
/sw/bin/make -f CMakeFiles/cmTryCompileExec1310359099.dir/build.make CMakeFiles/cmTryCompileExec1310359099.dir/build
make[2]: Entering directory `/Volumes/Isolde/builds/LLVM/clang34-stage1-build/CMakeFiles/CMakeTmp'
/Volumes/Mercedes2/sw/bin/cmake -E cmake_progress_report /Users/fang/local/src/LLVM-svn/clang34-stage1-build/CMakeFiles/CMakeTmp/CMakeFiles 1
Building CXX object CMakeFiles/cmTryCompileExec1310359099.dir/src.cxx.o
/sw/opt/llvm-3.4/bin/clang++    -std=c++11 -stdlib=libc++ -cxx-isystem /sw/include/c++/v1 -B/sw/lib/odcctools/bin -no-integrated-as -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor  -DCXX_SUPPORTS_CXX11   -std=c++11 -o CMakeFiles/cmTryCompileExec1310359099.dir/src.cxx.o -c /Users/fang/local/src/LLVM-svn/clang34-stage1-build/CMakeFiles/CMakeTmp/src.cxx
Linking CXX executable cmTryCompileExec1310359099
/Volumes/Mercedes2/sw/bin/cmake -E cmake_link_script CMakeFiles/cmTryCompileExec1310359099.dir/link.txt --verbose=1
/sw/opt/llvm-3.4/bin/clang++    -std=c++11 -stdlib=libc++ -cxx-isystem /sw/include/c++/v1 -B/sw/lib/odcctools/bin -no-integrated-as -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor  -DCXX_SUPPORTS_CXX11 -Wl,-search_paths_first -Wl,-headerpad_max_install_names   CMakeFiles/cmTryCompileExec1310359099.dir/src.cxx.o  -o cmTryCompileExec1310359099  -lm
ld: library not found for -lc++
clang-3.4: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: Leaving directory `/Volumes/Isolde/builds/LLVM/clang34-stage1-build/CMakeFiles/CMakeTmp'
make[1]: Leaving directory `/Volumes/Isolde/builds/LLVM/clang34-stage1-build/CMakeFiles/CMakeTmp'
make[2]: *** [cmTryCompileExec1310359099] Error 1
make[1]: *** [cmTryCompileExec1310359099/fast] Error 2


% grep LINKER_FLAGS CMakeCache.txt 
CMAKE_EXE_LINKER_FLAGS:STRING= -L/sw/lib/c++
CMAKE_EXE_LINKER_FLAGS_DEBUG:STRING=
CMAKE_EXE_LINKER_FLAGS_MINSIZEREL:STRING=
CMAKE_EXE_LINKER_FLAGS_RELEASE:STRING=
CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING=
CMAKE_MODULE_LINKER_FLAGS:STRING= -L/sw/lib/c++
CMAKE_MODULE_LINKER_FLAGS_DEBUG:STRING=
CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL:STRING=
CMAKE_MODULE_LINKER_FLAGS_RELEASE:STRING=
CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING=
CMAKE_SHARED_LINKER_FLAGS:STRING= -L/sw/lib/c++
CMAKE_SHARED_LINKER_FLAGS_DEBUG:STRING=
CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL:STRING=
CMAKE_SHARED_LINKER_FLAGS_RELEASE:STRING=
CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING=

and libc++ lives at /sw/lib/c++/libc++.dylib so that user may choose which libc++ to use (vendor's vs. built).

Can the trivial executable test be fixed to account for linker flags?
Better yet would be if there were an equivalent option to -cxx-isystem for linking.
Comment 1 David Fang 2014-03-10 12:01:56 PDT
workaround is to pass -L linker flags to CMAKE_CXX_COMPILER_FLAGS, as silly as that seems.  

cmake versions: 2.8.10.2 and 2.8.12.
Entirely possible that this should be fixed in cmake.
Comment 2 Evgenii Stepanov 2014-11-25 03:22:37 PST
This becomes a lot more fun when you add MSan into the mix :)

I've filed http://www.cmake.org/Bug/view.php?id=15264
Comment 3 David Fang 2015-08-10 00:38:08 PDT
(In reply to comment #2)
> This becomes a lot more fun when you add MSan into the mix :)
> 
> I've filed http://www.cmake.org/Bug/view.php?id=15264


According to their issue history, 
http://www.cmake.org/Bug/view.php?id=14066#c37279
this should be fixed with cmake-3.2.