Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zip doesn't compile on 32b system with GCC 9.2.0 #110

Closed
russkel opened this issue Nov 11, 2019 · 12 comments
Closed

zip doesn't compile on 32b system with GCC 9.2.0 #110

russkel opened this issue Nov 11, 2019 · 12 comments
Assignees
Labels
bug Something isn't working

Comments

@russkel
Copy link

russkel commented Nov 11, 2019

Trying to compile assimp for Alpine Linux on 32bit platforms and there seems to be an issue with ssize_t decleration:

[ 62%] Building CXX object code/CMakeFiles/assimp.dir/__/contrib/poly2tri/poly2tri/sweep/cdt.cc.o
In file included from /home/buildozer/aports/testing/assimp/src/assimp-5.0.0/code/3MF/D3MFExporter.cpp:61:
/home/buildozer/aports/testing/assimp/src/assimp-5.0.0/contrib/zip/src/zip.h:30:15: error: conflicting declaration 'typedef long int ssize_t'
   30 | typedef long  ssize_t;  /* byte count or error */
      |               ^~~~~~~
In file included from /usr/include/stdio.h:26,
                 from /usr/include/fortify/stdio.h:22,
                 from /usr/include/c++/9.2.0/cstdio:42,
                 from /usr/include/c++/9.2.0/ext/string_conversions.h:43,
                 from /usr/include/c++/9.2.0/bits/basic_string.h:6493,
                 from /usr/include/c++/9.2.0/string:55,
                 from /usr/include/c++/9.2.0/stdexcept:39,
                 from /usr/include/c++/9.2.0/array:39,
                 from /usr/include/c++/9.2.0/tuple:39,
                 from /usr/include/c++/9.2.0/bits/unique_ptr.h:37,
                 from /usr/include/c++/9.2.0/memory:80,
                 from /home/buildozer/aports/testing/assimp/src/assimp-5.0.0/code/3MF/D3MFExporter.h:44,
                 from /home/buildozer/aports/testing/assimp/src/assimp-5.0.0/code/3MF/D3MFExporter.cpp:45:
/usr/include/bits/alltypes.h:151:15: note: previous declaration as 'typedef int ssize_t'
  151 | typedef _Addr ssize_t;
      |               ^~~~~~~

CI output might be of interest: https://cloud.drone.io/alpinelinux/aports/13069 and AL PR alpinelinux/aports#11998

I posted this to assimp/assimp#2733 as well.

@russkel
Copy link
Author

russkel commented Nov 11, 2019

Is there a reason size_t is being redefined?

@kuba-- kuba-- added the bug Something isn't working label Nov 11, 2019
@kuba-- kuba-- self-assigned this Nov 11, 2019
@kuba--
Copy link
Owner

kuba-- commented Nov 11, 2019

Thanks @russkel - I'll take a look.

It was added in commit: 635ef1d

for 64-bit Windows:

// 64-bit Windows is the only mainstream platform
// where sizeof(long) != sizeof(void*)

It's not a problem with size_t but with redefined ssize_t
If we have ssize_t one of

_SSIZE_T_DEFINED
_SSIZE_T_DEFINED_
_SSIZE_T
_SSIZE_T_
__ssize_t_defined

should be defined. I'll take a look what GCC 9.X. defines.

BTW. Alpine uses musl instead of libc, so I'll have to take a look into this particular distro.

@kuba--
Copy link
Owner

kuba-- commented Nov 11, 2019

Looks adding __DEFINED_ssize_t (which is what musl has) to https://github.com/kuba--/zip/blob/master/src/zip.h#L22 may solve the problem but I'll have to double check it.

@kuba--
Copy link
Owner

kuba-- commented Nov 11, 2019

@russkel - I was able to compile this library on Alpine with gcc 9.2.0, without any problems.
Anyway, just in case I pushed PR: https://github.com/kuba--/zip/pull/111/files
which IMO should fix the potential issue. It just checks/defines another __DEFINED_ssize_t which is used by gcc on Alpine.
PTAL if it works for you

@kuba-- kuba-- closed this as completed Nov 12, 2019
@kuba--
Copy link
Owner

kuba-- commented Nov 12, 2019

@russkel Please feel free to reopen, if the issue still happens.
I'm gonna release a new version with the fix

@russkel
Copy link
Author

russkel commented Nov 13, 2019

hi @kuba-- thanks for this. I haven't had a chance to test it yet but I will later this evening and will report back! Thanks again for quick fix.

@russkel
Copy link
Author

russkel commented Nov 14, 2019

@kuba-- 👍 compiling fine. Thanks for the fix.

@randomMesh
Copy link

randomMesh commented Feb 3, 2020

Hi,

