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

Robert N. Simpson simpsonR4 at cardiff.ac.uk
Mon Jun 10 05:27:38 MDT 2013


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








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


More information about the Trilinos-Users mailing list