You are not logged in.

#1 2015-05-23 23:49:27

InspiredOne
Member
Registered: 2014-04-20
Posts: 7

[Solved] Conflicting declaration when cross compiling with mingw

I've been trying to figure out an issue I've been having with cross-compiling C++ code on Linux for Windows. The code I'm trying to compile is:

#include <iostream>

int main(int argc, char** argv){
    std::cout<<"Hello World!\n";
    return 0;
}

I'm trying to compile for a 64 bit windows installation, and so I run:

x86_64-w64-mingw32-g++ main.cpp

but it produces the following errors:

In file included from /usr/include/sched.h:34:0,
                 from /usr/include/pthread.h:23,
                 from /usr/x86_64-w64-mingw32/include/c++/4.9.2/x86_64-w64-mingw32/bits/gthr-default.h:35,
                 from /usr/x86_64-w64-mingw32/include/c++/4.9.2/x86_64-w64-mingw32/bits/gthr.h:148,
                 from /usr/x86_64-w64-mingw32/include/c++/4.9.2/ext/atomicity.h:35,
                 from /usr/x86_64-w64-mingw32/include/c++/4.9.2/bits/ios_base.h:39,
                 from /usr/x86_64-w64-mingw32/include/c++/4.9.2/ios:42,
                 from /usr/x86_64-w64-mingw32/include/c++/4.9.2/ostream:38,
                 from /usr/x86_64-w64-mingw32/include/c++/4.9.2/iostream:39,
                 from main.cpp:1:
/usr/include/time.h:75:18: error: conflicting declaration ‘typedef __time_t time_t’
 typedef __time_t time_t;
                  ^
In file included from /usr/x86_64-w64-mingw32/include/stddef.h:7:0,
                 from /usr/lib/gcc/x86_64-w64-mingw32/4.9.2/include/stddef.h:1,
                 from /usr/include/wchar.h:51,
                 from /usr/x86_64-w64-mingw32/include/c++/4.9.2/cwchar:44,
                 from /usr/x86_64-w64-mingw32/include/c++/4.9.2/bits/postypes.h:40,
                 from /usr/x86_64-w64-mingw32/include/c++/4.9.2/iosfwd:40,
                 from /usr/x86_64-w64-mingw32/include/c++/4.9.2/ios:38,
                 from /usr/x86_64-w64-mingw32/include/c++/4.9.2/ostream:38,
                 from /usr/x86_64-w64-mingw32/include/c++/4.9.2/iostream:39,
                 from main.cpp:1:
/usr/x86_64-w64-mingw32/include/crtdefs.h:138:20: note: previous declaration as ‘typedef __time64_t time_t’
 typedef __time64_t time_t;
                    ^
In file included from /usr/x86_64-w64-mingw32/include/c++/4.9.2/cwctype:50:0,
                 from /usr/x86_64-w64-mingw32/include/c++/4.9.2/bits/locale_facets.h:39,
                 from /usr/x86_64-w64-mingw32/include/c++/4.9.2/bits/basic_ios.h:37,
                 from /usr/x86_64-w64-mingw32/include/c++/4.9.2/ios:44,
                 from /usr/x86_64-w64-mingw32/include/c++/4.9.2/ostream:38,
                 from /usr/x86_64-w64-mingw32/include/c++/4.9.2/iostream:39,
                 from main.cpp:1:
/usr/include/wctype.h:52:27: error: conflicting declaration ‘typedef long unsigned int wctype_t’
 typedef unsigned long int wctype_t;
                           ^
In file included from /usr/x86_64-w64-mingw32/include/stddef.h:7:0,
                 from /usr/lib/gcc/x86_64-w64-mingw32/4.9.2/include/stddef.h:1,
                 from /usr/include/wchar.h:51,
                 from /usr/x86_64-w64-mingw32/include/c++/4.9.2/cwchar:44,
                 from /usr/x86_64-w64-mingw32/include/c++/4.9.2/bits/postypes.h:40,
                 from /usr/x86_64-w64-mingw32/include/c++/4.9.2/iosfwd:40,
                 from /usr/x86_64-w64-mingw32/include/c++/4.9.2/ios:38,
                 from /usr/x86_64-w64-mingw32/include/c++/4.9.2/ostream:38,
                 from /usr/x86_64-w64-mingw32/include/c++/4.9.2/iostream:39,
                 from main.cpp:1:
/usr/x86_64-w64-mingw32/include/crtdefs.h:107:24: note: previous declaration as ‘typedef short unsigned int wctype_t’
 typedef unsigned short wctype_t;
                        ^

The error line:

/usr/include/time.h:75:18: error: conflicting declaration ‘typedef __time_t time_t’
 typedef __time_t time_t;

suggests to me that mingw is using the linux libraries instead of the ones compiled for windows, but upon searching I cannot seem to figure out how to resolve this.I've tried reinstalling the mingw-w64 package group thinking that maybe the libraries were not compiled correctly but I'm still receiving the same errors.

To be clear, I am able to compile this code with:

g++ main.cpp

Any help or anything to point me in the right direction will be greatly appreciated. Thank you.

Last edited by InspiredOne (2015-05-24 21:48:59)

Offline

#2 2015-05-24 21:48:32

InspiredOne
Member
Registered: 2014-04-20
Posts: 7

Re: [Solved] Conflicting declaration when cross compiling with mingw

I found the problem and documented it on github.

The issue was that there was an environment variable set that mingw-w64 was using to find the linux header files. Specifically, I had set CPLUS_INCLUDE_PATH in my .bashrc a while ago and had forgotten about it. This variable does not generally need to be set unless there is some special circumstance that requires it. I do not personally rely on it. I commented out the export and the compiler seems to be finding all the headers it needs now. Marking as Solved.

Offline

Board footer

Powered by FluxBB