xiph / xiph/opus

CMake: #include <math.h> and link against -lm when checking if lrint is available

Open
#243 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
3.3k
Forks
808
PR merge metrics
No merged PRs in 30d

Description

The check for lrint in cmake\OpusConfig.cmake doesn't do its job properly and ends up silently dumping the following error into cmake errors.txt. Libopusfile does this check correctly though.
Determining if the function lrint exists failed with the following output:
Change Dir: /mnt/c/py/miniaudio/_skbuild/linux-x86_64-3.8/cmake-build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/ninja cmTC_939d2 && [1/2] Building C object CMakeFiles/cmTC_939d2.dir/CheckFunctionExists.c.o
: warning: conflicting types for built-in function ‘lrint’; expected ‘long int(double)’ [-Wbuiltin-declaration-mismatch]
/usr/share/cmake-3.16/Modules/CheckFunctionExists.c:7:3: note: in expansion of macro ‘CHECK_FUNCTION_EXISTS’
7 | CHECK_FUNCTION_EXISTS(void);
| ^~~~~~~~~~~~~~~~~~~~~
/usr/share/cmake-3.16/Modules/CheckFunctionExists.c:1:1: note: ‘lrint’ is declared in header ‘<math.h>’
+++ |+#include <math.h>
1 | #ifdef CHECK_FUNCTION_EXISTS
[2/2] Linking C executable cmTC_939d2
FAILED: cmTC_939d2
: && /usr/bin/cc -DCHECK_FUNCTION_EXISTS=lrint -rdynamic CMakeFiles/cmTC_939d2.dir/CheckFunctionExists.c.o -o cmTC_939d2 && :
/usr/bin/ld: CMakeFiles/cmTC_939d2.dir/CheckFunctionExists.c.o: in function main': CheckFunctionExists.c:(.text+0x14): undefined reference to lrint'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect cmake\OpusConfig.cmake and compare its lrint availability check with the corresponding libopusfile check mentioned in the issue. Reproduce the CMake configuration check, then verify that the completed check accounts for <math.h> and libm so the reported linker failure no longer occurs.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cmake
Domain
build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.