-
Notifications
You must be signed in to change notification settings - Fork 394
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
CMake build with BUILD_PROG=ON
fails on Linux due to libm
#759
Comments
Thank you for those suggestions, Michael. I don't maintain the cmake files, but was wondering why about half of the programs that require including math.h are not in that list. Thank you also for PR #760. Someone will get to that soon. |
Can you please be more clear about what you are doing? E.g. steps to reproduction of issue? cd /tmp
git clone https://github.com/DanBloomberg/leptonica.git --depth 1
cd leptonica/
cmake -Bbuild -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_PREFIX_PATH=/usr -DCMAKE_MODULE_PATH=/usr/lib/cmake -DBUILD_PROG=ON .
cmake --build build --config Release |
I added programs using sqrt to |
Fedora is more standard and this is their workaround: https://src.fedoraproject.org/rpms/leptonica/blob/rawhide/f/leptonica_cmake.patch#_41 The difference is static vs shared build. You should be able to reproduce by running same commands with Specifically, can reproduce (on Ubuntu 22.04 / glibc 2.35 / aarch64) by updating one command in your example to:
For Homebrew, we run on Ubuntu 22.04 and use the system glibc 2.35 and gcc 11 so I think it should be reproducible on Debian. Our CI runs on x86_64(GitHub actions). I'm personally running on aarch64(armv8) in a docker container. So, I'd expect this to impact modern glibc. Haven't tested other C libraries, e.g. musl. Behavior would be similar if they use a shared library but could be different if inlining or something else. |
Trying #761 to see if CI can catch this EDIT: and it worked:
|
Sorry for the late reply. Thank you for example I am able to reproduce the problem. I tried several different compiler (clang, msvc, MinGW 8.1) to compile simple a program: #include<stdio.h>
#include <math.h>
int main() {
double x = pow(2.0, 3.0);
printf("Value of x = %f\n", x);
double factor = sqrt(2.0);
printf("Factor (sqrt of 2) = %f\n", factor);
return 0;
} none of them required linking |
Library does link to libm: Line 60 in e36609f
The example may be too simple as a constant can be computed at compile time. Can try moving to function and passing in as variables. Also make sure to run in separate steps like CMake does for compilation and linking. This is needed so the For example, assuming code is moved to function int main() {
return f(2.0, 3.0);
} $ /usr/bin/gcc -o test.o -c test.c
$ nm test.o
0000000000000058 T main
U pow
U printf
U sqrt
0000000000000000 T test
$ /usr/bin/gcc -o test test.o
/usr/bin/ld: test.o: in function `test':
test.c:(.text+0x18): undefined reference to `pow'
/usr/bin/ld: test.c:(.text+0x34): undefined reference to `sqrt'
collect2: error: ld returned 1 exit status
$ /usr/bin/gcc -o test test.o -lm
I think many modern Linux distros use |
But it is restricted to UNIX. We can do add UNIX to Line 18 in e36609f
or simplify that conditions to I saw some reports about a misbehaviour of programs when |
That is simplest option. I did try it in #760 and seemed to work.
|
Thanks. IMO most of Fedora patch should be applied. I need some time to evaluate effect of |
Was experimenting with CMake build at Homebrew Homebrew/homebrew-core#194875 (mainly due to #757) and noticed the Linux build kept failing on libm.
Probably similar to BSD (d5c36c8).
One note is that failure is happening in a file not specified in list, i.e.
blend4_reg
leptonica/prog/CMakeLists.txt
Line 2 in 96a3d74
Can also see Fedora's workaround to always use
-lm
- https://src.fedoraproject.org/rpms/leptonica/blob/rawhide/f/leptonica_cmake.patch#_41Many of these look like test programs, so perhaps putting them behind a CMake option so that users can build only the
INSTALL_PROGS
would be useful.The text was updated successfully, but these errors were encountered: