Compilation errors with M1 MacBook Pro and cmake - c++

I have just got my new M1 MacBook Pro and am trying to compile a code base required for my university work. Here are the steps I have taken:
I set Terminal to always open using Rosetta.
Installed homebrew using /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Installed cmake using brew install cmake
Run cmake <path to source> (this works fine)
Run make (this fails)
Here is the error I get:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/stdlib.h:97:15: fatal error:
'stdlib.h' file not found
#include_next <stdlib.h>
I have tried uninstalling and re-installing Xcode and CommandLineTools to no avail.
When using the cmake gui app, I get a different error. I have it set to use CommandLineTools/SDKs/MacOsX11.0.sdk.
When running make after generating and configuring the build files using this cmake gui setup, I get this error:
-- The C compiler identification is AppleClang 12.0.0.12000032
-- The CXX compiler identification is AppleClang 12.0.0.12000032
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - broken
CMake Error at /Applications/CMake.app/Contents/share/cmake-3.18/Modules/CMakeTestCCompiler.cmake:66 (message):
The C compiler
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /Users/freyamurphy/nori/build/ext_build/src/tbb_p-build/CMakeFiles/CMakeTmp
If I run the command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc test.c (Simple hello world program) I get this error:
test.c:1:10: fatal error: 'stdio.h' file not found
#include "stdio.h"
But using cc test.c everything works fine. (This runs usr/bin/cc).
Seems to me there is perhaps an issue with Xcode. Has anyone had any similar issues or could give me some advice? It would be much appreciated.

Have you reopen Terminal after xcode installed? It's needed to set the environment variable SDKROOT.
Close and run again Terminal or open a new tab in Terminal.
Or run the following command in the current Terminal
export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
Also be sure the proper xcode toolchain is selected
# list available xcode toolchains
xcode-select -p
# select one of listed above
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

Related

cmake .. -G Xcode suddenly fails with the project it used to work with

I have a project, where I used to do cmake .. -G Xcode to build for Xcode and it used to work fine. I haven't touched the project for a month or so and when I ran the same command today I got an error below.
The only thing I changed since the last time I built the project was doing some Rust tutorial, so I installed some things for Rust, but I don't remember what exactly.
What could have happened?
-- The C compiler identification is AppleClang 12.0.0.12000032
-- The CXX compiler identification is AppleClang 12.0.0.12000032
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -- broken
CMake Error at /usr/local/Cellar/cmake/3.16.4/share/cmake/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /Users/path-to-project/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/xcodebuild -project CMAKE_TRY_COMPILE.xcodeproj build -target cmTC_a8107 -configuration Debug -hideShellScriptEnvironment && Command line invocation:
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project CMAKE_TRY_COMPILE.xcodeproj build -target cmTC_a8107 -configuration Debug -hideShellScriptEnvironment
User defaults from command line:
HideShellScriptEnvironment = YES
Prepare build
note: The Legacy Build System will be removed in a future release. You can configure the selected build system and this deprecation message in File > Project Settings.
=== BUILD TARGET cmTC_a8107 OF PROJECT CMAKE_TRY_COMPILE WITH CONFIGURATION Debug ===
Check dependencies
No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=arm64, VALID_ARCHS=arm64 arm64e i386 x86_64, EXCLUDED_ARCHS=(
arm64,
arm64e
)).
** BUILD FAILED **
The following build commands failed:
Check dependencies
(1 failure)
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
-- Configuring incomplete, errors occurred!
See also "/Users/path-to-project/build/CMakeFiles/CMakeOutput.log".
See also "/Users/path-to-project/build/CMakeFiles/CMakeError.log".
Updating cmake to the latest version (3.18.4) resolved the problem for me.

CMake can not find g++ compiler on Windows

I have a CMake project I want to compile with g++. The project compiles and runs on Linux. Now I am trying to get it working on Windows.
For that reason, I installed MinGW and added it to the PATH and I am using Git Bash. In order to force CMake to use g++ I added these env variables:
CC = C:\MinGW\bin\gcc
CXX = C:\MinGW\bin\g++
But when I run CMake it does not detect any compilers and tells me:
-- The C compiler identification is unkown
-- The CXX compiler identification is unkown
I created a super basic example on github which I would like to get running on Windows + MinGw: https://github.com/j-o-d-o/Basic-CMake-Project
How can I use the env variables in windows to force CMake to use g++ and gcc compiler?
I needed to add -G "MinGW Makefiles" to the CMake command.
I check if I am on Windows and if yes, I add the parameter to the CMake command in the shell script.
I also need to use mingw32-make instead of make when I am on Windows.
There are some other issues now, but it resolves the issue/question I have posted.

how to get cmake to use the gnu stack of tools under msys2 (mingw)

On Windows 10, with an installed msys2, which is a variant of mingw, I have an installed cmake with the gcc toolchain and all the standard tools like make.
The version of g++ is 6.2 and make is 4.2.1 Both are in the path.
When I build using cmake:
cmake .
it tries to build using nmake and cl. So somehow because I am on windows cmake is trying to use the visual studio toolchain.
export CMAKE_CXX_COMPILER=g++
does not help. The error is:
-- Building for: NMake Makefiles
-- The C compiler identification is unknown
-- The CXX compiler identification is Clang 3.8.0
-- Check for working C compiler: D:/msys64/mingw64/bin/clang++.exe
CMake Error: Generator: execution of make failed. Make command was: "nmake" "/NOLOGO" "cmTC_87e5f\fast"
-- Check for working C compiler: D:/msys64/mingw64/bin/clang++.exe -- broken
CMake Error at D:/msys64/mingw64/share/cmake-3.6/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler "D:/msys64/mingw64/bin/clang++.exe" is not able to compile a
simple test program.
It fails with the following output:
Change Dir: D:/git/CSP/CMakeFiles/CMakeTmp
Run Build Command:"nmake" "/NOLOGO" "cmTC_87e5f\fast"
Generator: execution of make failed. Make command was: "nmake" "/NOLOGO"
"cmTC_87e5f\fast"
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (project)
-- Configuring incomplete, errors occurred!
See also "D:/git/CSP/CMakeFiles/CMakeOutput.log".
See also "D:/git/CSP/CMakeFiles/CMakeError.log".
To use MSYS2 toolchain, you need to specify the build system generator explicitly, i.e.
cmake -G 'MSYS Makefiles' .
Additional note, it's a good practice to separate the application . source file and cmake's generated file, e.g.
mkdir build
cd build
cmake -G 'MSYS Makefiles' ..

QT GCC Error During Cross Compile Setup

I have been working this problem for more than a week. I installed the free version of QT off the QT site. I am trying to set up a cross compile environment for a Beaglebone Black ARM 8 platform. I have set up the compiler options using GNU ARM 6.3.0 GNU compiler -- The same compiler that is on my BBB. I successfully created the cross-compile environment and the Beaglebone device. The connect test worked correctly as well.
Here is the simple C++ application that I am trying to compile,
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
Here is what my QT gcc compile options look like,
Here is my kit setup,
Here is my device setup,
When I build the default QT simple application I get these errors,
Running Windows Runtime device detection.
C:/Qt/5.11.0/winrt_armv7_msvc2015/bin/winrtrunner.exe --list-devices
Found 2 Windows Runtime devices.
Running "C:\Program Files (x86)\CMake\bin\cmake.exe -E server "--pipe=\.\pipe{2e664e46-cacb-46ae-b680-ed9c235dc502}" --experimental" in C:\Users\Stephen\AppData\Local\Temp\QtCreator-WLEKuI\qtc-cmake-IDzcFnnJ.
Starting to parse CMake project, using: "-DCMAKE_CXX_COMPILER:STRING=C:/SysGCC/beaglebone-6.3.0/bin/arm-linux-gnueabihf-g++.exe", "-DCMAKE_C_COMPILER:STRING=C:/SysGCC/beaglebone-6.3.0/bin/arm-linux-gnueabihf-gcc.exe", "-DCMAKE_PREFIX_PATH:STRING=", "-DQT_QMAKE_EXECUTABLE:STRING=".
The C compiler identification is GNU 6.3.0
The CXX compiler identification is GNU 6.3.0
Check for working C compiler: C:/SysGCC/beaglebone-6.3.0/bin/arm-linux-gnueabihf-gcc.exe
Check for working C compiler: C:/SysGCC/beaglebone-6.3.0/bin/arm-linux-gnueabihf-gcc.exe -- broken
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:52 (message):
The C compiler
"C:/SysGCC/beaglebone-6.3.0/bin/arm-linux-gnueabihf-gcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/Stephen/AppData/Local/Temp/QtCreator-WLEKuI/qtc-cmake-IDzcFnnJ/CMakeFiles/CMakeTmp
Run Build Command:"C:/PROGRA~2/Ninja/ninja.exe" "cmTC_c3136"
[1/2] Building C object CMakeFiles/cmTC_c3136.dir/testCCompiler.c.obj
[2/2] Linking C executable cmTC_c3136.exe
FAILED: cmTC_c3136.exe
cmd.exe /C "cd . && C:\SysGCC\beaglebone-6.3.0\bin\arm-linux-gnueabihf-gcc.exe CMakeFiles/cmTC_c3136.dir/testCCompiler.c.obj -o cmTC_c3136.exe -Wl,--out-implib,libcmTC_c3136.dll.a -Wl,--major-image-version,0,--minor-image-version,0 && cd ."
c:/sysgcc/beaglebone-6.3.0/bin/../lib/gcc/arm-linux-gnueabihf/6/../../../../arm-linux-gnueabihf/bin/ld.exe: unrecognized option '--major-image-version'
c:/sysgcc/beaglebone-6.3.0/bin/../lib/gcc/arm-linux-gnueabihf/6/../../../../arm-linux-gnueabihf/bin/ld.exe: use the --help option for usage information
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
The build seems to issues a command to the GCC compiler suite to an executable called ld.exe. I verified the path to ld.exe and it is indeed in the directory and handles my "ld --version" command.The error messages show ld.exe '--major-image-version' and fails. ld.exe does not support --major-image-version. Not sure why it is issuing this command to ld.exe.
I know these compilers work as I have manually compiled this program using g++ 6.3.0 compiler. Any suggestions?
A make argument is wrong. Specifically:
unrecognized option '--major-image-version'
You should remove the argument "--major-image-version" from your project's Makefile LFLAGS.
On windows there are 3 makefiles, Makefile, Makefile.debug and Makefile.release
Remove the argument from the one matching your current build config.

How to build flatbuffers on OSX?

I'm trying to build flatbuffers on OSX but I'm not sure how to proceed exactly. According to the doc. I should run cmake -G "Xcode". I did that and got the result:
-- The C compiler identification is Clang 5.1.0
-- The CXX compiler identification is Clang 5.1.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
-- Configuring done
-- Generating done
-- Build files have been written to: Temp/flatbuffers
However from there I'm not sure what to do. I've tried to run make but got the error message make: *** No targets specified and no makefile found. Stop.. Any idea how to build it?
When you ran cmake, you generated a project for the Xcode IDE (downloadable from the Apple app store).
If you want to build using make, use this command instead:
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
After that,
make
should work as intended.
Instead make, just run following command in the shell:
$ cmakexbuild
After it finish you will get flatc in ./Debug folder.
On OSX it's recommended to use Homebrew to install the flatbuffer schema compiler.
brew install flatbuffers
Usage: Using the schema compiler
For Mac-OSX
Make sure Xcode is already installed in your machine. If not, install it by executing command xcode-select --install.
If you need latest changes download source code from repo or to get source code for a particular version download source from here
cd flatbuffers and execute cmake -G "Xcode" -DCMAKE_BUILD_TYPE=Release
If you encounter error like
CMake Warning:
No source or binary directory provided. Both will be assumed to be the
same as the current working directory, but note that this warning will
become a fatal error in future CMake releases.
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:6 (project):
No CMAKE_C_COMPILER could be found.
CMake Error at CMakeLists.txt:6 (project):
No CMAKE_CXX_COMPILER could be found.
-- Configuring incomplete, errors occurred!
See also "<sourc-code-path>/flatbuffers-1.12.0/CMakeFiles/CMakeOutput.log".
See also "<sourc-code-path>/flatbuffers-1.12.0/CMakeFiles/CMakeError.log".
Inside the log file CMakeError.log:
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
then refer this SO thread
success message is :
-- Configuring done
-- Generating done
-- Build files have been written to: <source-code-path>/standalone/flatbuffers-1.12.0
./FlatBuffers.xcodeproj or open project in xcode
Build and Run project from Xcode UI
cd Debugand you can see all the binaries present.
If you want flatc to be available globally:
ln -sf <path>/flatbuffers-1.12.0/Debug/flatc /usr/local/bin/flatc
Tried and Tested on
MacOSX: Mojave, version: 10.14.3, 10.14.6
Xcode: Version: 10.2.1(10E1001), 11.1(11A1027)
Note: Make sure you use the same version in a project for compatibility.
If you are not sure which version to pick, then you can clone the repo and go to a specific commit and build.
For e.g. For version 1.11, Commit version is bf9eb67a.
Follow the below steps to compile the flatbuffer code
Clone the Flatbuffer repo using - git clone https://github.com/google/flatbuffers.git
cd flatbuffers
cmake -G "Unix Makefiles"
make
FlatBuffers for LINUX(Ubuntu 16) install and build:
cd root project folder
yarn add flatc
cd node_modules of project
rm flatbuffers folder(if exist)
git clone https://github.com/google/flatbuffers.git
cd flatbuffers
cmake -G "Unix Makefiles" (install cmake if need)
make
cd root project folder
change path in command in package.json file from "./flatc" to "./node_modules/flatbuffers/flatc"