Clang compilation issues with libc++

1,812 views
Skip to first unread message

michaels...@gmail.com

unread,
Jun 1, 2017, 9:29:21 AM6/1/17
to Ceres Solver
I have managed to build Ceres using clang. Now when using it, I run into the following problem:

In file included from /usr/local/include/ceres/ceres.h:37:
In file included from /usr/local/include/ceres/autodiff_cost_function.h:132:
In file included from /usr/local/include/ceres/internal/autodiff.h:145:
In file included from /usr/local/include/ceres/jet.h:167:
/usr/local/include/ceres/internal/port.h:39:10: fatal error: 'tr1/memory' file not found
#include <tr1/memory>
         ^~~~~~~~~~~~

This probably originates here

-- Looking for C++ include unordered_map
-- Looking for C++ include unordered_map - not found
-- Looking for C++ include tr1/unordered_map
-- Looking for C++ include tr1/unordered_map - found
-- Found tr1/unordered_map/set in std::tr1 namespace.
-- Looking for C++ include memory
-- Looking for C++ include memory - found
-- Performing Test HAVE_SHARED_PTR_IN_STD_NAMESPACE
-- Performing Test HAVE_SHARED_PTR_IN_STD_NAMESPACE - Failed
-- Performing Test HAVE_SHARED_PTR_IN_TR1_NAMESPACE
-- Performing Test HAVE_SHARED_PTR_IN_TR1_NAMESPACE - Failed
-- Looking for C++ include tr1/memory
-- Looking for C++ include tr1/memory - found
-- Performing Test HAVE_SHARED_PTR_IN_TR1_NAMESPACE_FROM_TR1_MEMORY_HEADER
-- Performing Test HAVE_SHARED_PTR_IN_TR1_NAMESPACE_FROM_TR1_MEMORY_HEADER - Success
-- Found shared_ptr in std::tr1 namespace using <tr1/memory> header.

I have installed libc++1 using sudo apt-get install libc++-dev libc++1

in my own projects cmake file I have:
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()

Any hints? Mike

Alex Stewart

unread,
Jun 1, 2017, 2:37:14 PM6/1/17
to ceres-...@googlegroups.com
Just configure Ceres with:

cmake -DCMAKE_CXX_FLAGS=“-stdlib=libc++” <PATH_TO_CERES_SOURCE>

Ceres appends to CMAKE_CXX_FLAGS, it doesn’t overwrite what’s passed into the configure step.  However, by default it uses whatever the default options are for the C++ compiler detected by CMake.

-Alex

--
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/3a8b3bb3-9fd6-48b4-84e1-c8baf37037d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alex Stewart

unread,
Jun 1, 2017, 3:06:16 PM6/1/17
to ceres-...@googlegroups.com
OK, so actually we weren’t passing extra user-specified flags to check_cxx_compiles(), so that would be using the default compiler configuration which would in your case be a problem.

Please try this CL: https://ceres-solver-review.googlesource.com/#/c/10300/ - it, combined with the line below should fix your issue.

-Alex

michaels...@gmail.com

unread,
Jun 2, 2017, 6:38:36 AM6/2/17
to Ceres Solver
I am still in trouble with this one

I am trying to build it as follows:

cmake -DCMAKE_CXX_FLAGS=“-stdlib=libc++” -DCXX11=ON ../ceres-solver

but it gives me:


-- Looking for C++ include unordered_map
-- Looking for C++ include unordered_map - not found
-- Looking for C++ include tr1/unordered_map
-- Looking for C++ include tr1/unordered_map - not found
-- Unable to find <unordered_map> or <tr1/unordered_map>.
-- Replacing unordered_map/set with map/set (warning: slower!), try enabling CXX11 option if you expect C++11 to be available.
-- Looking for C++ include memory
-- Looking for C++ include memory - not found
-- Looking for C++ include tr1/memory
-- Looking for C++ include tr1/memory - not found
CMake Error at CMakeLists.txt:494 (message):
  Unable to find shared_ptr, try enabling CXX11 option if you expect C++11 to
  be available.

Mike

Alex Stewart

unread,
Jun 2, 2017, 8:38:00 AM6/2/17
to ceres-...@googlegroups.com
What do the CMakeError.log and CMakeOutput.log (located in <BUILD_DIR>/CMakeFiles) say about the unordered_map/shared_ptr tests?

-Alex

michaels...@gmail.com

unread,
Jun 2, 2017, 8:46:43 AM6/2/17
to Ceres Solver
I found two snippets of interest. It seems to be using libstd++ first and later it complains about stdlib=libc++. Not sure how to resolve this. I do have both standard libraries installed.

Mike

Determining if the include file unordered_map exists failed with the following output:
Change Dir: /opt/google/ceres-solver/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_1c220/fast"
/usr/bin/make -f CMakeFiles/cmTC_1c220.dir/build.make CMakeFiles/cmTC_1c220.dir/build
make[1]: Entering directory '/opt/google/ceres-solver/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_1c220.dir/CheckIncludeFile.cxx.o
/usr/bin/c++     -fopenmp=libomp  -fopenmp=libomp   -o CMakeFiles/cmTC_1c220.dir/CheckIncludeFile.cxx.o -c /opt/google/ceres-solver/CMakeFiles/CMakeTmp/CheckIncludeFile.cxx
In file included from /opt/google/ceres-solver/CMakeFiles/CMakeTmp/CheckIncludeFile.cxx:1:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/unordered_map:35:
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/c++0x_warning.h:32:2: error: This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support \

....

Determining if the include file unordered_map exists failed with the following output:
Change Dir: /opt/google/ceres-solver/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_1c220/fast"
/usr/bin/make -f CMakeFiles/cmTC_1c220.dir/build.make CMakeFiles/cmTC_1c220.dir/build
make[1]: Entering directory '/opt/google/ceres-solver/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_1c220.dir/CheckIncludeFile.cxx.o
/usr/bin/c++     -fopenmp=libomp  -fopenmp=libomp   -o CMakeFiles/cmTC_1c220.dir/CheckIncludeFile.cxx.o -c /opt/google/ceres-solver/CMakeFiles/CMakeTmp/CheckIncludeFile.cxx
In file included from /opt/google/ceres-solver/CMakeFiles/CMakeTmp/CheckIncludeFile.cxx:1:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/unordered_map:35:
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/c++0x_warning.h:32:2: error: This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support \

Alex Stewart

unread,
Jun 4, 2017, 8:18:44 AM6/4/17
to ceres-...@googlegroups.com
So this line:

/usr/bin/c++     -fopenmp=libomp  -fopenmp=libomp   -o CMakeFiles/cmTC_1c220.dir/CheckIncludeFile.cxx.o -c /opt/google/ceres-solver/CMakeFiles/CMakeTmp/CheckIncludeFile.cxx

shows that neither -std=c++11, nor -stdlib=libc++ are being passed to the check functions.  I can’t replicate this, as running with the latest CL:


I can add arbitrary additional flags via -DCMAKE_CXX_FLAGS=“…” that are correctly passed to the check functions as evidenced in the CMakeOutput.log output.  Given that you are also enabling the CXX11 option, what does the section in the CMakeOutput.log related to COMPILER_HAS_CXX11_FLAG say?

-Alex

Reply all
Reply to author
Forward
0 new messages