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

Compilation Error #92

Open
smileaf419 opened this issue May 3, 2023 · 4 comments
Open

Compilation Error #92

smileaf419 opened this issue May 3, 2023 · 4 comments

Comments

@smileaf419
Copy link

Using: cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release -DWITH_SYSTEM_ZLIB=1 -DCMAKE_C_COMPILER=clang -D CMAKE_C_STANDARD=11 -D CMAKE_C_EXTENSIONS=0

-- The C compiler identification is Clang 16.0.2
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found ZLIB: /lib/libz.so (found version "1.2.13")
-- Configuring done (0.2s)
-- Generating done (0.0s)
-- Build files have been written to: /var/tmp/spkg/libchdr-master/build
[ 4%] Building C object deps/lzma-22.01/CMakeFiles/lzma.dir/src/Alloc.c.o
[ 8%] Building C object deps/lzma-22.01/CMakeFiles/lzma.dir/src/Bra86.c.o
[ 12%] Building C object deps/lzma-22.01/CMakeFiles/lzma.dir/src/BraIA64.c.o
[ 16%] Building C object deps/lzma-22.01/CMakeFiles/lzma.dir/src/CpuArch.c.o
[ 20%] Building C object deps/lzma-22.01/CMakeFiles/lzma.dir/src/Delta.c.o
[ 24%] Building C object deps/lzma-22.01/CMakeFiles/lzma.dir/src/LzFind.c.o
[ 28%] Building C object deps/lzma-22.01/CMakeFiles/lzma.dir/src/Lzma86Dec.c.o
[ 32%] Building C object deps/lzma-22.01/CMakeFiles/lzma.dir/src/LzmaDec.c.o
[ 36%] Building C object deps/lzma-22.01/CMakeFiles/lzma.dir/src/LzmaEnc.c.o
[ 40%] Building C object deps/lzma-22.01/CMakeFiles/lzma.dir/src/Sort.c.o
[ 44%] Linking C static library liblzma.a
[ 44%] Built target lzma
[ 48%] Building C object CMakeFiles/chdr-static.dir/src/libchdr_bitstream.c.o
[ 52%] Building C object CMakeFiles/chdr-static.dir/src/libchdr_cdrom.c.o
[ 56%] Building C object CMakeFiles/chdr-static.dir/src/libchdr_chd.c.o
/var/tmp/spkg/libchdr-master/src/libchdr_chd.c:814:10: warning: implicit conversion from enumeration type 'enum huffman_error' to different enumeration type 'chd_error' (aka 'enum _chd_error') [-Wenum-conversion]
return err;
~~~~~~ ^~~
/var/tmp/spkg/libchdr-master/src/libchdr_chd.c:2993:6: error: call to undeclared function 'ftello'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
p = core_stdio_ftell_impl(fp);
^
/var/tmp/spkg/libchdr-master/src/libchdr_chd.c:2987:32: note: expanded from macro 'core_stdio_ftell_impl'
#define core_stdio_ftell_impl ftello
^
/var/tmp/spkg/libchdr-master/src/libchdr_chd.c:2993:6: note: did you mean 'ftell'?
/var/tmp/spkg/libchdr-master/src/libchdr_chd.c:2987:32: note: expanded from macro 'core_stdio_ftell_impl'
#define core_stdio_ftell_impl ftello
^
/usr/include/stdio.h:718:17: note: 'ftell' declared here
extern long int ftell (FILE *__stream) __wur;
^
/var/tmp/spkg/libchdr-master/src/libchdr_chd.c:2994:2: error: call to undeclared function 'fseeko'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
core_stdio_fseek_impl(fp, 0, SEEK_END);
^
/var/tmp/spkg/libchdr-master/src/libchdr_chd.c:2986:32: note: expanded from macro 'core_stdio_fseek_impl'
#define core_stdio_fseek_impl fseeko
^
/var/tmp/spkg/libchdr-master/src/libchdr_chd.c:2994:2: note: did you mean 'fseek'?
/var/tmp/spkg/libchdr-master/src/libchdr_chd.c:2986:32: note: expanded from macro 'core_stdio_fseek_impl'
#define core_stdio_fseek_impl fseeko
^
/usr/include/stdio.h:713:12: note: 'fseek' declared here
extern int fseek (FILE __stream, long int __off, int __whence);
^
/var/tmp/spkg/libchdr-master/src/libchdr_chd.c:3031:9: error: call to undeclared function 'fseeko'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
return core_stdio_fseek_impl((FILE
)file->argp, offset, whence);
^
/var/tmp/spkg/libchdr-master/src/libchdr_chd.c:2986:32: note: expanded from macro 'core_stdio_fseek_impl'
#define core_stdio_fseek_impl fseeko
^
1 warning and 3 errors generated.
make[2]: *** [CMakeFiles/chdr-static.dir/build.make:104: CMakeFiles/chdr-static.dir/src/libchdr_chd.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:118: CMakeFiles/chdr-static.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

@rtissera
Copy link
Owner

rtissera commented May 3, 2023

Can you share more on your building environment ?
Thanks :)