i try to compile latest ASSIMP (which uses zip) on FreeBSD 12.1 32Bit with GCC 9.2.0 and there still is an error regarding typedef redefinition:

[ 65%] Building C object code/CMakeFiles/assimp.dir/__/contrib/zip/src/zip.c.o
In file included from /home/foo/development/libs/assimp/contrib/zip/src/zip.c:39:

/home/foo/development/libs/assimp/contrib/zip/src/zip.h:31:14: error: typedef redefinition with different types ('long' vs '__ssize_t' (aka 'int'))

typedef long ssize_t; /* byte count or error */
             ^

/usr/include/sys/types.h:206:19: note: previous definition is here
typedef __ssize_t       ssize_t;
                        ^

1 error generated.
*** Error code 1

I see that @kimkulling added your fix to the master branch last year, but this doesn't seem to work on FreeBSD. What should i do?

@kuba--
Copy link
Owner

kuba-- commented Feb 3, 2020

@randomMesh - I'll take a look on define pre-proc. in freebsd library and update zip.c.
But if you have a easy access to FreeBSD, you can check /usr/include/sys/types.h file and try to fix by adding ifdef

@randomMesh
Copy link

Hi,

thanks for the quick answer. I made it compile.

I had a look at /usr/include/sys/types.h which looks like this:

#ifndef _SSIZE_T_DECLARED
typedef	__ssize_t	ssize_t;
#define	_SSIZE_T_DECLARED
#endif

So i added this to zip.h:

diff --git a/contrib/zip/src/zip.h b/contrib/zip/src/zip.h
index a48d64d6..d85306c8 100644
--- a/contrib/zip/src/zip.h
+++ b/contrib/zip/src/zip.h
@@ -21,7 +21,7 @@ extern "C" {
 
 #if !defined(_SSIZE_T_DEFINED) && !defined(_SSIZE_T_DEFINED_) &&               \
     !defined(__DEFINED_ssize_t) && !defined(__ssize_t_defined) &&              \
-    !defined(_SSIZE_T) && !defined(_SSIZE_T_)
+    !defined(_SSIZE_T) && !defined(_SSIZE_T_) && !defined(_SSIZE_T_DECLARED)
 
 // 64-bit Windows is the only mainstream platform
 // where sizeof(long) != sizeof(void*)
@@ -37,6 +37,7 @@ typedef long ssize_t; /* byte count or error */
 #define __ssize_t_defined
 #define _SSIZE_T
 #define _SSIZE_T_
+#define _SSIZE_T_DECLARED
 
 #endif
 

Thanks for the help!

@zeehead
Copy link

zeehead commented Apr 27, 2022

Hi @kuba--

so, I'm working on some code using Arduino IDE (2.0.0-rc6) and Blynk library, installed the latest esp32 board package (v 2.0.2).

And my code does compile, but still shows a red underline under the left bracket on

#include <BlynkSimpleEsp32_BT.h>

and it says this:

In included file: typedef redefinition with different types ('int' vs '_ssize_t' (aka 'long long'))clang(redefinition_different_typedef)
arch.h(202, 13): Error occurred here
types.h(184, 18): Previous definition is here

The path for types.h:

C:\Users\User\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2\xtensa-esp32-elf\sys-include\sys\types.h

and this is the definition:

#ifndef _SSIZE_T_DECLARED
typedef _ssize_t ssize_t;
#define	_SSIZE_T_DECLARED
#endif

Path for arch.h:

C:\Users\User\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.2\tools\sdk\esp32\include\lwip\lwip\src\include\lwip\arch.h

and this is where the error ocurred:

#ifdef SSIZE_MAX
/* If SSIZE_MAX is defined, unistd.h should provide the type as well */
#ifndef LWIP_NO_UNISTD_H
#define LWIP_NO_UNISTD_H 0
#endif
#if !LWIP_NO_UNISTD_H
#include <unistd.h>
#endif
#else /* SSIZE_MAX */
typedef int ssize_t;
#define SSIZE_MAX INT_MAX
#endif /* SSIZE_MAX */

/* some maximum values needed in lwip code */
#define LWIP_UINT32_MAX 0xffffffff

Could you help me out here? I'm not sure what exactly I should change now in my case. Or should I just leave it, since it still compiles?

BTW, I hope I'm not posting in the wrong place here.

@kuba--
Copy link
Owner

kuba-- commented Apr 27, 2022

@zeehead - size_t is tricky. On most platforms it's defined, but in a different way. But sometimes (very rarely) it's not defined at all. That's why we have the ifdef here: https://github.com/kuba--/zip/blob/master/src/zip.h#L37

Anyway, you can give me your platform name (how it's defined), so I can add it to the mentioned ifdef or you can (as a workaround):
#define _POSIX_C_SOURCE before you include zip.h.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants