Skip to content
Lori A. Burns edited this page Apr 28, 2017 · 13 revisions

STOP! This page is out-of-date and is superseded by the docs

C++ and C Compilers

In Psi4, a C++ compiler is vital for building the code.

Examples

  • #####Build with Auto-detected Compilers in $PATH

    setup
    
  • #####Build with Specific (Intel) Compilers in $PATH

    setup --cc icc --cxx icpc
    
  • #####Build with Specific (GNU) Compilers not in $PATH

    setup --cc /opt/gcc480/bin/gcc --cxx /opt/gcc480/bin/g++
    
  • #####Build with OpenMP Clang on Mac

setup --cc /path/to/bin/clang-omp --cxx /path/to/bin/clang-omp ```


Imposing your will upon CMake

  • #####Relevant setup Options:

    --cc STRING                    set the C compiler [default: pick automatically or
                                   based on CC=...] (default: None)
    --cxx STRING                   set the C++ compiler [default: pick automatically or
                                   based on CXX=...] (default: None)
    --extra-cc-flags STRING
                                   additional C flags [default: None]
    --extra-cxx-flags STRING
                                   additional C++ flags [default: None]
    --custom-cc-flags STRING
                                   replacement [default: None]
    --custom-cxx-flags STRING
                                   replacement [default: None]
    
  • #####Relevant cmake Options:

    -DCMAKE_C_COMPILER=STRING      - C compiler
    -DCMAKE_CXX_COMPILER=STRING    - C++ compiler
    -DEXTRA_C_FLAGS="STRING"       - additional C flags
    -DEXTRA_CXX_FLAGS="STRING"     - additional C++ flags
    -DCUSTOM_C_FLAGS="STRING"      - replacement C flags
    -DCUSTOM_CXX_FLAGS="STRING"    - replacement C++ flags
    

Notes and FAQ

  • Dependency Status: Required

  • ##### What C and C++ compilers are approved

    • On Linux, gcc/g++ (GNU; default) and icc/icpc (Intel) work nicely.
    • On Mac, clang (Apple; default) and icc/icpc (Intel) work nicely.
  • ##### What GCC fundamental libraries are approved

    Even building with Intel compilers relies on fundamental libraries like libgcc and libc++, so its version (gcc --version) matters.

    • 4.7 and 4.8 work nicely.
    • 4.6 has reported problems.
    • 5.1 has reported problems building (basisset.cc) and linking with Boost (which isn't building against 5 yet).
  • ##### What are known contraindicated Intel icpc versions

    • An error identifier "__is_trivial" is undefined has been reported with 12.0.2 that is fixed by 12.0.4
    • C++11 errors have been reported with 13.0.1
    • If you are willing to live without some Psi4 features, for icpc 13.2, I was able to compile the code by changing the following C++11 lines:
      • Comment out lines 439 through 441 of src/bin/fisapt/fisapt.cc
      • Remove the "=false" part of lines 61 through 63 src/bin/optking/frag_apply_frozen_constraints.cc
      • It probably goes without saying, but in case it doesn't, don't use these parts of the code (SAPT and geometry optimzations) after making these changes.
  • ##### How to set C and C++ compiler flags for the whole project and plugins

    1. specifying the build type via setup --type=[{release,debug,profile}] sets some sensible defaults from CXXFlags.cmake and CFlags.cmake for the three cases.
    2. OR by specifying the build type and some --extra-cc-flags and/or --extra-cxx-flags to be appended to the default flags. No checks are performed for compatibility with the defaults.
    3. OR by specifying --custom-cc-flags and/or --custom-cxx-flags to replace the default flags. No checks are performed for suitability.
  • Packages to install for specific OS or package managers:

    • Ubuntu g++
  • ##### How to obtain C and C++ compilers for Mac without Fink, MacPorts, or Homebrew

    The easiest compiler to obtain is clang which is a drop-in replacement for gcc and g++. Just install XCode. OS X Mavericks and Yosemite are approved; XCode on older versions can't handle some of the advanced C++ language features. Note that this is a software not hardware limitation. As of June 2015, Psi4 can be compiled on a ca. 2009 Mac with approved OS.