[Trilinos-Users] Building on mac with clang and c++11

Robert N. Simpson simpsonR4 at cardiff.ac.uk
Mon Jun 10 09:11:04 MDT 2013


Antonio,

Thanks for the advice. After trying various build options, I managed to link my project with Trilinos. The important feature I found was that I had to recompile the Trilinos library with clang making sure that the -stdlib=libc++ flag was included under the CMAKE_CXX_FLAGS option. Otherwise I get the errors I reported previously.

I also tried the additional linker flag you suggested. But I found no difference in my build setup, with or without the flag.

I'm happy though, since I can now progress with the real work of coding!

Rob

On 10 Jun 2013, at 13:54, Antonio Cervone wrote:

> hi Rob,
> i have been using a similar configuration on linux.
> i think your problem is unrelated to trilinos.
> in order to properly use clang along with libc++, i need to link also
> against libc++abi.
> you will need something like
> 
> elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
>    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++" )
>    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lc++abi" )
> else ()
> 
> don't know if mac osx requires this too.
> cheers
> 
> antonio
> 
> 
> On Mon, Jun 10, 2013 at 1:27 PM, Robert N. Simpson
> <simpsonR4 at cardiff.ac.uk> wrote:
>> I'm very new to the user group, so I'm not entirely sure this query is
>> appropriate for the email list. I'll give it a shot anyway.
>> 
>> My problem is that I am trying to build a project using on Mac OS X (10.7.5)
>> with clang (llvm 4.2) and c++11 while incorporating the Trilinos library. To
>> simplify my issue, I tried to compile a simple source file containing basic
>> Epetra classes. My CMakeLists.txt file for this project looks like the
>> following:
>> 
>> # ----- CMakeLists.txt file --------------
>> project( tester )
>> cmake_mimimum_required( VERSION 2.8 )
>> 
>> # Initialize CXXFLAGS.
>> set(CMAKE_CXX_FLAGS "-Wall -std=c++11")
>> 
>> # Compiler-specific C++11 activation.
>> if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
>>    execute_process(
>>        COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE
>> GCC_VERSION)
>>    if (NOT (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL
>> 4.7))
>>        message(FATAL_ERROR "${PROJECT_NAME} requires g++ 4.7 or greater.")
>>    endif ()
>> elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
>>    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++" )
>> else ()
>>    message(FATAL_ERROR "Your C++ compiler does not support C++11.")
>> endif ()
>> 
>> FIND_PACKAGE( Trilinos )
>> 
>> include_directories(${Trilinos_TPL_INCLUDE_DIRS})
>> include_directories(${Trilinos_INCLUDE_DIRS})
>> 
>> link_directories(${Trilinos_LIBRARY_DIRS})
>> link_directories(${Trilinos_TPL_LIBRARY_DIRS})
>> 
>> add_executable( tester main.cpp )
>> 
>> target_link_libraries( tester  ${Trilinos_LIBRARIES}
>> ${Trilinos_TPL_LIBRARIES} )
>> # ---------- end of file ----------
>> 
>> The source file main.cpp compiles ok, but during the linking stage I get
>> some errors trying to link with what seems to be the std c++ library. E.g.
>> here is the first error:
>> 
>> Undefined symbols for architecture x86_64:
>>  "std::string::size() const", referenced from:
>>      std::basic_string<char, std::char_traits<char>, std::allocator<char> >
>> std::operator+<char, std::char_traits<char>, std::allocator<char> >(char
>> const*, std::basic_string<char, std::char_traits<char>, std::allocator<char>
>>> const&) in libepetra.a(Epetra_MultiVector.cpp.o)
>>      std::basic_string<char, std::char_traits<char>, std::allocator<char> >
>> std::operator+<char, std::char_traits<char>, std::allocator<char> >(char
>> const*, std::basic_string<char, std::char_traits<char>, std::allocator<char>
>>> const&) in libepetra.a(Epetra_BlockMap.cpp.o)
>>      std::basic_string<char, std::char_traits<char>, std::allocator<char> >
>> std::operator+<char, std::char_traits<char>, std::allocator<char> >(char
>> const*, std::basic_string<char, std::char_traits<char>, std::allocator<char>
>>> const&) in libepetra.a(Epetra_IntVector.cpp.o)
>>      std::basic_string<char, std::char_traits<char>, std::allocator<char> >
>> std::operator+<char, std::char_traits<char>, std::allocator<char> >(char
>> const*, std::basic_string<char, std::char_traits<char>, std::allocator<char>
>>> const&) in libepetra.a(Epetra_IntSerialDenseMatrix.cpp.o)
>>      std::basic_string<char, std::char_traits<char>, std::allocator<char> >
>> std::operator+<char, std::char_traits<char>, std::allocator<char> >(char
>> const*, std::basic_string<char, std::char_traits<char>, std::allocator<char>
>>> const&) in libepetra.a(Epetra_CrsGraph.cpp.o)
>>      std::basic_string<char, std::char_traits<char>, std::allocator<char> >
>> std::operator+<char, std::char_traits<char>, std::allocator<char> >(char
>> const*, std::basic_string<char, std::char_traits<char>, std::allocator<char>
>>> const&) in libepetra.a(Epetra_SerialDenseMatrix.cpp.o)
>>  "std::string::c_str() const", referenced from:
>>      Epetra_Object::ReportError(std::string, int) const in
>> libepetra.a(Epetra_Object.cpp.o)
>> 
>> I have tried to play around with various settings, such as recompiling the
>> Trilinos library with the -std=c++11 and -stdlib=libc++ flags, but with no
>> success. Everything works fine on my linux machine with gcc.
>> 
>> Is there a simple way to get around the issues I am facing? Let me know if
>> I've left any important diagnostic details out.
>> 
>> Many thanks.
>> 
>> Rob
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> _______________________________________________
>> Trilinos-Users mailing list
>> Trilinos-Users at software.sandia.gov
>> http://software.sandia.gov/mailman/listinfo/trilinos-users
>> 
> _______________________________________________
> Trilinos-Users mailing list
> Trilinos-Users at software.sandia.gov
> http://software.sandia.gov/mailman/listinfo/trilinos-users
> 


Lecturer
School of Engineering
Cardiff University

Tel +44 (0)29 20876043.  Room number W/2.31





-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://software.sandia.gov/pipermail/trilinos-users/attachments/20130610/d5332537/attachment.html 


More information about the Trilinos-Users mailing list