I am pretty new to the MacOS so any help would be greatly appreciated!
I am trying to compile a programme on my Mac (M1 chip with arm64 architecture, Mac OS Monterey) which requires x86_64 architecture and gfortran. I installed a x86_64 version of brew, clang, gcc, gsl and pkg-config. However I am getting an error where the compiler is unable to find the header file:
Running cmake.
CMake Deprecation Warning at CMakeLists.txt:2 (cmake_policy):
The OLD behavior for policy CMP0002 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
-- The C compiler identification is AppleClang 13.0.0.13000029
-- The CXX compiler identification is AppleClang 13.0.0.13000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The Fortran compiler identification is GNU 11.2.0
-- Checking whether Fortran compiler has -isysroot
-- Checking whether Fortran compiler has -isysroot - yes
-- Checking whether Fortran compiler supports OSX deployment target flag
-- Checking whether Fortran compiler supports OSX deployment target flag - yes
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Check for working Fortran compiler: /usr/local/bin/gfortran - skipped
-- Checking whether /usr/local/bin/gfortran supports Fortran 90
-- Checking whether /usr/local/bin/gfortran supports Fortran 90 - yes
Defaulting to gfortran
-- Found PythonInterp: /Users/lg268561/opt/anaconda3/envs/kcap_env/bin/python (found version "3.9.7")
-- Found PkgConfig: /usr/local/bin/pkg-config (found version "0.29.2")
-- Found GSL: /usr/local/Cellar/gsl/2.7/include (found suitable version "2.7", minimum required is "2.1")
-- Looking for gfortran related libraries...
-- Extracting library and header information by calling 'gfortran -v'...
-- 'gfortran -v' returned:
-- Using built-in specs.
COLLECT_GCC=/usr/local/bin/gfortran
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/11.2.0_1/libexec/gcc/x86_64-apple-darwin21/11.2.0/lto-wrapper
Target: x86_64-apple-darwin21
Configured with: ../configure --prefix=/usr/local/Cellar/gcc/11.2.0_1 --libdir=/usr/local/Cellar/gcc/11.2.0_1/lib/gcc/11 --disable-nls --enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran,d --program-suffix=-11 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-zstd=/usr/local/opt/zstd --with-pkgversion='Homebrew GCC 11.2.0_1' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --enable-libphobos --build=x86_64-apple-darwin21 --with-system-zlib --disable-multilib --without-build-config --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (Homebrew GCC 11.2.0_1)
-- Detected gfortran version 11.2.0
-- Architecture string: Target: x86_64-apple-darwin21
-- Detected gfortran architecture: x86_64-apple-darwin21
-- Detected gfortran prefix: /usr/local/Cellar/gcc/11.2.0_1
-- Detected default gfortran exec-prefix
-- Detected gfortran exec-prefix: /usr/local/Cellar/gcc/11.2.0_1
-- Found --libdir flag -- yes
-- gfortran libraries path: /usr/local/Cellar/gcc/11.2.0_1/lib/gcc/11
-- gfortran include path dir: /usr/local/Cellar/gcc/11.2.0_1/lib/gcc/11/gcc/x86_64-apple-darwin21/11.2.0/include
-- Found GFortranLibs: /usr/local/Cellar/gcc/11.2.0_1/lib/gcc/11/libgfortran.dylib (found version "11.2.0")
-- Looking for gfortran libraries -- found
-- gfortran version: 11.2.0
CMake Deprecation Warning at cosebis/CMakeLists.txt:5 (cmake_policy):
The OLD behavior for policy CMP0002 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
GSL_INC:/usr/local/Cellar/gsl/2.7/include
GSL_LIB:/usr/local/Cellar/gsl/2.7/lib
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/lg268561/Downloads/kcap/build
Running make.
[ 0%] Built target GSL
[ 5%] Running make for cosebis
make[3]: Entering directory `/Users/lg268561/Downloads/kcap/cosebis'
make[4]: Entering directory `/Users/lg268561/Downloads/kcap/cosebis/modules'
clang: warning: -lgsl: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lgslcblas: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-L/usr/local/Cellar/gsl/2.7/lib' [-Wunused-command-line-argument]
matrix.cc:1:10: fatal error: 'unistd.h' file not found
#include "unistd.h"
^~~~~~~~~~
1 error generated.
Attempts at a solution from reading off the web:
-When I check the gfortran include path directories, the header file is there.
-Delete everything in the /Library/Developer/CommandTools/ directory and reran xcode-select --install but the error persists.
-I've aliased my gcc and clang to the x86_64 versions, located in the /usr/local/ directory. gcc -v gives:
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 13.0.0 (clang-1300.0.29.3)
Target: x86_64-apple-darwin21.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
and clang -v gives:
Apple clang version 13.0.0 (clang-1300.0.29.3)
Target: x86_64-apple-darwin21.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
I've symlinked every version of MacOSX.sdk in my SDKs/ folder. The problem still persists.
Edit
I checked the CMake error log:
Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler: /Library/Developer/CommandLineTools/usr/bin/cc
Build flags:
Id flags:
The output was:
1
ld: library not found for -lSystem
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: /Library/Developer/CommandLineTools/usr/bin/c++
Build flags:
Id flags:
The output was:
1
ld: library not found for -lc++
clang: error: linker command failed with exit code 1 (use -v to see invocation)
could it be a problem with linked libraries instead?