CMake ignoring compilation flags [duplicate] - c++

This question already has answers here:
Passing compiler options in CMake
(6 answers)
Closed 10 months ago.
I'm trying to compile assimp using MinGW.
I run the commands
cmake CMakeLists.txt -G "MinGW Makefiles" -Wno-error
cmake --build .
but when the project builds I still get an error and the build fails.
The error:
In file included from C:\godijustwantittowork\include\assimp-5.2.3\contrib\unzip\ioapi.c:22:
C:\godijustwantittowork\include\assimp-5.2.3\contrib\unzip\ioapi.c: In function 'ftell64_file_func':
C:\godijustwantittowork\include\assimp-5.2.3\contrib\unzip\ioapi.h:39:21: error: implicit declaration of function 'ftello'; did you mean 'ftell'? [-Werror=implicit-function-declaration]
39 | # define ftello64 ftello
| ^~~~~~
C:\godijustwantittowork\include\assimp-5.2.3\contrib\unzip\ioapi.c:245:11: note: in expansion of macro 'ftello64'
245 | ret = ftello64(ioposix->file);
| ^~~~~~~~
C:\godijustwantittowork\include\assimp-5.2.3\contrib\unzip\ioapi.c: In function 'fseek64_file_func':
C:\godijustwantittowork\include\assimp-5.2.3\contrib\unzip\ioapi.h:40:21: error: implicit declaration of function 'fseeko'; did you mean 'fseek'? [-Werror=implicit-function-declaration]
40 | # define fseeko64 fseeko
| ^~~~~~
C:\godijustwantittowork\include\assimp-5.2.3\contrib\unzip\ioapi.c:303:9: note: in expansion of macro 'fseeko64'
303 | if (fseeko64(ioposix->file, offset, fseek_origin) != 0)
| ^~~~~~~~
cc1.exe: all warnings being treated as errors
code\CMakeFiles\assimp.dir\build.make:3049: recipe for target 'code/CMakeFiles/assimp.dir/__/contrib/unzip/ioapi.c.obj' failed
mingw32-make.exe[2]: *** [code/CMakeFiles/assimp.dir/__/contrib/unzip/ioapi.c.obj] Error 1
CMakeFiles\Makefile2:249: recipe for target 'code/CMakeFiles/assimp.dir/all' failed
mingw32-make.exe[1]: *** [code/CMakeFiles/assimp.dir/all] Error 2
Makefile:147: recipe for target 'all' failed
mingw32-make.exe: *** [all] Error 2
Couldn't find an answer on here so sorry if this is a duplicate.

Passing -Wno-error to cmake doesn't magically cause CMake to pass that flag to any and all compilers for any and all languages.
To pass a flag to the C compiler, put CFLAGS=-Wno-error on your CMake command line. See e.g. this answer. You may need to clear your CMake cache.
Also note that this is unlikely to help you, because suppressing the implicit declaration warning still doesn't make those ftello and fseeko functions available.

Related

'dummy' may be used uninitialized

I have an issue running a clion project stepik file. The following error keeps showing up. I have a compiler and I can run other codes, but some doesn't work.
In file included from /home/gergoszabo/CLionProjects/Prog2_08/test-framework/googletest-src/googletest/src/gtest-all.cc:42:
/home/gergoszabo/CLionProjects/Prog2_08/test-framework/googletest-src/googletest/src/gtest-death-test.cc: In function ‘bool testing::internal::StackGrowsDown()’:
/home/gergoszabo/CLionProjects/Prog2_08/test-framework/googletest-src/googletest/src/gtest-death-test.cc:1224:24: error: ‘dummy’ may be used uninitialized [-Werror=maybe-uninitialized]
1224 | StackLowerThanAddress(&dummy, &result);
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/home/gergoszabo/CLionProjects/Prog2_08/test-framework/googletest-src/googletest/src/gtest-death-test.cc:1214:13: note: by argument 1 of type ‘const void*’ to ‘void testing::internal::StackLowerThanAddress(const void*, bool*)’ declared here
1214 | static void StackLowerThanAddress(const void* ptr, bool* result) {
| ^~~~~~~~~~~~~~~~~~~~~
/home/gergoszabo/CLionProjects/Prog2_08/test-framework/googletest-src/googletest/src/gtest-death-test.cc:1222:7: note: ‘dummy’ declared here
1222 | int dummy;
| ^~~~~
cc1plus: all warnings being treated as errors
gmake[3]: *** [../test-framework/googletest-build/googlemock/gtest/CMakeFiles/gtest.dir/build.make:72: ../test-framework/googletest-build/googlemock/gtest/CMakeFiles/gtest.dir/src/gtest-all.cc.o] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:587: ../test-framework/googletest-build/googlemock/gtest/CMakeFiles/gtest.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:1394: lesson1/labbeli/CMakeFiles/global-lesson1-labbeli-test.dir/rule] Error 2
gmake: *** [Makefile:598: global-lesson1-labbeli-test] Error 2
This problem is not in your own project, but in a library it seems to be using: GoogleTest.
The version of GoogleTest you're using currently has a problem when compiled with GCC 11. GCC gives off this warning (for various complex reasons). GoogleTest has configured that any warnings the compiler gives should be treated as errors. And so GCC will stop compiling when it encounters that warning.
It's not your mistake, but up to GoogleTest to fix. A fix has been made and merged here: https://github.com/google/googletest/pull/3024
Updating GoogleTest to use version 1.11.0 or newer should resolve the problem.

Error with linking flag when using the cmake build for cppyy

I am trying to build the example for a make build for cppyy in the cppyy-knearestneighbors example (https://github.com/jclay/cppyy-knearestneighbors-example). From what I understand it used the more modern cppyy cmake.
However when it comes to the linking I find this error,
ld: unknown option: --no-as-needed
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [knn_example/libknn_exampleCppyy.dylib] Error 1
make[1]: *** [CMakeFiles/knn_exampleCppyy.dir/all] Error 2
make: *** [all] Error 2
I couldn't find away to remove this flag as it seems to be something internal to cppyy cmake. Is there any work around to fix the compilation?
I cannot talk about cppyy since I have never used it, but since it internally uses CMake, the issue that you have could control by the value of the LINK_WHAT_YOU_USE property.
I would first try to disable the default value of LINK_WHAT_YOU_USE with:
# When running cmake configure:
cmake -GNinja -DCMAKE_LINK_WHAT_YOU_USE=OFF
If it does not work, a more evolve approach which means iterating all of the targets and unsetting their LINK_WHAT_YOU_USE property. Let me know if you need help for this
https://cmake.org/cmake/help/latest/variable/CMAKE_LINK_WHAT_YOU_USE.html#variable:CMAKE_LINK_WHAT_YOU_USE

Is it possible to get list of libraries set that produce fine build?

Trying to build GCC for Raspberry Pi from source according to project in my Ubuntu 20.04 machine with gcc 9.3.0 . Getting different problems while taking different sets of libraries
Configuration below brings __uint128_t error:
GCC_VERSION="9.3.0"
BINUTILS_VERSION="2.34"
GLIBC_VERSION="2.31"
MPFR_VERSION="3.1.6"
MPC_VERSION="1.0.3"
GMP_VERSION="6.2.0"
CLOOG_VERSION="0.18.1"
In file included from ../sysdeps/unix/sysv/linux/bits/sigcontext.h:30,
from ../signal/signal.h:291,
from ../include/signal.h:2,
from ../misc/sys/param.h:28,
from ../include/sys/param.h:1,
from ../sysdeps/generic/hp-timing-common.h:39,
from ../sysdeps/generic/hp-timing.h:25,
from ../nptl/descr.h:27,
from ../sysdeps/arm/nptl/tls.h:42,
from ../sysdeps/unix/sysv/linux/arm/tls.h:23,
from ../sysdeps/unix/sysv/linux/arm/sysdep.h:30,
from <stdin>:1:
/home/a/gcc_buildings/1/xc-arm-linux-gnueabi/arm-linux-gnueabi/include/asm/sigcontext.h:77:2: error: unknown type name ‘__uint128_t’
77 | __uint128_t vregs[32];
| ^~~~~~~~~~~
Configurations below brings the same mpfr_fmma error:
GCC_VERSION="9.3.0"
BINUTILS_VERSION="2.34"
GLIBC_VERSION="2.31"
MPFR_VERSION="4.1.0"
MPC_VERSION="1.0.3"
GMP_VERSION="6.2.0"
CLOOG_VERSION="0.18.1"
GCC_VERSION=9.3.0"
MPFR_VERSION="4.1.0"
MPC_VERSION="1.2.1"
GMP_VERSION="6.2.1"
ISL_VERSION="0.18"
CLOOG_VERSION="0.18.1"
/home/a/gcc-cross-compiler/xc-arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/tmp/gcc-4.9.2/mpfr/src/mpfr.h:765:21: note: previous declaration of ‘mpfr_fmma’ was here
765 | __MPFR_DECLSPEC int mpfr_fmma (mpfr_ptr, mpfr_srcptr, mpfr_srcptr, mpfr_srcptr,
| ^~~~~~~~~
make[3]: *** [Makefile:532: mul.lo] Error 1
make[3]: Leaving directory '/home/a/gcc-cross-compiler/xc-arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/tmp/build-gcc/mpc/src'
make[2]: *** [Makefile:462: all-recursive] Error 1
make[2]: Leaving directory '/home/a/gcc-cross-compiler/xc-arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/tmp/build-gcc/mpc'
make[1]: *** [Makefile:373: all] Error 2
make[1]: Leaving directory '/home/a/gcc-cross-compiler/xc-arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/tmp/build-gcc/mpc'
make: *** [Makefile:5289: all-mpc] Error
In other libraries combinations I'm getting other errors.
Is it possible to get list of libraries set that produce fine build?

Build error "ISO C++ forbids zero-size array ‘f_handle’ [-Wpedantic]" only when using snapcraft VM

I'm using the catkin command line tools to build benchmark_catkin, which is a catkin wrapper for Google's benchmark. The build uses a CMakeLists file and always worked fine so far on Ubuntu 18.04. I'm now trying to build this package with snapcraft. Snapcraft has the catkin-tools plugin and sets up a VM before building. However, I'm now getting an error from a system library and the build is not successful:
In file included from /root/parts/workspace/install/usr/include/x86_64-linux-gnu/bits/fcntl.h:61:0,
from /root/parts/workspace/install/usr/include/fcntl.h:35,
from /root/parts/workspace/build/benchmark_catkin/benchmark_src-prefix/src/benchmark_src/src/sysinfo.cc:23:
/root/parts/workspace/install/usr/include/x86_64-linux-gnu/bits/fcntl-linux.h:355:27: error: ISO C++ forbids zero-size array ‘f_handle’ [-Wpedantic]
unsigned char f_handle[0];
^
In file included from /root/parts/workspace/install/usr/include/x86_64-linux-gnu/bits/fcntl.h:61:0,
from /root/parts/workspace/install/usr/include/fcntl.h:35,
from /root/parts/workspace/build/benchmark_catkin/benchmark_src-prefix/src/benchmark_src/src/timers.cc:23:
/root/parts/workspace/install/usr/include/x86_64-linux-gnu/bits/fcntl-linux.h:355:27: error: ISO C++ forbids zero-size array ‘f_handle’ [-Wpedantic]
unsigned char f_handle[0];
^
make[5]: *** [src/CMakeFiles/benchmark.dir/sysinfo.cc.o] Error 1
make[5]: *** Waiting for unfinished jobs....
make[5]: *** [src/CMakeFiles/benchmark.dir/timers.cc.o] Error 1
make[4]: *** [src/CMakeFiles/benchmark.dir/all] Error 2
make[4]: *** Waiting for unfinished jobs....
make[3]: *** [all] Error 2
make[2]: *** [benchmark_src-prefix/src/benchmark_src-stamp/benchmark_src-build] Error 2
make[1]: *** [CMakeFiles/benchmark_src.dir/all] Error 2
make: *** [all] Error 2
I assume this error is referring to a zero-size array in the libc6-dev library. Since I'm using base: core18 in my snapcraft.yaml and also running an Ubuntu 18.04 system, I'm wondering why I just get the error in the VM. Is this a bug in the library? How can I solve this?
For reference, my snapcraft.yaml file:
name: nav
base: core18
version: 'w1.0'
summary: The Nav Software
description: |
grade: devel
confinement: strict
plugs:
network:
network-bind:
parts:
core-dep:
plugin: nil
build-packages:
- autoconf
- libtool
- git
workspace:
plugin: catkin-tools
source: .
catkin-packages: [catkin_simple, glog_catkin, gflags_catkin, benchmark_catkin]
after: [core-dep]
On request, here the code around the erroneous line of /usr/include/x86_64-linux-gnu/bits/fcntl-linux.h:
/* File handle structure. */
struct file_handle
{
unsigned int handle_bytes;
int handle_type;
/* File identifier. */
unsigned char f_handle[0];
};
I took a look into the project. CMakeLists.txt of benchmark_catkin internally checks out google/benchmark and builds that. The error comes from that build.
CMakeLists.txt google/benchmark sets tons of compiler options, and specifically -pedantic-errors (as well as -pedantic and -Werror) which causes the compiler to stop on any use of a language extension. Frankly in my opinion, CMakeLists.txt should not set any warning flags and especially no -Werror or -pedantic-errors flags without the user asking for it, so I would consider that a bug, but google devs may disagree.
The glibc header uses a language extension. But that is fine because warnings in system headers should be ignored. So the actual cause for the build failure is failure to treat the glibc header as a system header.
I know nothing about snapcraft, but I suspect that the cause of the problem is in there.

Can not compile google test with MinGW on Windows

I tried to compile google test framework with MinGW on Windows following instructions from this post, but I got errors when executing make:
[ 25%] Building CXX object CMakeFiles/gtest.dir/src/gtest-all.cc.obj
In file included from d:/downloads/googletest-master/googletest/src/gtest-all.cc:45:0:
D:/downloads/googletest-master/googletest/src/gtest-port.cc: In static member function 'static void testing::internal::ThreadLocalRegistryImpl::StartWatcherThreadFor(DWORD)':
D:/downloads/googletest-master/googletest/src/gtest-port.cc:495:21: error: '::OpenThread' has not been declared
HANDLE thread = ::OpenThread(SYNCHRONIZE | THREAD_QUERY_INFORMATION,
^
make[2]: *** [CMakeFiles/gtest.dir/src/gtest-all.cc.obj] Error 1
make[1]: *** [CMakeFiles/gtest.dir/all] Error 2
make: *** [all] Error 2
Please help. I tried:
cmake -G "MSYS Makefiles" --with-pthreads=no
But got:
CMake Error: The source directory "D:/downloads/googletest-master/googletest/--with-pthreads=no" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.
Thanks for answers.
cmake -G "MSYS Makefiles" --with-pthreads=no
I don't think --with-pthreads=no is a valid cmake option. CMake tries to interpret it as the source directory. Remove that option. I think google test needs pthreads anyways, that is why OpenThread is not declared, because it depends on pthreads.
If you're not using the MSYS shell, try to use the "MinGW Makefiles" generator for cmake.
cmake -G "MinGW Makefiles"
Then run make.