@smileaf419
Copy link
Author

I run a self-built LFS-referenced variant. (Sort of experimental toy: https://github.com/smileaf419/spkg)
The error was originally found building ares.
No cflags are set (an output of ENV can also be found within the bug report there)

@rtissera
Copy link
Owner

rtissera commented May 3, 2023

Ok, let me try to reproduce and come back to you.
Obviously sounds like fseeko/ftello are not detected for some reason.

@invertego
Copy link
Contributor

invertego commented May 4, 2023

To provide more context, ares currently builds all C source files, including those from libchdr, with -std=c11. This causes __STRICT_ANSI__ to be defined, and as a result glibc does not define certain POSIX APIs that it will otherwise define if you specify no standard or one of the GNU variants (e.g. -std=gnu11). fseeko/ftello are POSIX APIs, not standard C.

There are many macros supported by glibc that can influence these definitions:

  • Defining _POSIX_C_SOURCE >= 200112L will enable fseeko/ftello among many others
  • Defining _XOPEN_SOURCE >= 600 will have a similar effect (implicitly defining _POSIX_C_SOURCE)
  • Defining _GNU_SOURCE will enable a superset of the above
  • Defining _LARGEFILE_SOURCE will enable fseeko/ftello
  • Defining _LARGEFILE64_SOURCE will enable fseeko64/ftello64
  • Defining _FILE_OFFSET_BITS=64 will cause fseeko/ftello to be 64-bit even on 32-bit systems

References:
https://man7.org/linux/man-pages/man7/feature_test_macros.7.html
https://github.com/bminor/glibc/blob/master/include/features.h

For ares, we can work around this by tweaking the flags passed to the compiler, but there's an opportunity to make the following code more robust across varying compilation environments.

libchdr/src/libchdr_chd.c

Lines 2973 to 2988 in fec8ab9

#if defined USE_LIBRETRO_VFS
#define core_stdio_fseek_impl fseek
#define core_stdio_ftell_impl ftell
#elif defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(__WIN64__)
#define core_stdio_fseek_impl _fseeki64
#define core_stdio_ftell_impl _ftelli64
#elif defined(_LARGEFILE_SOURCE) && defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64
#define core_stdio_fseek_impl fseeko64
#define core_stdio_ftell_impl ftello64
#elif defined(__PS3__) && !defined(__PSL1GHT__) || defined(__SWITCH__) || defined(__vita__)
#define core_stdio_fseek_impl(x,y,z) fseek(x,(off_t)y,z)
#define core_stdio_ftell_impl(x) (off_t)ftell(x)
#else
#define core_stdio_fseek_impl fseeko
#define core_stdio_ftell_impl ftello
#endif

There are a couple of issues with this code as it stands:

  • It assumes the availability of POSIX APIs by placing them in the final #else case. If they stay here (as opposed to being guarded by some additional checks), then appropriate defines should be added to the top of the file before the first #include to guarantee that fseeko/ftello are defined.
  • The current checks for fseeko64/ftello64 are erroneous and do not correspond to the condition that causes them to be defined (i.e. _LARGEFILE64_SOURCE being defined). This case should be revised or removed entirely.

There are a lot of options for which macros to define, of course. One or more of _POSIX_C_SOURCE/_XOPEN_SOURCE/_GNU_SOURCE/_LARGEFILE_SOURCE combined with _FILE_OFFSET_BITS should cover the bases, though. For what it's worth, the GNU libc manual recommends _GNU_SOURCE, though it is by far the most expansive.

As an aside, none of this seems to be an issue with BSD libc. It defines fseeko/ftello even with -std=c11 and the offsets are always 64-bit. I have not examined other C standard library implementations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants