How to enable -mno-outline-atomics AArch64 flag? - c++

I've been trying to cross compile an open source library for AArch64.
When I run an executable linking against this library on a Raspberry Pi 4 (running a 64-bit OS), I get an Illegal Instruction error.
I created a github issue and the library developer suggested I enable the -mno-outline-atomics compiler flag (more details on the github issue here). More details on the flag itself can be found here.
So I edited the aarch64 cmake toolchain file (found here) to include the following:
set(CMAKE_C_FLAGS "-march=armv8-a -mno-outline-atomics")
set(CMAKE_CXX_FLAGS "-march=armv8-a -mno-outline-atomics")
However, when I try to compile the library, I get the following error messages:
-- CMAKE_TOOLCHAIN_FILE = /home/cyrus/work/c-sdks/3rd_party_libs/ncnn/toolchains/aarch64-linux-gnu.toolchain.cmake
-- CMAKE_INSTALL_PREFIX = /home/cyrus/work/c-sdks/3rd_party_libs/ncnn/build_aarch64/install
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/aarch64-linux-gnu-gcc
-- Check for working C compiler: /usr/bin/aarch64-linux-gnu-gcc - broken
CMake Error at /usr/local/share/cmake-3.17/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"/usr/bin/aarch64-linux-gnu-gcc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /home/cyrus/work/c-sdks/3rd_party_libs/ncnn/build_aarch64/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make cmTC_65def/fast && /usr/bin/make -f CMakeFiles/cmTC_65def.dir/build.make CMakeFiles/cmTC_65def.dir/build
make[1]: Entering directory '/home/cyrus/work/c-sdks/3rd_party_libs/ncnn/build_aarch64/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_65def.dir/testCCompiler.c.o
/usr/bin/aarch64-linux-gnu-gcc -march=armv8-a -mno-outline-atomics -o CMakeFiles/cmTC_65def.dir/testCCompiler.c.o -c /home/cyrus/work/c-sdks/3rd_party_libs/ncnn/build_aarch64/CMakeFiles/CMakeTmp/testCCompiler.c
aarch64-linux-gnu-gcc: error: unrecognized command line option ‘-mno-outline-atomics’; did you mean ‘-fno-inline-atomics’?
CMakeFiles/cmTC_65def.dir/build.make:82: recipe for target 'CMakeFiles/cmTC_65def.dir/testCCompiler.c.o' failed
make[1]: *** [CMakeFiles/cmTC_65def.dir/testCCompiler.c.o] Error 1
make[1]: Leaving directory '/home/cyrus/work/c-sdks/3rd_party_libs/ncnn/build_aarch64/CMakeFiles/CMakeTmp'
Makefile:138: recipe for target 'cmTC_65def/fast' failed
make: *** [cmTC_65def/fast] Error 2
Why is the compiler complaining about this: unrecognized command line option ‘-mno-outline-atomics’?
How can I properly enable the flag using CMake?

The outline-atomic feature was added with gcc 9.4.
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
Clearly, your compiler is too old and does not support it.

Related

CMake on MacOS 10.15 falls to link -- ld: unknown option: -platform_version

I am compiling a C++ application on CLion IDE using the Clang 12 from LLVM with CMake 3.20. MacOS version is 10.15.7.
The error I get is:
-- The C compiler identification is Clang 12.0.1
-- The CXX compiler identification is Clang 12.0.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /usr/local/Cellar/llvm/12.0.1/bin/clang-12
-- Check for working C compiler: /usr/local/Cellar/llvm/12.0.1/bin/clang-12 - broken
CMake Error at /Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.20/Modules/CMakeTestCCompiler.cmake:66 (message):
The C compiler
"/usr/local/Cellar/llvm/12.0.1/bin/clang-12"
is not able to compile a simple test program.
ld: unknown option: -platform_version
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [cmTC_ca485] Error 1
make: *** [cmTC_ca485/fast] Error 2
I was trying to solve the problem with the help of the following: Clang 10 fails to link C++ application with CMake on macOS 10.12 but to no avail.
It seems CMake is using the linker from /usr/bin/. Forcing it to use the one from the same directory where Clang 12 resides (by using -DCMAKE_LINKER="/usr/local/Cellar/llvm/12.0.1/bin/lld) doesn't help. Not sure if it is relevant but when I try to get the linker version by running ld64.lld -v I get the error message:
ld64.lld: error: -arch not specified and could not be inferred
Any help will be highly appreciated.

gcc-4.8 can't compile test program? [duplicate]

This question already has answers here:
g++: error trying to exec 'cc1plus': execvp: No such file or directory
(5 answers)
Closed 5 years ago.
I've installed gcc-4.8 on Ubuntu 16.04 to build a C++11 program. I have a CMakeList.txt file that worked well on OS X with Clang and GCC 4.8 built from Macports.
I started by setting CXX=/usr/bin/gcc-4.8 and then CMake fails with the following error:
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is unknown
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/gcc-4.8
-- Check for working CXX compiler: /usr/bin/gcc-4.8 -- broken
CMake Error at /usr/share/cmake-3.5/Modules/CMakeTestCXXCompiler.cmake:54 (message):
The C++ compiler "/usr/bin/gcc-4.8" is not able to compile a simple test
program.
It fails with the following output:
Change Dir: /home/ruipacheco/databaseclient/cpp/ninja/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_5df0c/fast"
/usr/bin/make -f CMakeFiles/cmTC_5df0c.dir/build.make
CMakeFiles/cmTC_5df0c.dir/build
make[1]: Entering directory
'/home/ruipacheco/databaseclient/cpp/ninja/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_5df0c.dir/testCXXCompiler.cxx.o
/usr/bin/gcc-4.8 -o CMakeFiles/cmTC_5df0c.dir/testCXXCompiler.cxx.o -c
/home/ruipacheco/databaseclient/cpp/ninja/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
gcc-4.8: error trying to exec 'cc1plus': execvp: No such file or directory
CMakeFiles/cmTC_5df0c.dir/build.make:65: recipe for target
'CMakeFiles/cmTC_5df0c.dir/testCXXCompiler.cxx.o' failed
make[1]: *** [CMakeFiles/cmTC_5df0c.dir/testCXXCompiler.cxx.o] Error 1
make[1]: Leaving directory
'/home/ruipacheco/databaseclient/cpp/ninja/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_5df0c/fast' failed
make: *** [cmTC_5df0c/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:6 (project)
-- Configuring incomplete, errors occurred!
Again, I know gcc-4.8 is capable of building C++11 programs and I've managed to make this CMakeLists.txt file work with gcc 4.8 on OSX so what could I be missing?
"gcc-4.8" is a C compiler, not a C++ compiler. You should set the CXX variable to "g++-4.8" or "g++" or some other C++ compiler executable.

cmake: why doesn't CMAKE_CXX_STANDARD seem to work with check_cxx_source_compiles

Here's an MCVE:
cmake_minimum_required(VERSION 3.1)
Project(Test)
include(CheckCXXSourceCompiles)
set (CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
#set (CMAKE_CXX_STANDARD_REQUIRED TRUE)
#set (CMAKE_CXX_STANDARD 11)
#set (CMAKE_CXX_EXTENSIONS FALSE)
check_cxx_source_compiles("
#include <atomic>
int main() {
std::atomic<int> u{5};
return u;
}" HAVE_STDLIB_ATOMIC)
if (NOT HAVE_STDLIB_ATOMIC)
message(FATAL_ERROR "Did not find std::atomic support!")
endif()
When I use the CMAKE_CXX_FLAGS version, it works fine, but when I use the new CMAKE_CXX_STANDARD flags which we are supposed to use now, it doesn't work, I get the following build errors:
$ cmake ..
-- The C compiler identification is GNU 5.4.1
-- The CXX compiler identification is GNU 5.4.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test HAVE_STDLIB_ATOMIC
-- Performing Test HAVE_STDLIB_ATOMIC - Failed
CMake Error at CMakeLists.txt:20 (message):
Did not find std::atomic support!
-- Configuring incomplete, errors occurred!
See also "/home/chris/cmake_test/build/CMakeFiles/CMakeOutput.log".
See also "/home/chris/cmake_test/build/CMakeFiles/CMakeError.log".
The error log indicates it's not using the -std=c++11 flag:
$ cat /home/chris/cmake_test/build/CMakeFiles/CMakeError.log
Performing C++ SOURCE FILE Test HAVE_STDLIB_ATOMIC failed with the following output:
Change Dir: /home/chris/cmake_test/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_42a05/fast"
/usr/bin/make -f CMakeFiles/cmTC_42a05.dir/build.make CMakeFiles/cmTC_42a05.dir/build
make[1]: Entering directory '/home/chris/cmake_test/build/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_42a05.dir/src.cxx.o
/usr/bin/c++ -DHAVE_STDLIB_ATOMIC -o CMakeFiles/cmTC_42a05.dir/src.cxx.o -c /home/chris/cmake_test/build/CMakeFiles/CMakeTmp/src.cxx
In file included from /usr/include/c++/5/atomic:38:0,
from /home/chris/cmake_test/build/CMakeFiles/CMakeTmp/src.cxx:2:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support \
^
/home/chris/cmake_test/build/CMakeFiles/CMakeTmp/src.cxx: In function ‘int main()’:
/home/chris/cmake_test/build/CMakeFiles/CMakeTmp/src.cxx:5:3: error: ‘atomic’ is not a member of ‘std’
std::atomic<int> u{5};
^
/home/chris/cmake_test/build/CMakeFiles/CMakeTmp/src.cxx:5:15: error: expected primary-expression before ‘int’
std::atomic<int> u{5};
^
/home/chris/cmake_test/build/CMakeFiles/CMakeTmp/src.cxx:6:10: error: ‘u’ was not declared in this scope
return u;
^
CMakeFiles/cmTC_42a05.dir/build.make:65: recipe for target 'CMakeFiles/cmTC_42a05.dir/src.cxx.o' failed
make[1]: *** [CMakeFiles/cmTC_42a05.dir/src.cxx.o] Error 1
make[1]: Leaving directory '/home/chris/cmake_test/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_42a05/fast' failed
make: *** [cmTC_42a05/fast] Error 2
Source file was:
#include <atomic>
int main() {
std::atomic<int> u{5};
return u;
}
My cmake version is:
$ cmake --version
cmake version 3.5.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
I can't figure out why cmake doesn't use the std=c++11 flag here, according to the docu, CMAKE_CXX_STANDARD is supposed to work since version 3.1.
Anyone know what's wrong here?
What's the most appropriate workaround? Should I use CMAKE_CXX_FLAGS adjustments for the tests, and CMAKE_CXX_STANDARD for the targets? It seems to me that the exact same configuration should be used for the tests and the targets, otherwise what's the point of the tests :/
According to documentation, you can set CMAKE_REQUIRED_FLAGS to make try_compile use C++11 flag.
Since CMake 3.8, you can add
cmake_policy(SET CMP0067 NEW)
(you do need CMAKE_CXX_STANDARD_REQUIRED=ON). See the CMake doc on CMP0067

CMake passes Visual C++ parameters to clang instead of expexted GCC ones

I'm trying to build the project under win10 using mingw latest toolchain and clang compilers (from CLion IDE) with explicitly specified compilers in commandline options :
-DCMAKE_C_COMPILER=C:/dev/tools/LLVM/bin/clang.exe
-DCMAKE_CXX_COMPILER=C:/dev/tools/LLVM/bin/clang++.exe
cmake recognize clang correctly, but during the test compilations tries to pass cl (Visual C++ compiler) flags:
C:\dev\tools\CLion.RC\bin\cmake\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=C:/dev/tools/LLVM/bin/clang.exe -DCMAKE_CXX_COMPILER=C:/dev/tools/LLVM/bin/clang++.exe -G "CodeBlocks - MinGW Makefiles" C:\Users\amigo421\ClionProjects\hr2
-- The C compiler identification is unknown
-- The CXX compiler identification is Clang 3.9.0
-- Check for working C compiler: C:/dev/tools/LLVM/bin/clang.exe
-- Check for working C compiler: C:/dev/tools/LLVM/bin/clang.exe -- broken CMake Error at
C:/dev/tools/CLion.RC/bin/cmake/share/cmake-3.6/Modules/CMakeTestCCompiler.cmake:61
(message): The C compiler "C:/dev/tools/LLVM/bin/clang.exe" is not
able to compile a simple test program.
It fails with the following output:
C:\dev\tools\LLVM\bin\clang.exe /DWIN32 /D_WINDOWS /W3 -o
CMakeFiles\cmTC_397ea.dir\testCCompiler.c.obj -c
C:\Users\amigo421\ClionProjects\hr2\cmake-build-debug\CMakeFiles\CMakeTmp\testCCompiler.c
**clang.exe: error: no such file or directory: '/DWIN32'**
**clang.exe: error: no such file or directory: '/D_WINDOWS'**
**clang.exe: error: no such file or directory: '/W3'**
CMakeFiles\cmTC_397ea.dir\build.make:64: recipe for target
'CMakeFiles/cmTC_397ea.dir/testCCompiler.c.obj' failed
mingw32-make.exe[1]: ***
[CMakeFiles/cmTC_397ea.dir/testCCompiler.c.obj] Error 1
mingw32-make.exe[1]: Leaving directory
'C:/Users/amigo421/ClionProjects/hr2/cmake-build-debug/CMakeFiles/CMakeTmp'
you see that cmake passes visual c++ flags , I don't plan to use clang-cl.
I suppose that cmake should use GCC (MinGW) parameters in command line
any idea how to fix this

CMake "clang++ is not able compile a simple test program" (Fedora 20)

So I tried to install clang + cmake to compile a simple C++ program and I'm getting the following error:
-- The C compiler identification is GNU 4.8.3
-- The CXX compiler identification is Clang 3.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/local/bin/clang++
-- Check for working CXX compiler: /usr/local/bin/clang++ -- broken
CMake Error at /usr/share/cmake/Modules/CMakeTestCXXCompiler.cmake:54 (message):
The C++ compiler "/usr/local/bin/clang++" is not able to compile a simple
test program.
It fails with the following output:
Change Dir: /home/jtcwang/tmp/CMake/CMake/CMakeFiles/CMakeTmp
Run Build Command:/usr/bin/gmake "cmTryCompileExec697180971/fast"
/usr/bin/gmake -f CMakeFiles/cmTryCompileExec697180971.dir/build.make
CMakeFiles/cmTryCompileExec697180971.dir/build
gmake[1]: Entering directory
`/home/jtcwang/tmp/CMake/CMake/CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report
/home/jtcwang/tmp/CMake/CMake/CMakeFiles/CMakeTmp/CMakeFiles 1
Building CXX object
CMakeFiles/cmTryCompileExec697180971.dir/testCXXCompiler.cxx.o
/usr/local/bin/clang++ -o
CMakeFiles/cmTryCompileExec697180971.dir/testCXXCompiler.cxx.o -c
/home/jtcwang/tmp/CMake/CMake/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
Linking CXX executable cmTryCompileExec697180971
/usr/bin/cmake -E cmake_link_script
CMakeFiles/cmTryCompileExec697180971.dir/link.txt --verbose=1
/usr/local/bin/clang++
CMakeFiles/cmTryCompileExec697180971.dir/testCXXCompiler.cxx.o -o
cmTryCompileExec697180971 -rdynamic
/usr/bin/ld: cannot find -lstdc++
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
gmake[1]: Leaving directory
`/home/jtcwang/tmp/CMake/CMake/CMakeFiles/CMakeTmp'
gmake[1]: *** [cmTryCompileExec697180971] Error 1
gmake: *** [cmTryCompileExec697180971/fast] Error 2
It's not even compiling my program because it fails to compile a test program.
Looks like the important line is here:
/usr/bin/ld: cannot find -lstdc++
However, I have checked that libstdc++ is installed and up to date, so at this point I'm quite lost.
Other things I've tried:
Using prebuilt binaries instead of sudo yum install clang
remove and reinstall
Tried clang++ hello.cpp (hello world program). It says <iostreams> is not found. Is clang missing a standard library? EDIT: changing to <iostream> gives me the same linker error above.
I'm not familiar with the clang, cmake and C++ scene in general, so I'd appreciate any pointers. Thanks!
You need the development libraries and headers for C++ library, try
yum install libstdc++-devel
Your /home/gnu/bin/c++ seem to require additional flag to link things properly and CMake doesn't know about that.
To use /usr/bin/c++ as your compiler run cmake with -DCMAKE_CXX_COMPILER=/usr/bin/c++.
Also, CMAKE_PREFIX_PATH variable sets destination dir where your project' files should be installed. It has nothing to do with CMake installation prefix and CMake itself already know this.