Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
158 views
in Technique[技术] by (71.8m points)

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

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:WINDOWSsystem32cmd.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:UsersRS3DesktopSCC HiWiCodeC++myGmmUQeigen-3.3.9" -I"C:UsersRS3DesktopSCC HiWiCodeC++myGmmUQHalton" -I"C:UsersRS3DesktopSCC HiWiCodeC++myGmmUQquasimvnrnd" -I"C:UsersRS3DesktopSCC HiWiCodeC++myGmmUQdirentdirent-masterinclude"
In file included from C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test/main.cpp:5:
C:UsersRS3DesktopSCC HiWiCodeC++myGmmUQeigen-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:mingwlibgccmingw328.2.0includestdint.h:9,
                 from c:mingwlibgccmingw328.2.0includec++cstdint:41,
                 from c:mingwlibgccmingw328.2.0includec++itschar_traits.h:501,
                 from c:mingwlibgccmingw328.2.0includec++ios:40,
                 from c:mingwlibgccmingw328.2.0includec++ostream:38,
                 from c:mingwlibgccmingw328.2.0includec++iostream:39,
                 from C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test/main.cpp:2:
c:mingwincludestdint.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:UsersRS3DesktopSCC HiWiCodeC++myGmmUQeigen-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:mingwlibgccmingw328.2.0includestdint.h:9,
                 from c:mingwlibgccmingw328.2.0includec++cstdint:41,
                 from c:mingwlibgccmingw328.2.0includec++itschar_traits.h:501,
                 from c:mingwlibgccmingw328.2.0includec++ios:40,
                 from c:mingwlibgccmingw328.2.0includec++ostream:38,
                 from c:mingwlibgccmingw328.2.0includec++iostream:39,
                 from C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test/main.cpp:2:
c:mingwincludestdint.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?

question from:https://stackoverflow.com/questions/65901014/how-to-solve-this-all-error-2-in-this-case

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...