Skip to content

[BUG] Build fails with clang & musl due to missing header #312

@tribals

Description

@tribals

Clight version the issue has been seen with:

4.11

Used distribution:

Chimera

Describe the bug

Chimera is based on musl libc & LLVM compiler collection. It also applies many hardening options by default. When tried to build Clight on it, got this:

error: call to undeclared function 'open'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
Full log
[26/27] Building C object CMakeFiles/clight.dir/src/utils/log.c.o
FAILED: CMakeFiles/clight.dir/src/utils/log.c.o 
/usr/lib/ccache/bin/clang -DCONFDIR=\"/etc/clight\" -DDATADIR=\"/usr/share/clight\" -DLIBSYSTEMD_VERSION=255 -DOLDCONFDIR=\"/etc/default\" -DVERSION=\"4.11-\" -D_GNU_SOURCE -I/builddir/clight-4.11/src -I/builddir/clight-4.11/src/conf -I/builddir/clight-4.11/src/modules -I/builddir/clight-4.11/src/utils -I/builddir/clight-4.11/src/pubsub -I/usr/include/elogind -ffile-prefix-map=/builddir/clight-4.11=. -Wformat -Werror=format-security -ftrivial-auto-var-init=zero -fstack-clash-protection -fno-omit-frame-pointer -fsanitize=signed-integer-overflow,integer-divide-by-zero -fsanitize-trap=signed-integer-overflow,integer-divide-by-zero -fno-sanitize-recover -flto=thin -O2 -g2 -std=gnu11 -MD -MT CMakeFiles/clight.dir/src/utils/log.c.o -MF CMakeFiles/clight.dir/src/utils/log.c.o.d -o CMakeFiles/clight.dir/src/utils/log.c.o -c /builddir/clight-4.11/src/utils/log.c
../src/utils/log.c:33:14: error: call to undeclared function 'open'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
   33 |     int fd = open(log_path, O_CREAT | O_WRONLY, 0644);
      |              ^
../src/utils/log.c:33:29: error: use of undeclared identifier 'O_CREAT'
   33 |     int fd = open(log_path, O_CREAT | O_WRONLY, 0644);
      |                             ^
../src/utils/log.c:33:39: error: use of undeclared identifier 'O_WRONLY'
   33 |     int fd = open(log_path, O_CREAT | O_WRONLY, 0644);
      |                                       ^
3 errors generated.
ninja: build stopped: subcommand failed.

Expected behavior

Build should not fail.

To Reproduce

Well, you need to bootstrap compatible environment to reproduce bug. Fortunately, they provide rootfs which you can spawn in container etc. You can find build template for clight here.

So,

$ git clone cports.git
$ ./cbuild bootstrap
$ rm user/clight/patches/*.patch
$ ./cbuild build user/clight

Watch it failing.

Possible solution

Probably will be as simple as adding <fcntl.h> to src/utils/log.c.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions