Is there a way to use the Clang compiler while mixing C++ and Fortran?
Until now I use cmake with
project(mixing CXX Fortran)
but this triggers the use of g++
.
-- The CXX compiler identification is GNU 6.2.0
CMakeLists.txt of my project with Fortran mixing:
cmake_minimum_required(VERSION 3.7.0)
project(mixing CXX Fortran)
# SET UP ROOT https://root.cern.ch/how/integrate-root-my-project-cmake
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} /opt/local/libexec/root6/etc/root/cmake)
find_package(ROOT REQUIRED COMPONENTS MATH MINUIT2)
include(${ROOT_USE_FILE})
include_directories(Experiment Theory ${ROOT_INCLUDE_DIRS})
add_executable(mixing main.cpp)
target_link_libraries(mixing ${ROOT_LIBRARIES})
Not working, because g++ cannot use the needed Clang flag -stdlib=libc++
of the ROOT library.
You can always override c/c++ compiler by changing CMAKE_<LANG>_COMPILER, where <LANG> in your case is C or CXX.
CC
and CXX
environment variables to override defaults for CMAKE_C_COMPILER / CMAKE_CXX_COMPILER:CC=clang CXX=clang++ cmake
cmake -D CMAKE_C_COMPILER=clang -D CMAKE_CXX_COMPILER=clang++
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
make sure however that you do that at the very top of your cmake file before any project/enable_language directive is used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With