TheLogicMaster / switch-gdx

A LibGDX Nintendo Switch Homebrew and Xbox/UWP backend
GNU General Public License v2.0
83 stars 9 forks source link

Compilation of natives.cpp fails #2

Open Clomclem opened 2 years ago

Clomclem commented 2 years ago

So, i think saying small in #1 was a understatement.

Info

Windows 10 Latest version of msys2/mingw64/gcc

Problem

When i execute the run task, the transpile task works correctly, but when it moves into the actual compiling, it compiles all the way until the natives.cpp file, in where it fails with a bunch of errors:

Error log ``` [ 94%] Building C object CMakeFiles/SwitchGDX.dir/source/me_clomclem_islandium_world_World.c.obj [ 95%] Building C object CMakeFiles/SwitchGDX.dir/source/me_clomclem_islandium_world_WorldManager.c.obj [ 95%] Building C object CMakeFiles/SwitchGDX.dir/source/me_clomclem_islandium_world_World_Component.c.obj [ 95%] Building C object CMakeFiles/SwitchGDX.dir/source/nativeMethods.c.obj [ 95%] Building CXX object CMakeFiles/SwitchGDX.dir/source/natives.cpp.obj In file included from /D/devkitPro/msys2/usr/include/w32api/winsock2.h:56, from /D/Islandium/switch/build/Islandium/source/natives.cpp:22: /D/devkitPro/msys2/usr/include/w32api/psdk_inc/_fd_types.h:100:2: warning: #warning "fd_set and associated macros have been defined in sys/types. This can cause runtime problems with W32 sockets" [-Wcpp] 100 | #warning "fd_set and associated macros have been defined in sys/types. \ | ^~~~~~~ In file included from /D/devkitPro/msys2/usr/include/w32api/winsock2.h:57, from /D/Islandium/switch/build/Islandium/source/natives.cpp:22: /D/devkitPro/msys2/usr/include/w32api/psdk_inc/_ip_types.h:63:8: error: redefinition of ‘struct linger’ 63 | struct linger { | ^~~~~~ In file included from /usr/include/sys/socket.h:13, from /D/devkitPro/msys2/mingw64/include/curl/system.h:422, from /D/devkitPro/msys2/mingw64/include/curl/curl.h:37, from /D/Islandium/switch/build/Islandium/source/natives.cpp:10: /usr/include/cygwin/socket.h:52:8: note: previous definition of ‘struct linger’ 52 | struct linger { | ^~~~~~ In file included from /D/devkitPro/msys2/usr/include/w32api/winsock2.h:57, from /D/Islandium/switch/build/Islandium/source/natives.cpp:22: /D/devkitPro/msys2/usr/include/w32api/psdk_inc/_ip_types.h:70:8: error: redefinition of ‘struct sockaddr’ 70 | struct sockaddr { | ^~~~~~~~ In file included from /usr/include/sys/socket.h:13, from /D/devkitPro/msys2/mingw64/include/curl/system.h:422, from /D/devkitPro/msys2/mingw64/include/curl/curl.h:37, from /D/Islandium/switch/build/Islandium/source/natives.cpp:10: /usr/include/cygwin/socket.h:27:8: note: previous definition of ‘struct sockaddr’ 27 | struct sockaddr { | ^~~~~~~~ In file included from /D/Islandium/switch/build/Islandium/source/natives.cpp:22: /D/devkitPro/msys2/usr/include/w32api/winsock2.h:269:10: error: redefinition of ‘struct sockaddr_storage’ 269 | struct sockaddr_storage { | ^~~~~~~~~~~~~~~~ In file included from /usr/include/sys/socket.h:13, from /D/devkitPro/msys2/mingw64/include/curl/system.h:422, from /D/devkitPro/msys2/mingw64/include/curl/curl.h:37, from /D/Islandium/switch/build/Islandium/source/natives.cpp:10: /usr/include/cygwin/socket.h:39:8: note: previous definition of ‘struct sockaddr_storage’ 39 | struct sockaddr_storage { | ^~~~~~~~~~~~~~~~ In file included from /D/Islandium/switch/build/Islandium/source/natives.cpp:22: /D/devkitPro/msys2/usr/include/w32api/winsock2.h:1003:37: error: conflicting declaration of C function ‘SOCKET accept(SOCKET, sockaddr*, int*)’ 1003 | WINSOCK_API_LINKAGE SOCKET WSAAPI accept(SOCKET s,struct sockaddr *addr,int *addrlen); | ^~~~~~ In file included from /D/devkitPro/msys2/mingw64/include/curl/system.h:422, from /D/devkitPro/msys2/mingw64/include/curl/curl.h:37, from /D/Islandium/switch/build/Islandium/source/natives.cpp:10: /usr/include/sys/socket.h:21:7: note: previous declaration ‘int accept(int, sockaddr*, socklen_t*)’ 21 | int accept (int, struct sockaddr *__peer, socklen_t *); | ^~~~~~ In file included from /D/Islandium/switch/build/Islandium/source/natives.cpp:22: /D/devkitPro/msys2/usr/include/w32api/winsock2.h:1004:34: error: conflicting declaration of C function ‘int bind(SOCKET, const sockaddr*, int)’ 1004 | WINSOCK_API_LINKAGE int WSAAPI bind(SOCKET s,const struct sockaddr *name,int namelen); | ^~~~ In file included from /D/devkitPro/msys2/mingw64/include/curl/system.h:422, from /D/devkitPro/msys2/mingw64/include/curl/curl.h:37, from /D/Islandium/switch/build/Islandium/source/natives.cpp:10: /usr/include/sys/socket.h:23:7: note: previous declaration ‘int bind(int, const sockaddr*, socklen_t)’ 23 | int bind (int, const struct sockaddr *__my_addr, socklen_t __addrlen); | ^~~~ In file included from /D/Islandium/switch/build/Islandium/source/natives.cpp:22: /D/devkitPro/msys2/usr/include/w32api/winsock2.h:1006:34: error: conflicting declaration of C function ‘int connect(SOCKET, const sockaddr*, int)’ 1006 | WINSOCK_API_LINKAGE int WSAAPI connect(SOCKET s,const struct sockaddr *name,int namelen); | ^~~~~~~ In file included from /D/devkitPro/msys2/mingw64/include/curl/system.h:422, from /D/devkitPro/msys2/mingw64/include/curl/curl.h:37, from /D/Islandium/switch/build/Islandium/source/natives.cpp:10: /usr/include/sys/socket.h:24:7: note: previous declaration ‘int connect(int, const sockaddr*, socklen_t)’ 24 | int connect (int, const struct sockaddr *, socklen_t); | ^~~~~~~ In file included from /D/Islandium/switch/build/Islandium/source/natives.cpp:22: /D/devkitPro/msys2/usr/include/w32api/winsock2.h:1008:34: error: conflicting declaration of C function ‘int getpeername(SOCKET, sockaddr*, int*)’ 1008 | WINSOCK_API_LINKAGE int WSAAPI getpeername(SOCKET s,struct sockaddr *name,int *namelen); | ^~~~~~~~~~~ In file included from /D/devkitPro/msys2/mingw64/include/curl/system.h:422, from /D/devkitPro/msys2/mingw64/include/curl/curl.h:37, from /D/Islandium/switch/build/Islandium/source/natives.cpp:10: /usr/include/sys/socket.h:25:7: note: previous declaration ‘int getpeername(int, sockaddr*, socklen_t*)’ 25 | int getpeername (int, struct sockaddr *__peer, socklen_t *); | ^~~~~~~~~~~ In file included from /D/Islandium/switch/build/Islandium/source/natives.cpp:22: /D/devkitPro/msys2/usr/include/w32api/winsock2.h:1009:34: error: conflicting declaration of C function ‘int getsockname(SOCKET, sockaddr*, int*)’ 1009 | WINSOCK_API_LINKAGE int WSAAPI getsockname(SOCKET s,struct sockaddr *name,int *namelen); | ^~~~~~~~~~~ In file included from /D/devkitPro/msys2/mingw64/include/curl/system.h:422, from /D/devkitPro/msys2/mingw64/include/curl/curl.h:37, from /D/Islandium/switch/build/Islandium/source/natives.cpp:10: /usr/include/sys/socket.h:26:7: note: previous declaration ‘int getsockname(int, sockaddr*, socklen_t*)’ 26 | int getsockname (int, struct sockaddr *__addr, socklen_t *); | ^~~~~~~~~~~ In file included from /D/Islandium/switch/build/Islandium/source/natives.cpp:22: /D/devkitPro/msys2/usr/include/w32api/winsock2.h:1010:34: error: conflicting declaration of C function ‘int getsockopt(SOCKET, int, int, char*, int*)’ 1010 | WINSOCK_API_LINKAGE int WSAAPI getsockopt(SOCKET s,int level,int optname,char *optval,int *optlen); | ^~~~~~~~~~ In file included from /D/devkitPro/msys2/mingw64/include/curl/system.h:422, from /D/devkitPro/msys2/mingw64/include/curl/curl.h:37, from /D/Islandium/switch/build/Islandium/source/natives.cpp:10: /usr/include/sys/socket.h:38:7: note: previous declaration ‘int getsockopt(int, int, int, void*, socklen_t*)’ 38 | int getsockopt (int __s, int __level, int __optname, void *__optval, | ^~~~~~~~~~ In file included from /D/Islandium/switch/build/Islandium/source/natives.cpp:22: /D/devkitPro/msys2/usr/include/w32api/winsock2.h:1020:34: error: conflicting declaration of C function ‘int listen(SOCKET, int)’ 1020 | WINSOCK_API_LINKAGE int WSAAPI listen(SOCKET s,int backlog); | ^~~~~~ In file included from /D/devkitPro/msys2/mingw64/include/curl/system.h:422, from /D/devkitPro/msys2/mingw64/include/curl/curl.h:37, from /D/Islandium/switch/build/Islandium/source/natives.cpp:10: /usr/include/sys/socket.h:27:7: note: previous declaration ‘int listen(int, int)’ 27 | int listen (int, int __n); | ^~~~~~ In file included from /D/Islandium/switch/build/Islandium/source/natives.cpp:22: /D/devkitPro/msys2/usr/include/w32api/winsock2.h:1028:34: error: conflicting declaration of C function ‘int recv(SOCKET, char*, int, int)’ 1028 | WINSOCK_API_LINKAGE int WSAAPI recv(SOCKET s,char *buf,int len,int flags); | ^~~~ In file included from /D/devkitPro/msys2/mingw64/include/curl/system.h:422, from /D/devkitPro/msys2/mingw64/include/curl/curl.h:37, from /D/Islandium/switch/build/Islandium/source/natives.cpp:10: /usr/include/sys/socket.h:28:11: note: previous declaration ‘ssize_t recv(int, void*, size_t, int)’ 28 | ssize_t recv (int, void *__buff, size_t __len, int __flags); | ^~~~ In file included from /D/Islandium/switch/build/Islandium/source/natives.cpp:22: /D/devkitPro/msys2/usr/include/w32api/winsock2.h:1029:34: error: conflicting declaration of C function ‘int recvfrom(SOCKET, char*, int, int, sockaddr*, int*)’ 1029 | WINSOCK_API_LINKAGE int WSAAPI recvfrom(SOCKET s,char *buf,int len,int flags,struct sockaddr *from,int *fromlen); | ^~~~~~~~ In file included from /D/devkitPro/msys2/mingw64/include/curl/system.h:422, from /D/devkitPro/msys2/mingw64/include/curl/curl.h:37, from /D/Islandium/switch/build/Islandium/source/natives.cpp:10: /usr/include/sys/socket.h:29:11: note: previous declaration ‘ssize_t recvfrom(int, void*, size_t, int, sockaddr*, socklen_t*)’ 29 | ssize_t recvfrom (int, void *__buff, size_t __len, int __flags, | ^~~~~~~~ In file included from /D/Islandium/switch/build/Islandium/source/natives.cpp:22: /D/devkitPro/msys2/usr/include/w32api/winsock2.h:1031:34: error: conflicting declaration of C function ‘int select(int, fd_set*, fd_set*, fd_set*, PTIMEVAL)’ 1031 | WINSOCK_API_LINKAGE int WSAAPI select(int nfds,fd_set *readfds,fd_set *writefds,fd_set *exceptfds,const PTIMEVAL timeout); | ^~~~~~ In file included from /usr/include/sys/types.h:50, from /usr/include/sys/_default_fcntl.h:210, from /usr/include/sys/fcntl.h:3, from /usr/include/fcntl.h:12, from /D/Islandium/switch/build/Islandium/source/natives.cpp:1: /usr/include/sys/select.h:76:5: note: previous declaration ‘int select(int, fd_set*, fd_set*, fd_set*, timeval*)’ 76 | int select __P ((int __n, fd_set *__readfds, fd_set *__writefds, | ^~~~~~ In file included from /D/Islandium/switch/build/Islandium/source/natives.cpp:22: /D/devkitPro/msys2/usr/include/w32api/winsock2.h:1033:34: error: conflicting declaration of C function ‘int send(SOCKET, const char*, int, int)’ 1033 | WINSOCK_API_LINKAGE int WSAAPI send(SOCKET s,const char *buf,int len,int flags); | ^~~~ In file included from /D/devkitPro/msys2/mingw64/include/curl/system.h:422, from /D/devkitPro/msys2/mingw64/include/curl/curl.h:37, from /D/Islandium/switch/build/Islandium/source/natives.cpp:10: /usr/include/sys/socket.h:32:11: note: previous declaration ‘ssize_t send(int, const void*, size_t, int)’ 32 | ssize_t send (int, const void *__buff, size_t __len, int __flags); | ^~~~ In file included from /D/Islandium/switch/build/Islandium/source/natives.cpp:22: /D/devkitPro/msys2/usr/include/w32api/winsock2.h:1034:34: error: conflicting declaration of C function ‘int sendto(SOCKET, const char*, int, int, const sockaddr*, int)’ 1034 | WINSOCK_API_LINKAGE int WSAAPI sendto(SOCKET s,const char *buf,int len,int flags,const struct sockaddr *to,int tolen); | ^~~~~~ In file included from /D/devkitPro/msys2/mingw64/include/curl/system.h:422, from /D/devkitPro/msys2/mingw64/include/curl/curl.h:37, from /D/Islandium/switch/build/Islandium/source/natives.cpp:10: /usr/include/sys/socket.h:34:11: note: previous declaration ‘ssize_t sendto(int, const void*, size_t, int, const sockaddr*, socklen_t)’ 34 | ssize_t sendto (int, const void *, size_t __len, int __flags, | ^~~~~~ In file included from /D/Islandium/switch/build/Islandium/source/natives.cpp:22: /D/devkitPro/msys2/usr/include/w32api/winsock2.h:1035:34: error: conflicting declaration of C function ‘int setsockopt(SOCKET, int, int, const char*, int)’ 1035 | WINSOCK_API_LINKAGE int WSAAPI setsockopt(SOCKET s,int level,int optname,const char *optval,int optlen); | ^~~~~~~~~~ In file included from /D/devkitPro/msys2/mingw64/include/curl/system.h:422, from /D/devkitPro/msys2/mingw64/include/curl/curl.h:37, from /D/Islandium/switch/build/Islandium/source/natives.cpp:10: /usr/include/sys/socket.h:36:7: note: previous declaration ‘int setsockopt(int, int, int, const void*, socklen_t)’ 36 | int setsockopt (int __s, int __level, int __optname, const void *optval, | ^~~~~~~~~~ In file included from /D/Islandium/switch/build/Islandium/source/natives.cpp:22: /D/devkitPro/msys2/usr/include/w32api/winsock2.h:1036:34: error: conflicting declaration of C function ‘int shutdown(SOCKET, int)’ 1036 | WINSOCK_API_LINKAGE int WSAAPI shutdown(SOCKET s,int how); | ^~~~~~~~ In file included from /D/devkitPro/msys2/mingw64/include/curl/system.h:422, from /D/devkitPro/msys2/mingw64/include/curl/curl.h:37, from /D/Islandium/switch/build/Islandium/source/natives.cpp:10: /usr/include/sys/socket.h:40:7: note: previous declaration ‘int shutdown(int, int)’ 40 | int shutdown (int, int); | ^~~~~~~~ In file included from /D/Islandium/switch/build/Islandium/source/natives.cpp:22: /D/devkitPro/msys2/usr/include/w32api/winsock2.h:1037:37: error: conflicting declaration of C function ‘SOCKET socket(int, int, int)’ 1037 | WINSOCK_API_LINKAGE SOCKET WSAAPI socket(int af,int type,int protocol); | ^~~~~~ In file included from /D/devkitPro/msys2/mingw64/include/curl/system.h:422, from /D/devkitPro/msys2/mingw64/include/curl/curl.h:37, from /D/Islandium/switch/build/Islandium/source/natives.cpp:10: /usr/include/sys/socket.h:41:7: note: previous declaration ‘int socket(int, int, int)’ 41 | int socket (int __family, int __type, int __protocol); | ^~~~~~ /D/Islandium/switch/build/Islandium/source/natives.cpp: In function ‘JAVA_INT com_thelogicmaster_switchgdx_SwitchSocket_create___java_lang_String_int_int_int_R_int(ThreadLocalData*, JAVA_OBJECT, JAVA_INT, JAVA_INT, JAVA_INT)’: /D/Islandium/switch/build/Islandium/source/natives.cpp:604:34: error: cannot convert ‘u_long*’ {aka ‘long unsigned int*’} to ‘__ms_u_long*’ {aka ‘unsigned int*’} 604 | ioctlsocket(fd, FIONBIO, &nonblocking); | ^~~~~~~~~~~~ | | | u_long* {aka long unsigned int*} In file included from /D/Islandium/switch/build/Islandium/source/natives.cpp:22: /D/devkitPro/msys2/usr/include/w32api/winsock2.h:1007:76: note: initializing argument 3 of ‘int ioctlsocket(SOCKET, int, __ms_u_long*)’ 1007 | WINSOCK_API_LINKAGE int WSAAPI ioctlsocket(SOCKET s,__LONG32 cmd,u_long *argp); | ^ /D/Islandium/switch/build/Islandium/source/natives.cpp:661:34: error: cannot convert ‘u_long*’ {aka ‘long unsigned int*’} to ‘__ms_u_long*’ {aka ‘unsigned int*’} 661 | ioctlsocket(fd, FIONBIO, &nonblocking); | ^~~~~~~~~~~~ | | | u_long* {aka long unsigned int*} In file included from /D/Islandium/switch/build/Islandium/source/natives.cpp:22: /D/devkitPro/msys2/usr/include/w32api/winsock2.h:1007:76: note: initializing argument 3 of ‘int ioctlsocket(SOCKET, int, __ms_u_long*)’ 1007 | WINSOCK_API_LINKAGE int WSAAPI ioctlsocket(SOCKET s,__LONG32 cmd,u_long *argp); | ^ /D/Islandium/switch/build/Islandium/source/natives.cpp: In function ‘JAVA_INT com_thelogicmaster_switchgdx_SwitchServerSocket_create___int_boolean_R_int(ThreadLocalData*, JAVA_INT, JAVA_BOOLEAN)’: /D/Islandium/switch/build/Islandium/source/natives.cpp:762:34: error: cannot convert ‘u_long*’ {aka ‘long unsigned int*’} to ‘__ms_u_long*’ {aka ‘unsigned int*’} 762 | ioctlsocket(fd, FIONBIO, &nonblocking); | ^~~~~~~~~~~~ | | | u_long* {aka long unsigned int*} In file included from /D/Islandium/switch/build/Islandium/source/natives.cpp:22: /D/devkitPro/msys2/usr/include/w32api/winsock2.h:1007:76: note: initializing argument 3 of ‘int ioctlsocket(SOCKET, int, __ms_u_long*)’ 1007 | WINSOCK_API_LINKAGE int WSAAPI ioctlsocket(SOCKET s,__LONG32 cmd,u_long *argp); | ^ /D/Islandium/switch/build/Islandium/source/natives.cpp: In function ‘JAVA_INT com_thelogicmaster_switchgdx_SwitchServerSocket_accept___int_R_int(ThreadLocalData*, JAVA_OBJECT, JAVA_INT)’: /D/Islandium/switch/build/Islandium/source/natives.cpp:826:34: error: cannot convert ‘u_long*’ {aka ‘long unsigned int*’} to ‘__ms_u_long*’ {aka ‘unsigned int*’} 826 | ioctlsocket(fd, FIONBIO, &nonblocking); | ^~~~~~~~~~~~ | | | u_long* {aka long unsigned int*} In file included from /D/Islandium/switch/build/Islandium/source/natives.cpp:22: /D/devkitPro/msys2/usr/include/w32api/winsock2.h:1007:76: note: initializing argument 3 of ‘int ioctlsocket(SOCKET, int, __ms_u_long*)’ 1007 | WINSOCK_API_LINKAGE int WSAAPI ioctlsocket(SOCKET s,__LONG32 cmd,u_long *argp); | ^ make[2]: *** [CMakeFiles/SwitchGDX.dir/build.make:15392: CMakeFiles/SwitchGDX.dir/source/natives.cpp.obj] Error 1 make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/SwitchGDX.dir/all] Error 2 make: *** [Makefile:91: all] Error 2 ```

