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

Build fails with uclibc: src/util.cc:426:28: error: 'getloadavg' was not declared in this scope #985

Closed
tstellar opened this issue Jul 6, 2015 · 7 comments

Comments

@tstellar
Copy link

tstellar commented Jul 6, 2015

Hi,

The ninja builds fails on Linux systems that use uclibc as the C standard library rather than glibc:

i686-gentoo-linux-uclibc-g++ -O2 -march=i686 -pipe -Wno-deprecated -DNINJA_PYTHON="/usr/bin/python2.7" -DNI/graphviz.cc src/manifest_parser.cc src/eval_env.cc src/line_printer.cc src/subprocess-posix.cc src/debug_fc src/lexer.cc -o ninja.bootstrap
src/util.cc: In function 'double GetLoadAverage()':
src/util.cc:426:28: error: 'getloadavg' was not declared in this scope
if (getloadavg(loadavg, 3) < 0) {
^

@nico
Copy link
Collaborator

nico commented Jul 6, 2015

http://linux.die.net/man/3/getloadavg says that this is in stdlib.h which util.cc does include, and http://linux.die.net/man/7/feature_test_macros says "If no feature test macros are explicitly defined, then the following feature test macros are defined by default: _BSD_SOURCE, _SVID_SOURCE, _POSIX_SOURCE, and _POSIX_C_SOURCE=200809L". So I'm not sure what uclibc needs.

@tstellar
Copy link
Author

tstellar commented Jul 6, 2015

I think those man pages are for glibc an not linux in general.

My understanding is that the reason uclibc doesn't implement getloadavg, is because it is not part of the POSIX specification. I think uses of getloadavg on linux will need to be guarded by something like #if defined(GLIBC) if ninja wants to support alternative standard library implementations, like uclibc.

@nico
Copy link
Collaborator

nico commented Jul 7, 2015

ninja doesn't have an opinion on this. If someone wants to use ninja with uclibc and doing so isn't too ugly, we'd merge the patch.

@jbergstroem
Copy link

musl provides a generic getloadavg.c to mitigate this (pretty common use). I reckon we copy that, put it into ninja and provide it for systems that lack it (so far, my only knowns are ulibc and ulibc-ng)

@evmar
Copy link
Collaborator

evmar commented Oct 5, 2015

musl's implementation is essentially this with error handling, where "b" is the output array:

    FILE *f = fopen("/proc/loadavg", "rbe");
    i = fscanf(f, "%lf %lf %lf", b, b+1, b+2);

https://github.com/cloudius-systems/musl/search?utf8=%E2%9C%93&q=getloadavg

@jbergstroem
Copy link

@martine thats the old version. The newer uses sysinfo.h: http://git.musl-libc.org/cgit/musl/commit/?id=20cbd607759038dca57f84ef7e7b5d44a3088574

@jbergstroem
Copy link

Want me to file a PR with the suggested change?

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

4 participants