GCC Compiler error: -Werror=stringop-truncation: no option - c++

I am trying to run a gcc compiler to make an executable, but I get this whenever I run the 'make' command in my terminal:
Scanning dependencies of target my_libs-atmega328p
[ 2%] Building CXX object my_libs/CMakeFiles/my_libs-atmega328p.dir/CLed.cpp.obj
cc1plus: error: -Werror=stringop-truncation: no option -Wstringop-truncation
make[2]: *** [my_libs/CMakeFiles/my_libs-atmega328p.dir/build.make:63:my_libs/CMakeFiles/my_libs-atmega328p.dir/CLed.cpp.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:246: my_libs/CMakeFiles/my_libs-atmega328p.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
I don't even have a string in the file it gets tripped up on (CLed.cpp), so I don't know why it is trying to truncate a string. I have even commented out the entire file and it still is looking for something. Where might I go to find the solution?

I don't even have a string in the file it gets tripped up on (CLed.cpp), so I don't know why it is trying to truncate a string
It is not "trying to truncate a string", nor is it warning about "trying to truncate a string."
The error is saying that the compiler was given the option -Werror=stringop-truncation while the compiler does not recognise such warning option. The solution is to not pass -Werror=stringop-truncation to the compiler. Or to use another compiler (version) that does support such option.

Related

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

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.

CGREEN compilation error: ‘assertion_tests’ does not name a type

When I try to compile cgreen unit testing framework in cygwin64 I get this error:
[ 34%] Building CXX object tests/CMakeFiles/cgreen_cpp_tests.dir/assertion_tests.cpp.o
/home/Administrator/cgreen/tests/assertion_tests.cpp:1:1: error: ‘assertion_tests’ does not name a type
assertion_tests.c
^~~~~~~~~~~~~~~
make[2]: *** [tests/CMakeFiles/cgreen_cpp_tests.dir/build.make:63: tests/CMakeFiles/cgreen_cpp_tests.dir/assertion_tests.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:1615: tests/CMakeFiles/cgreen_cpp_tests.dir/all] Error 2 make: *** [Makefile:161: all] Error 2
I have searched on google with no result.
I am using cygwin64 with cmake 3.6.2 and gcc 7.3.0
Any help will be appreciated!
The assertion_tests.cpp file is a symlink, see github cgreen repo. Sadly, on windows symlink is converted into textfile with the path to the file it should link to. You need to convert the file into actual link, as well all the others links in the cgreen repo, and there are some. Some help on how to do it may be better found on this thread.

Trouble compiling praat on Windows with cygwin - internal compiler error

I'm attempting to compile Praat (http://www.fon.hum.uva.nl/praat/) with Cygwin. I tried following the instructions on the GitHub page (https://github.com/praat/praat). When I run 'make', several files compile with no problem, but then I get:
x86_64-w64-mingw32-gcc -std=gnu99 -municode -D_FILE_OFFSET_BITS=64 -O1 -I ../../sys -I ../../dwsys -c -o gsl_complex__math.o gsl_complex__math.c
gsl_complex__math.c: In function ‘gsl_complex_log10’:
gsl_complex__math.c:425:3: internal compiler error: Segmentation fault
return gsl_complex_mul_real (gsl_complex_log (a), 1 / log (10.));
^
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
<builtin>: recipe for target 'gsl_complex__math.o' failed
make[1]: *** [gsl_complex__math.o] Error 1
make[1]: Leaving directory '/cygdrive/c/Users/Colin/workspace/praat-master/external/gsl'
makefile:14: recipe for target 'all' failed
make: *** [all] Error 2
I tried posting a question on the Praat user group with no luck. My suspicion is that it will work with a previous version of x86_64-w64-mingw32-gcc, but I'm not sure how to identify which version will work, or honestly, how to downgrade. (I'm also not sure what the difference is between x86_64-w64-mingw32-gcc and plain ol' gcc.) I'd like to avoid any solution that involves editing the source code because it has clearly been compiled as-is before with no problems.
Any suggestions or pointers is the right direction would be greatly appreciated! :)

Can someone explain why my cmake file fails to build my cpp file?

So I've got the following CMakeLists.txt file to try and build my main.cpp file.
project(shell)
set(extra_flags = -std=c++11 -Werror -Wall -Wextra)
set(CMAKE_CXX_FLAGS $(CMAKE_CXX_FLAGS) $(extra_flags))
add_executable(shell main.cpp)
At this point, I am just trying to build it with a Hello World program just to make sure everything works. But the flags are there for the rest of the program that I need to write. The actual process of calling cmake . works just fine, but when I use make I get the following error:
[100%] Building CXX object CMakeFiles/shell.dir/main.cpp.o
c++: fatal error: no input files
compilation terminated.
/bin/sh: 1: -o: not found
CMakeFiles/shell.dir/build.make:54: recipe for target 'CMakeFiles/shell.dir/main.cpp.o' failed
make[2]: *** [CMakeFiles/shell.dir/main.cpp.o] Error 127
CMakeFiles/Makefile2:60: recipe for target 'CMakeFiles/shell.dir/all' failed
make[1]: *** [CMakeFiles/shell.dir/all] Error 2
Makefile:72: recipe for target 'all' failed
make: *** [all] Error 2
I'm new to Ubuntu and the command line, so any help would be greatly appreciated.
Make sure you use curly brackets ${} (comment above)
Make sure you delete your CMakeCache.txt if you want a "reset" (comment above)
I also developed the habit to always use set(CMAKE_CXX_FLGAS "${CMAKE_CXX_FLAGS} ${extra_flags}") instead of set(CMAKE_CXX_FLGAS ${CMAKE_CXX_FLAGS} ${extra_flags}) which proved to cause less headache in any of my applications. Try that as well.
Use make VERBOSE=1 to see which commands CMake actually runs. You then can mess with the command directly and see how you get it to work.
If it's just HelloWorld!, try leaving out the -std=c++11 flag (or any flags, really) and see.