From where can i download C language libraries? [duplicate] - c

This question already has answers here:
sqrt() function link error
(5 answers)
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 4 years ago.
I have a problem that when i compile a program whit pow or cos it be like:
main':<br/>just-test.c:(.text+0x3d): undefined reference tosqrt'
just-test.c:(.text+0x5e): undefined reference to 'pow'
collect2: error: ld returned 1 exit status
p.s: "im using linux and atom editor"

You don't need to download anything. But you have to tell the linker, that it should add the math library to your executable. Do this by adding -lm to the linker command line.
-l adds a library to linking, and the math library is simply called m.

Related

Import zlib on stm32 microcontroller giving error Type undefined reference to `gzclose' [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 3 years ago.
I'm trying an example of compressing a file using zlib, on a stm32 microcontroller.
It's just giving med the compiler error
Type undefined reference to `gzclose'
I have looked on similar problems including the solution here on stackoverflow. Where it needs to be linked to zlib.
How do I do this when I'm Atollic TrueSTUDIO?
try add library to project ( project Properties -> C/C++ General -> Paths and Symbols -> Libraries)

Is this a glitch with online C compiler, gcc-7.2.0? [duplicate]

This question already has answers here:
Linking with GCC and -lm doesn't define ceil() on Ubuntu
(3 answers)
undefined reference to "only some math.h" functions
(4 answers)
Why do you have to link the math library in C?
(14 answers)
gcc: why is the -lm flag needed to link the math library? [duplicate]
Closed 5 years ago.
On an online C compiler called jdoodle, I tried this simple snippet below:
#include<math.h>
#include<stdio.h>
int main(void)
{
double f = 1.2;
//printf("%f\n", ceil(f));
printf("%f\n", ceil(1.2));
return 0;
}
It prints:
2.000000
Which is what I expected.
But when I change code to:
printf("%f\n", ceil(f));
//printf("%f\n", ceil(1.2));
The compiler complains:
/tmp/ccv6kz5w.o: In function `main':
jdoodle.c:(.text+0x23): undefined reference to `ceil'
collect2: error: ld returned 1 exit status
Its fairly simple and clear from the man page for ceil() that it takes a double variable as the only argument.
When I changed the compiler version to 5.3.0 from 7.2.0, both codes were compiled successfully and generated the expected output.
Why is the updated version of compiler complaining about it then?
If compiler is right about complaining it, can anyone tell me why ceil(f); would be a problematic piece of code so that gcc-7.2.0 is not considering it valid, surprisingly assigning 'an undefined reference error' to a valid library function?
Update: I tried the same snippet with codechef online compiler with C-GCC6.3, it compiles fine and generates the expected output.
The man page for ceil(3) document that:
you need to #include <math.h>
and that you should
Link with -lm.
You forgot to configure your online compiler to link with -lm; perhaps the one you are using don't offer such an option.
I recommend compiling on your own computer.

No linking required with some functions [duplicate]

This question already has answers here:
undefined reference to "only some math.h" functions
(4 answers)
Closed 5 years ago.
I just encountered a strange thing. While testing math.h I tried to use pow() and compile it. I did not have to link math.h .
But when I try the same with something like fmod() I have to link math.h while compiling the programm.
Why do I have to link the library in the second case but not in the first?
Your compiler may be replacing some usages of pow with a constant. For example, it could replace pow(2.0, 3.0) with 8.0. This is a good optimisation and means you no longer need the pow in math.h.
But your compiler probably can't replace fmod, or all usages of math functions, so it still needs to link to the math library.

Linux' dynamique linker : how to call a function from the main process from an .so object? [duplicate]

This question already has answers here:
How can a shared library (.so) call a function that is implemented in its loader code?
(4 answers)
Closed 6 years ago.
In my main source code, I defined a function named findConst(). In the same source, I'm loading a shared object (.so) using dlopen() et dlsym().
In this shared object, I have some code that use findConst() ... but unfortunately, when I run my progy, I got a lookup error :
./Selene: symbol lookup error: ./SelDirectFB.so: undefined symbol: findConst
What I need to do to solve this issue ?
Thanks
You can't do that and if you succeed to do so you shouldn't. Do the opposite, define findConst() in the shared object and then load it in the main program with dlsym().
Or even better, link the main program to the shared object and call the function directly.

g++ ubuntu multithreading undefined reference [duplicate]

This question already has answers here:
Undefined reference to pthread_create in Linux
(16 answers)
Closed 7 years ago.
I am writing a c code on ubuntu that creates a certain number of threads
I have already added pthreads library but when I run the code
it ends up with this error
Threads.cc:(.text+0x128): undefined reference to 'pthread_create'
Threads.cc:(.text+0x15b): undefined reference to 'pthread_join'
I am using ubuntu 15.04 virtual machine.
I have tried many suggested solutions, non of them worked!
any help would be appreciated
I have already added pthreads library [..]
No. You haven't. If you did you wouldn't get this problem. You probably mean to say you included <pthread.h>. But that doesn't link with pthreads library.
Add pthread at the end of your compilation options. For example,
gcc -o out myfile.c -pthread

Resources