Possible solutions

It's mostly caused by duplicate definitions of certain things in windows and cygwin headers, which to my understanding shouldn't happen because of the ifdef platform detection, but that's just my theory. The rest of errors can be easily fixed by casting, which should be no big deal.

I think the errors might just be caused by the compiler being too aggresive, so putting a extra flag might solve it, though i haven't tested it yet.

TheLogicMaster commented 2 years ago

That's strange. When I added UWP support recently, I definitely had everything compiling on Windows 10 with the newest devkitPro. I use a VM without anything else installed, aside from Visual Studio 2019 and JetBrains IDEs. It does look like it could be an issue with platform detection, and I did struggle getting the socket APIs to play nicely for both Unix and Windows, so maybe some of the ifdefs aren't working as intended.

Looking at the stack traces, it looks like the Windows APIs are being used rather than the Unix ones, so that's fine. The conversion errors seem to indicate that different function signatures are present, so potentially different compiler settings or different headers being included. I see sys/socket.h is being included in addition to winsock2.h, and it looks like curl.h is the culprit, so that's probably causing the duplicate definitions. Seems like there are dev environment differences, since including curl didn't cause any errors for me. Commenting out the curl code might resolve it.

The UWP build uses the Visual Studio compiler, so that one probably wouldn't have the same issue.

Clomclem commented 2 years ago

So, after a lot of trouble (mainly taking out some imports like curl and replacing u_long with __ms_u_long) I managed to get only 1 error, and it’s about the duplicate definition of the select function, so maybe that’ll be more manageable, I’ll make another comment later if I manage to fix it.

TheLogicMaster commented 1 year ago

With the C++ rewrite, I've gotten everything working on a clean Windows 10 install and updated the documentation accordingly, so hopefully any compilation issues should be resolved.