Not sure if this is a valid issue. xawd.c ----------------- #include <byteswap.h> ----------------- Compile with: dmd xawd.c -betterC Error: ----------------- /usr/bin/ld: /usr/lib64/gcc/x86_64-solus-linux/12/../../../../lib64/Scrt1.o: in function `_start': /home/build/YPKG/root/glibc/build/glibc-2.36/csu/../sysdeps/x86_64/start.S:103: undefined reference to `main' /usr/bin/ld: xawd.o: in function `_D10__builtins__T17__builtin_bswap16ZQuFNaNbNiNftZt': xawd.c:(.text._D10__builtins__T17__builtin_bswap16ZQuFNaNbNiNftZt[_D10__builtins__T17__builtin_bswap16ZQuFNaNbNiNftZt]+0x10): undefined reference to `_D4core5bitop8byteswapFNaNbNiNftZt' collect2: error: ld returned 1 exit status Error: linker exited with status 1 ----------------- This specific byteswap.h file has: ----------------- static __inline __uint16_t __bswap_16 (__uint16_t __bsx) { #if __GNUC_PREREQ (4, 8) return __builtin_bswap16 (__bsx); #else return __bswap_constant_16 (__bsx); #endif } ----------------- DMD64 D Compiler v2.103.0 Linux
The problem is that in druntime/src/__builtins.di, which is loaded on every compile of an ImportC program, defines: ushort __builtin_bswap16()(ushort value) { import core.bitop; return core.bitop.byteswap(value); } and core.bitop.byteswap is defined in the D runtime library, not the C one. Hence it shows up as an undefined symbol when a link is attempted.
-betterC is irrelevant for ImportC.
@WalterBright created dlang/dmd pull request #15224 "fix Issue 23877 - ImportC: Importing byteswap.h results in undefined …" fixing this issue: - fix Issue 23877 - ImportC: Importing byteswap.h results in undefined reference to core.bitop.byteswap https://github.com/dlang/dmd/pull/15224
dlang/dmd pull request #15224 "fix Issue 23877 - ImportC: Importing byteswap.h results in undefined …" was merged into master: - c9b63234d03cd95ca4da665c2765ec355525b398 by Walter Bright: fix Issue 23877 - ImportC: Importing byteswap.h results in undefined reference to core.bitop.byteswap https://github.com/dlang/dmd/pull/15224