libm

Can CMake detect if I need to link to libm when using pow in C?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 11:42:40
问题 With some compilers, using pow and certain other functions in a C program requires linking to the m library. However, some compilers don't require this and would error out on linking to the m library. An almost identical situation exists for C++ with std::thread and pthread , but the CMake module FindThreads alleviates this entirely - is there some similar module for libm? What is the best way to detect what to do with CMake? This is my current solution, which is less than ideal because there

NDK: libm static linking

余生长醉 提交于 2019-12-04 03:40:42
I have a problem during try to compile sources with recent android-9 x86 platform. Primary question: why static library libm.a and dynamic libm.so are different? Problem is i've try to compile: /path/to/android-ndk-r8/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-gcc --sysroot=/path/to/android-ndk-r8/platforms/android-9/arch-x86 -I/path/to/android-ndk-r8/sources/cxx-stl/gnu-libstdc++/include -I/path/to/android-ndk-r8/sources/cxx-stl/gnu-libstdc++/libs/x86/include -L/path/to/android-ndk-r8/sources/cxx-stl/gnu-libstdc++/lib -L/path/to/android-ndk-r8/platforms/android-9/arch-x86

Can CMake detect if I need to link to libm when using pow in C?

点点圈 提交于 2019-12-03 08:29:47
With some compilers, using pow and certain other functions in a C program requires linking to the m library . However, some compilers don't require this and would error out on linking to the m library. An almost identical situation exists for C++ with std::thread and pthread , but the CMake module FindThreads alleviates this entirely - is there some similar module for libm? What is the best way to detect what to do with CMake? This is my current solution, which is less than ideal because there are many more C compilers than just GCC and MSVC: if(NOT MSVC) target_link_libraries(my-c-target

Why am I getting “undefined reference to sqrt” error even though I include math.h header? [duplicate]

[亡魂溺海] 提交于 2019-11-26 12:53:56
This question already has an answer here: undefined reference to sqrt (or other mathematical functions) 5 answers I'm very new to C and I have this code: #include <stdio.h> #include <math.h> int main(void) { double x = 0.5; double result = sqrt(x); printf("The square root of %lf is %lf\n", x, result); return 0; } But when I compile this with: gcc test.c -o test I get an error like this: /tmp/cc58XvyX.o: In function `main': test.c:(.text+0x2f): undefined reference to `sqrt' collect2: ld returned 1 exit status Why does this happen? Is sqrt() not in the math.h header file? I get the same error

Why am I getting “undefined reference to sqrt” error even though I include math.h header? [duplicate]

对着背影说爱祢 提交于 2019-11-26 03:35:47
问题 This question already has an answer here: undefined reference to sqrt (or other mathematical functions) 5 answers I\'m very new to C and I have this code: #include <stdio.h> #include <math.h> int main(void) { double x = 0.5; double result = sqrt(x); printf(\"The square root of %lf is %lf\\n\", x, result); return 0; } But when I compile this with: gcc test.c -o test I get an error like this: /tmp/cc58XvyX.o: In function `main\': test.c:(.text+0x2f): undefined reference to `sqrt\' collect2: ld