cmake build failed on macos catalina 10.15 - macos

I have recently installed macos catalina with Xcode 11.1 and updated cmake, clang and llvm
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
$ cmake --version
cmake version 3.15.4
$ which cmake
/usr/local/bin/cmake
$ clang --version
Apple clang version 11.0.0 (clang-1100.0.33.8)
Target: x86_64-apple-darwin19.0.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$ which clang
/usr/bin/clang
The CMakeLists.txt looks as bellow:
cmake_minimum_required(VERSION 3.14)
project("ROZZETA" VERSION 0.0.1 LANGUAGES C)
# Allow us to import cmake scripts from ./cmake
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}")
# Compiler flags
set(CMAKE_C_COMPILER /usr/bin/clang CACHE PATH "")
find_package(GMP REQUIRED)
add_executable(Rozzeta main.c)
target_link_libraries(Rozzeta gmp libgmp libgmp.a)
cmake detected gmp successfully :
/usr/local/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=c++ -G "CodeBlocks - Unix Makefiles" /<path to project>
-- The C compiler identification is AppleClang 11.0.0.11000033
-- Check for working C compiler: /usr/bin/clang
-- Check for working C compiler: /usr/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Using toolchain file: .
-- Found GMP: /usr/local/include/gmp.h and /usr/local/lib/libgmp.a
-- Configuring done
-- Generating done
build failed :
cmake --build .
Scanning dependencies of target Rozzeta
[ 50%] Building C object CMakeFiles/Rozzeta.dir/main.c.o
/Users/gajaka/CLionProjects/Rozzeta/main.c:4:10: fatal error: 'gmp.h' file not found
#include <gmp.h>
^~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/Rozzeta.dir/main.c.o] Error 1
make[1]: *** [CMakeFiles/Rozzeta.dir/all] Error 2
make: *** [all] Error 2
I have compiled manually with:
cc main.c -lgmp
Anyone can help me with this ?
Many thanks in advance

It was very frustrating for me! I am personally using CLion from jetbrains, while tried to build old codes written in C/C++, it's giving me error because MacOS 10.15, Catalina removed the C headers pkg used to be in Mojave. So, found another way around and tried.
If you have installed XCode 11.1, then open the terminal and run the following command:
xcode-select --install
then,
sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/* /usr/local/include/
Now, you are good to go. Try to build using cmake.

If you're calling find_package(GMP ...) in your CMake file, why not use the GMP-specific variables it populates? It looks like CMake successfully finds GMP installed on your system (based on your CMake log), so try using the GMP_* variables that should be populated:
cmake_minimum_required(VERSION 3.14)
project("ROZZETA" VERSION 0.0.1 LANGUAGES C)
# Allow us to import cmake scripts from ./cmake
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}")
# Compiler flags
set(CMAKE_C_COMPILER /usr/bin/clang CACHE PATH "")
find_package(GMP REQUIRED)
add_executable(Rozzeta main.c)
# Use the populated GMP variables here.
target_include_directories(Rozzeta PRIVATE ${GMP_INCLUDE_DIR})
target_link_libraries(Rozzeta PRIVATE ${GMP_LIB})

after
xcode-select --install
I got a clang but no cmake so I did
brew install cmake
which installed cmake for Catalina.

In order to compile programs with cmake and XCode's toolchain in Mac OS 10.15 (Catalina) you must install xcode command line utility tools + make some additional symlinks (#Roy said about it, but forgot to mention other two):
$ xcode-select --install
$ sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/* /usr/local/include/
$ for i in {Platforms,Toolchains,Tools}; do sudo ln -sn /Applications/Xcode.app/Contents/Developer/$i /Library/Developer/CommandLineTools/$i; done

Related

"CMAKE_CXX_COMPILER broken" while compiling with CMake

I'm trying to compile a Git project, and I'm facing some problems with CMake. Initially, it didn't find the C++ compiler and prompted an error:
cmake ..
No CMAKE_CXX_COMPILER could be found.
Tell CMake where to find the compiler by setting either the environment variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path to the compiler, or to the compiler name if it is in the PATH.
So, I did:
CXX="gcc" cmake ..
But another error was prompted:
-- The CXX compiler identification is unknown
-- Check for working CXX compiler: /usr/bin/gcc
-- Check for working CXX compiler: /usr/bin/gcc -- broken
CMake Error at /usr/share/cmake-3.0/Modules/CMakeTestCXXCompiler.cmake:54 (message):
The C++ compiler "/usr/bin/gcc" is not able to compile a simple test program.
How can I solve this error and compile the project?
You should try installing build-essential if you haven't done so.
Try this
sudo apt-get update
sudo apt-get install -y build-essential
You are trying to use C compiler gcc as C++ one, which is wrong.
You need to install g++ or other C++ compiler.

Compiling C Library for iOS 9 From Command Line, Xcode 7-beta 2

I am having trouble compiling a C library (gmp) for iOS 9 using the latest Xcode 7-beta clang. I am trying to produce bitcode to get all the warnings in Xcode to stop (and I would like to produce these libraries in bitcode). However, I can't even compile the library in the first place. ./configure fails, and after looking at the config.log, it seems ld is the problem as it is failing with "ld: library not found for -lSystem". Here is the command I have used to compile gmp in the past :
./configure CC=clang CPP="/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xct‌​oolchain/usr/bin/clang -E" CPPFLAGS="-isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Deve‌​loper/SDKs/iPhoneOS.sdk/ -L /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Deve‌​loper/SDKs/iPhoneOS.sdk/usr/lib/ -miphoneos-version-min=7.0 -arch armv7 -target arm-apple-darwin
The
-L /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Deve‌​loper/SDKs/iPhoneOS.sdk/usr/lib/
flag I added is to see if that would help with ld finding the required libraries to link, but it fails with the same error whether I include that option or not. I have not include the option to compile into bitcode in the above command, as I I can't even get it to compile in the first place using the same command I used to use. I have noticed that when I add the gmp .a files to xcode under "link binary with libraries", that ld can't find the libraries. I must manually add the project to the ld search path in the project settings for ld to find the libraries. This wasn't necessary in Xcode 6, so is it just ld being buggy in the current beta, or is there anything I can do?
Okay, here is what worked. Set your xcode development to use the new compilers using
sudo xcode-select -s /Applications/Xcode-beta.app
Then, I used this configure :
./configure CC=clang CPP="/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -E" CPPFLAGS="-isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/ -fembed-bitcode -miphoneos-version-min=7.0 -arch armv7 -target arm-apple-darwin" --host=aarch64-apple-darwin --disable-assembly --enable-static --disable-shared --disable-thread-safe --enable-cxx
The above works when compiling mpfr and mpc also.

error: <atomic> is not implemented in LLVM version 5.1

I'm trying to compile libcxxabi with cmake, and running into issues. I believe that this is because I don't have a separate copy of llvm installed that has llvm-config. So I've checked out llvm, and am trying to build that with cmake. I get the error:
CMake Error at cmake/modules/HandleLLVMOptions.cmake:37 (message):
Host Clang must be able to find libstdc++4.7 or newer!
And cmake/modules/HandleLLVMOptions.cmake:37 is literally a block like:
check_cxx_source_compiles("
#include <atomic>
std::atomic<float> x(0.0f);
int main() { return (float)x; }"
LLVM_NO_OLD_LIBSTDCXX)
if(NOT LLVM_NO_OLD_LIBSTDCXX)
message(FATAL_ERROR "Host Clang must be able to find libstdc++4.7 or newer!")
endif()
and if I try to compile the 3 liner with the compiler flag -std=c++0x (which is higher up in the cmake file) I get the error:
atomic.cpp:1:10: fatal error: 'atomic' file not found
#include <atomic>
^
1 error generated.
How is it that I don't have support for c++11 atomics? I'm running OSX 10.8.5, upgraded from 10.8.4, and XCode version 5.1.1, and clang++ 5.1 (clang-503.0.40) (based on LLVM 3.4svn). I have no options to upgrade xcode in the app store, nor the developer tools. Do I need to reinstall XCode, or upgrade to Mavericks?
I needed to check out all of LLVM and pass an additonal command line argument to CMake.
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
cd llvm/tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
cd ../projects
svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
cd ..
mkdir build
cd build
cmake .. -DLLVM_ENABLE_LIBCXX=ON
make
make install
Had the same issue with xCode 6.4. When using atomic in a simple helloWorld program it worked, but when using a project generated by CMake, I had the "#error is not implemented"
It appears CMake needs special flags to enable c++11 on mac... So, did exactly (almost... replaced if(UNIX) by if(APPLE)) as kitware indicates here:
https://cmake.org/Wiki/CMake/Tutorials/C%2B%2B11Flags
In case the link stops working one day....
cmake_minimum_required(VERSION 2.6)
PROJECT(Test)
if(UNIX)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=gnu++0x")
endif()
# MSVC does not require any special flags

cmake of "libarchive" fails on OSX Maverick

I'm trying to compile libarchive using cmake -G Xcode libarchive according to the official build instructions
I ve cmake 2.8.12 installed via mac port and use the current CMakeList.txt
cmake -G Xcode libarchive outputs
-- The C compiler identification is Clang 5.0.0
-- The CXX compiler identification is Clang 5.0.0
-- Check for working C compiler using: Xcode
-- Check for working C compiler using: Xcode -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Xcode
-- Check for working CXX compiler using: Xcode -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at CMakeLists.txt:177 (SET_TARGET_PROPERTIES):
set_target_properties called with incorrect number of arguments.
CMake Error at CMakeLists.txt:193 (INSTALL_MAN):
Unknown CMake command "INSTALL_MAN".
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as
cmake_minimum_required(VERSION 2.8)
should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it.
Configure from the top-level directory (the one containing the README file):
$ cmake -G Xcode .
the subsidiary CMakeLists.txt files in various directories are not complete and cannot be used by themselves.

Building GCC 4.8.2 in OS X 10.9

I'm trying to compile and install GCC 4.8.2 in OS X 10.9. I followed the instructions here (http://gcc.gnu.org/wiki/InstallingGCC) to first run ./contrib/download_prerequesites and then ran configure and make from a directory different from the source. My build fails with error:
checking for suffix of object files... configure: error: in `/Users/prokilogrammer/temp/gcc-build482/x86_64-apple-darwin13.0.2/libgcc':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details.
Apparently this problem would be solved if GCC's dependencies (GMP, MPC, MPFR) are properly installed (http://gcc.gnu.org/wiki/FAQ#configure_suffix). I checked and made sure they are correctly installed under /usr/local/lib & /usr/local/include directories.
Looking at config.log, I see the following errors:
configure:3565: checking for suffix of object files
configure:3587: /Users/prokilogrammer/temp/gcc-build482/./gcc/xgcc -B/Users/prokilogrammer/temp/gcc-build482/./gcc/ -B/usr/local/x86_64-apple-darwin13.0.2/bin/ -B/usr/local/x86_64-apple-darwin13.0.2/lib/ -isystem /usr/local/x86_64-apple-darwin13.0.2/include -isystem /usr/local/x86_64-apple-darwin13.0.2/sys-include -c -g -O2 conftest.c >&5
conftest.c:1:0: internal compiler error: Segmentation fault: 11
/* confdefs.h */
^
libbacktrace could not find executable to open
I am not sure if the segfault is because of the missing dependencies or a legit issue in gcc.
Have you guys experienced similar problems? Is there a solution/workaround?
PS: I have also tried setting LD_LIBRARY_PATH & DYLD_LIBRARY_PATH without any luck.
I've built GCC 4.8.2 on several Mavericks machines, but I chose a slightly different strategy. Specifically, I included the code for GMP, MPC, MPFR (and CLOOG and ISL) in the build directory. I used a script to quasi-automate it:
GCC_VER=gcc-4.8.2
tar -xf ${GCC_VER}.tar.bz2 || exit 1
cd ${GCC_VER} || exit
cat <<EOF |
cloog 0.18.0 tar.gz
gmp 5.1.3 tar.xz
isl 0.11.1 tar.bz2
mpc 1.0.1 tar.gz
mpfr 3.1.2 tar.xz
EOF
while read file vrsn extn
do
tar -xf "../$file-$vrsn.$extn" &&
ln -s "$file-$vrsn" "$file"
done
With that done:
mkdir gcc-4.8.2-obj
cd gcc-4.8.2-obj
../gcc-4.8.2/configure --prefix=$HOME/gcc/v4.8.2
make -j8 bootstrap
AFAICR, that was about all it took, with 4.8.1 and 4.8.2.

Resources