How to solve this [All] Error 2 in this case? - c++

So I coding a simple tensor with Eigen as follows:
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <Eigen/Dense>
#include <unsupported/Eigen/CXX11/Tensor>
using namespace Eigen;
using namespace std;
int main () {
Tensor<double, 3> A(4,5,6); // 3 dimensions (4x5x6)
A.setZero();
A(0,1,2) = 1.7;
A(1,2,2) = -1.5;
cout<<A(1,2,2)<<endl;
return 0;
}
But then I get the following error and I looked around the internet for help, but sadly I am still clueless. I always get this error with my more advanced code, so I decided to do a small code just to test when I get this error. Note: I didn't get this error when I was did the same with an Eigen matrix. Only when I changed to a tensor, did I get this error. Then afterwards I changed it back to a matrix and I somehow get the same error now? However, even in my more advanced code I don't even have any tensors, but for some reason still get this error. Can someone please help me as this is driving me insane?
C:\WINDOWS\system32\cmd.exe /C C:/MinGW/bin/mingw32-make.exe -j4 SHELL=cmd.exe -e -f Makefile
"----------Building project:[ Test - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test'
mingw32-make.exe[1]: Leaving directory 'C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test'
mingw32-make.exe[1]: Entering directory 'C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test'
C:/MinGW/bin/g++.exe -c "C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test/main.cpp" -std=c++14 -Wall -g -O0 -Wall -o ./Debug/main.cpp.o -I. -I"C:\Users\RS3\Desktop\SCC HiWi\Code\C++\myGmm\UQ\eigen-3.3.9" -I"C:\Users\RS3\Desktop\SCC HiWi\Code\C++\myGmm\UQ\Halton" -I"C:\Users\RS3\Desktop\SCC HiWi\Code\C++\myGmm\UQ\quasimvnrnd" -I"C:\Users\RS3\Desktop\SCC HiWi\Code\C++\myGmm\UQ\dirent\dirent-master\include"
In file included from C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test/main.cpp:5:
C:\Users\RS3\Desktop\SCC HiWi\Code\C++\myGmm\UQ\eigen-3.3.9/unsupported/Eigen/CXX11/Tensor:53:17: error: conflicting declaration 'typedef long int int32_t'
typedef __int32 int32_t;
^~~~~~~
In file included from c:\mingw\lib\gcc\mingw32\8.2.0\include\stdint.h:9,
from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\cstdint:41,
from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\bits\char_traits.h:501,
from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\ios:40,
from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\iostream:39,
from C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test/main.cpp:2:
c:\mingw\include\stdint.h:62:15: note: previous declaration as 'typedef int int32_t'
typedef int int32_t;
^~~~~~~
In file included from C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test/main.cpp:5:
C:\Users\RS3\Desktop\SCC HiWi\Code\C++\myGmm\UQ\eigen-3.3.9/unsupported/Eigen/CXX11/Tensor:54:26: error: conflicting declaration 'typedef long unsigned int uint32_t'
typedef unsigned __int32 uint32_t;
^~~~~~~~
In file included from c:\mingw\lib\gcc\mingw32\8.2.0\include\stdint.h:9,
from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\cstdint:41,
from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\bits\char_traits.h:501,
from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\ios:40,
from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\iostream:39,
from C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test/main.cpp:2:
c:\mingw\include\stdint.h:63:19: note: previous declaration as 'typedef unsigned int uint32_t'
typedef unsigned uint32_t;
^~~~~~~~
mingw32-make.exe[1]: *** [Debug/main.cpp.o] Error 1
Test.mk:97: recipe for target 'Debug/main.cpp.o' failed
mingw32-make.exe[1]: Leaving directory 'C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test'
mingw32-make.exe: *** [All] Error 2
Makefile:4: recipe for target 'All' failed
====1 errors, 4 warnings====
UPDATE: When I remove the last include and do the Eigen matrix again, there's no problem. So the problem is with the last include. But without it, I can't work with tensors. What should I do to work with tensors without the error?

Can you let us know where your version of MinGW comes from?
The issue is that your version of MinGW is apparently defining __int32 as long but int32_t as int, leading to a type conflict. We had some code in the Tensor module to ensure int32_t is always defined on Windows, since Visual Studio prior to 2010 doesn't actually provide an stdint.h header. We've never seen this cause an issue before. I tried several versions of MinGW, both 32-bit and 64-bit, but in all the ones I've tried so far __int32 is always an int.
I have a potential fix pending on the master branch here: !373. Once it's merged we can backport the change to the stable 3.3 branch.
If you just want to get something up and running, you can try installing a different version of MinGW.

Related

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.

OpenCV "conflicting declaration" issue at compilation on armv7l (Odroid XU4)

I'm trying to compile OpenCV 3.4.0 from sources but I'm running into a conflicting declaration issue between QT and OpenGL.
Upgrading from QT4 to QT5 solved some issues but not all.
It looks like GLsizeiptr and GLintptr are declared in both the OpenGL headers and the QT headers.
I tried to replace
#include <GL/glx.h>
with
#include <GLES3/gl3.h>
in window_QT.cpp but that only created more declaration issues.
Any ideas on how to fix that?
(My machine is an armv7l (Odroid XU4) running Ubuntu 16.04.3 LTS)
The cmake command I'm running:
cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -DWITH_QT=5 -DWITH_OPENGLES=ON -DWITH_V4L=ON -DWITH_TBB=ON -DBUILD_TBB=ON -DENABLE_VFPV3=ON -DENABLE_NEON=ON ..
make -j8
the errors I'm getting:
[ 62%] Built target opencv_videoio
[ 63%] Built target opencv_superres
[ 63%] Building CXX object
modules/highgui/CMakeFiles/opencv_highgui.dir/src/window_QT.cpp.o
cc1plus: warning: /home/odroid/temporary_cmake_binary_dir/opencv-3.4.0/release/modules/highgui/precomp.hpp.gch/opencv_highgui_RELEASE.gch: not used because `TBB_USE_GCC_BUILTINS' is defined [-Winvalid-pch]
In file included from /usr/include/GL/gl.h:2055:0,
from /usr/include/GL/glx.h:32,
from /home/odroid/temporary_cmake_binary_dir/opencv-3.4.0/modules/highgui/src/window_QT.cpp:59:
/usr/include/GL/glext.h:466:19: error: conflicting declaration ‘typedef ptrdiff_t GLsizeiptr’
typedef ptrdiff_t GLsizeiptr;
^
In file included from /usr/include/arm-linux-gnueabihf/qt5/QtGui/qopengl.h:95:0,
from /usr/include/arm-linux-gnueabihf/qt5/QtGui/qopenglcontext.h:54,
from /usr/include/arm-linux-gnueabihf/qt5/QtGui/QtGui:32,
from /usr/include/arm-linux-gnueabihf/qt5/QtOpenGL/QtOpenGLDepends:4,
from /usr/include/arm-linux-gnueabihf/qt5/QtOpenGL/QtOpenGL:3,
from /home/odroid/temporary_cmake_binary_dir/opencv-3.4.0/modules/highgui/src/window_QT.h:50,
from /home/odroid/temporary_cmake_binary_dir/opencv-3.4.0/modules/highgui/src/window_QT.cpp:47:
/usr/include/GLES3/gl31.h:77:25: note: previous declaration as ‘typedef khronos_ssize_t GLsizeiptr’
typedef khronos_ssize_t GLsizeiptr;
^
In file included from /usr/include/GL/gl.h:2055:0,
from /usr/include/GL/glx.h:32,
from /home/odroid/temporary_cmake_binary_dir/opencv-3.4.0/modules/highgui/src/window_QT.cpp:59:
/usr/include/GL/glext.h:467:19: error: conflicting declaration ‘typedef ptrdiff_t GLintptr’
typedef ptrdiff_t GLintptr;
^
In file included from /usr/include/arm-linux-gnueabihf/qt5/QtGui/qopengl.h:95:0,
from /usr/include/arm-linux-gnueabihf/qt5/QtGui/qopenglcontext.h:54,
from /usr/include/arm-linux-gnueabihf/qt5/QtGui/QtGui:32,
from /usr/include/arm-linux-gnueabihf/qt5/QtOpenGL/QtOpenGLDepends:4,
from /usr/include/arm-linux-gnueabihf/qt5/QtOpenGL/QtOpenGL:3,
from /home/odroid/temporary_cmake_binary_dir/opencv-3.4.0/modules/highgui/src/window_QT.h:50,
from /home/odroid/temporary_cmake_binary_dir/opencv-3.4.0/modules/highgui/src/window_QT.cpp:47:
/usr/include/GLES3/gl31.h:78:26: note: previous declaration as ‘typedef khronos_intptr_t GLintptr’
typedef khronos_intptr_t GLintptr;
^
[ 63%] Built target gen_opencv_python_source
modules/highgui/CMakeFiles/opencv_highgui.dir/build.make:129: recipe for target 'modules/highgui/CMakeFiles/opencv_highgui.dir/src/window_QT.cpp.o' failed
make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/window_QT.cpp.o] Error 1
CMakeFiles/Makefile2:5307: recipe for target 'modules/highgui/CMakeFiles/opencv_highgui.dir/all' failed
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
Makefile:160: recipe for target 'all' failed
make: *** [all] Error 2
Thanks for the help!
Problem solved: I just tried a fresh install with latest version of opencv cloned directly from github and the install went flawlessly.

XGCC stdarg.h NO SUCH FILE OR DIRECTORY

I have included vsprintf in my project. However, when I compile it I receive the following error.
/opt/xgcc/decstation-ultrix/bin/xgcc -DIN_USER_MODE -c -I../userprog -I../threads -G 0 -Wall -O2 -DCHANGED -c vsprintf.c
vsprintf.c:12: stdarg.h: No such file or directory
make[1]: *** [vsprintf.o] Error 1
rm add.o
make[1]: Leaving directory `/home/banana/se31/code/test'
make: *** [all] Error 2
Line 12 of vsprintf contains the following:
#include <stdarg.h>
I verified that stdarg.h is properly installed in my system using the following short programs.
//test.c and test.cpp
#include <stdarg.h>
int main(void)
{
return 0;
}
When I run gcc test.c or gcc test.cpp I receive no errors which implies that my vsprint.c and gcc is properly installed.
I have gone through similar questions in stackoverflow but have not got a solution yet. I am using Ubuntu 32 bit as my Operating System. Could someone guide me on how I can resolve this issue?
As hvd
pointed out. I was checking for stdarg.h in the wrong place. To fix it, stdarg.h had to be added to my project. From there, the cross compiler (xgcc) was able to compile the program.

Can't build test application with WxWIdgets in Netbeans

I'm a total c++ Newbie.
I'm trying to build windows aplications with Wx-Widgets under Net Beans.
So far so good. I have instaled everything, configured, build wx-widgets and attached it to the new project - with help of a good man here: Can't make wx-widget work with net-beans.
Now I try to build my first app:
#include <wx/string.h>
int main(int argc, char **argv)
{
wxPuts(wxT("A wxWidgets console application"));
}
and this is what I get:
I'm not sure if this is readable so I paste the errors:
g++ `C:\WXWIN\wx-config --cxxflags` -c -g -I../../../WXWIN/include `C:\WXWIN\wx-config --cxxflags` -MMD -MP -MF build/Debug/MinGW-Windows/main.o.d -o build/Debug/MinGW-Windows/main.o main.cpp
/bin/sh.exe: C:WXWINwx-config: command not found
/bin/sh.exe: C:WXWINwx-config: command not found
In file included from ../../../WXWIN/include/wx/defs.h:21:0,
from ../../../WXWIN/include/wx/string.h:25,
from main.cpp:1:
../../../WXWIN/include/wx/platform.h:196:22: fatal error: wx/setup.h: No such file or directory
compilation terminated.
make[2]: *** [build/Debug/MinGW-Windows/main.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
make[2]: Leaving directory `/c/xampp/htdocs/WxWwigets_tutorial'
make[1]: Leaving directory `/c/xampp/htdocs/WxWwigets_tutorial'
BUILD FAILED (exit value 2, total time: 859ms)
Please notice that I have set everything in linker and compiler like ordered: http://wiki.wxwidgets.org/Compiling_using_Netbeans
The error is right in front of you: "command not found". If you use /bin/sh, you must use Unix style paths, e.g. C:/WXWIN/wx-config instead of DOS paths with the backslashes.
I seriously advise you to get familiar with the environment you're using instead of just following the Wiki instructions without understanding them, otherwise your problems won't be over any time soon.

Problems compiliing c++ code using cygwin

I am trying to compile some source code in cygwin (in windows 7)
and get the following error when I run the make file
g++ -DHAVE_CONFIG_H -I. -I.. -I.. -Wall -Wextra -Werror -g -O2 -MT libcommon_a Fcntl.o -MD -MP -MF .deps/libcommon_a-Fcntl.Tpo -c -o libcommon_a-Fcntl.o `test -f 'Fcntl.cpp' || echo './'`Fcntl.cpp
Fcntl.cpp: In function int setCloexec(int):
Fcntl.cpp:8: error: 'F_GETFD' was not declared in this scope
Fcntl.cpp:8: error: 'fcntl' was not declared in this scope
Fcntl.cpp:11: error: 'FD_CLOEXEC' was not declared in this scope
Fcntl.cpp:12: error: 'F_SETFD' was not declared in this scope
make[4]: *** [libcommon_a-Fcntl.o] Error 1
make[4]: Leaving directory `/abyss-1.1.2/Common'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/abyss-1.1.2'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/abyss-1.1.2'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/cygdrive/c/Users/Martin/Documents/NetBeansProjects/abyss-1.1.2_1'
make: *** [.build-impl] Error 2
The problem file is:-
#include "Fcntl.h"
#include <fcntl.h>
/* Set the FD_CLOEXEC flag of the specified file descriptor. */
int setCloexec(int fd)
{
int flags = fcntl(fd, F_GETFD, 0);
if (flags == -1)
return -1;
flags |= FD_CLOEXEC;
return fcntl(fd, F_SETFD, flags);
}
I don't understand what is going on,
the file fcntl.h is available and the varaiables that it says were not declared in this scope
do not give an error when I compile the file on its own
Any help would be much appreciated
Many Thanks
I've not built things with Cygwin, so this might be off-base, but considering that you're building on Windows, which has a case-insensitive filesystem, are you sure that the compiler can tell the difference between your header Fcntl.h and the system header fcntl.h? It might just be including your header twice and never getting the system header.
What's up with those #include statements? It seems like you have a header file in your project called Fcntl.h, is that right? Does it have include guards in it? If it does, maybe you're accidentally using the same guard as the built-in header, and as a result not getting its contents. Cygwin normally runs on a case-insensitive filesystem, so even giving those headers similar names like that is probably dangerous.