Compiling NucNet Tools with the LLVM/clang compiler

As of version 4.1, the default compiler for Xcode is no longer gcc. In this post, I will show how I got NucNet Tools compiled after upgrading my Mac to OS X Yosemite version 10.10.2 and Xcode 6.1.1.

Once I upgraded, I typed

gcc -v

which returned

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix

The latest versions of Xcode now alias the default C and C++ compilers as gcc and g++, respectively; thus, invoking g++, the default compiler for NucNet Tools, in fact invokes clang++. I tested that the NucNet Tools examples codes could run with clang++ by changing into nucnet-tools-code, updating, and then compiling the network example codes:

cd nucnet-tools-code

svn up

cd examples/network

make clean

export NNT_NO_OPENMP=1

make all_network

All of the codes compiled except run_multiple_zone_omp.cpp. This is because openMP is not yet supported in the Clang mainline. I will wait until that is done before I pursue openMP calculations with NucNet Tools compiled with the LLVM compilers.

I next compiled the codes with Sparskit2, which requires a fortran compiler. I typed

export NNT_USE_SPARSKIT2=1

and compiled

make run_single_zone

This failed because at this point I had no fortran compiler installed. I next installed the latest gcc suite of compilers via Mac ports to get gfortran by typing:

sudo port install gcc49

After installation, I typed

gcc -v

which showed that my Mac still had gcc set to clang. To set gcc to my recently installed gcc 4.9, I first checked that it was there by typing:

port select --list gcc

which returned

Available versions for gcc:
    mp-gcc49
    none (active)

I then typed

sudo port select --set gcc mp-gcc49

to set gcc to gcc 4.9 and

source ~/.bash_profile

to make sure my current shell knew about the change. When I typed

gcc -v

I got

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin14/4.9.2/lto-wrapper
Target: x86_64-apple-darwin14
Configured with: /opt/local/var/macports/build/_opt_mports_dports_lang_gcc49/gcc49/work/gcc-4.9.2/configure --prefix=/opt/local --build=x86_64-apple-darwin14 --enable-languages=c,c++,objc,obj-c++,lto,fortran,java --libdir=/opt/local/lib/gcc49 --includedir=/opt/local/include/gcc49 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-4.9 --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-4.9 --with-gxx-include-dir=/opt/local/include/gcc49/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-isl=/opt/local --disable-isl-version-check --with-cloog=/opt/local --disable-cloog-version-check --enable-stage1-checking --disable-multilib --enable-lto --enable-libstdcxx-time --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --with-pkgversion='MacPorts gcc49 4.9.2_1'
Thread model: posix
gcc version 4.9.2 (MacPorts gcc49 4.9.2_1)

indicating that indeed gcc was now set to gcc 4.9. I next typed

make clean

make all_network

In this case, all the codes compiled because I was using the full gcc compiler suite (in my case, g++ and gfortran). I then tested compiling with clang++ and gfortran. I couldn't do this resetting gcc to clang by typing

sudo port select --set gcc none

source ~/.bash_profile

because that would make gfortran invisible again. (If you try this and then type gfortran -v, it will return command not found. You'll then need to port select back to mp-gcc49.) Instead, what I did was to change the compiler in the examples/network/Makefile to clang++ by editing the file to read:

 NNT_DIR = $(NUCNET_TARGET)/nnt
 USER_DIR = $(NUCNET_TARGET)/user
 BUILD_DIR = $(NUCNET_TARGET)/build

 GC = clang++

 #///////////////////////////////////////////////////////////////////////////////
 # End of lines to be edited.
 #///////////////////////////////////////////////////////////////////////////////

I typed

make clean

make run_single_zone

and the code built the C++ parts with clang++ and the fortran parts with gfortran. I note that the Makefile now explicitly links with libstdc++ when compiling with clang++ to get it to work with gfortran. run_multi_zone_omp.cpp did not compile again because the default clang++ compiler does not yet support openMP.

For the foreseeable future, I will continue to use the gnu compilers, so to restore the original Makefile and remake, I typed

svn revert Makefile

make clean

make all_network

Nevertheless, I will try to keep abreast of developments with the LLVM compilers since some users may prefer them.

Posted by Bradley S. Meyer 2015-02-09
  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous - 2015-11-10

    Dear Sir,
    I have trried as what you said, but I encountered the following errors:

    In file included from /opt/local/include/boost/lexical_cast/detail/converter_lexical.hpp:54:
    /opt/local/include/boost/lexical_cast/detail/converter_lexical_streams.hpp:210:17: error:
    unused typedef 'boost_static_assert_typedef_212'
    [-Werror,-Wunused-local-typedef]
    BOOST_STATIC_ASSERT_MSG(( sizeof(T) <= sizeof(CharT)),
    ^
    /opt/local/include/boost/static_assert.hpp:36:48: note: expanded from macro
    'BOOST_STATIC_ASSERT_MSG'

    define BOOST_STATIC_ASSERT_MSG( B, Msg ) BOOST_STATIC_ASSERT( B )

                                               ^
    

    /opt/local/include/boost/static_assert.hpp:170:16: note: expanded from macro
    'BOOST_STATIC_ASSERT'
    BOOST_JOIN(boost_static_assert_typedef_, LINE) BOOST_...
    ^
    /opt/local/include/boost/config/suffix.hpp:544:28: note: expanded from macro
    'BOOST_JOIN'

    define BOOST_JOIN( X, Y ) BOOST_DO_JOIN( X, Y )

                           ^
    

    /opt/local/include/boost/config/suffix.hpp:545:31: note: expanded from macro
    'BOOST_DO_JOIN'

    define BOOST_DO_JOIN( X, Y ) BOOST_DO_JOIN2(X,Y)

                              ^
    

    /opt/local/include/boost/config/suffix.hpp:546:32: note: expanded from macro
    'BOOST_DO_JOIN2'

    define BOOST_DO_JOIN2( X, Y ) X##Y

                               ^
    

    <scratch space="">:103:1: note: expanded from here
    boost_static_assert_typedef_212
    ^
    fatal error: too many errors emitted, stopping now [-ferror-limit=]
    20 errors generated.
    make: *** [../../obj/auxiliary.o] Error 1

     
    • Bradley S. Meyer

      I've created a Ticket for this issue.

       
  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous - 2015-11-10

    Dear sir,
    the same problem always come to my mac:

    In file included from ../../nnt/auxiliary.cpp:29:0:

    ../../nnt/auxiliary.h:37:33: fatal error: boost/tuple/tuple.hpp: No such file or directory

    #include <boost tuple="" tuple.hpp="">

    ^

    compilation terminated.

    make: *** [../../obj/auxiliary.o] Error 1

     
    • Bradley S. Meyer

      I've created a discussion post for this issue.

       
  • Bradley S. Meyer

    Mac users may also want to see this post.

     


Anonymous

Cancel  Add attachments





Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks