Using exp101 and log101 functions in C - c

I am trying to use the function exp1 and log101 which take long doubles as input and output long doubles in turn. However, when I try to compile the file I get the following error message:
/tmp/ccIvBVbG.o: In function `main':
derivative.c:(.text+0x250): undefined reference to `log101'
collect2: ld returned 1 exit status
I have included math.h library and also provided the -lm option. What is the remedy to this issue? Any help and comments are appreciated.
Thanks
P.S. Compiler is GCC on 32-bit Ubuntu 12.04 LTS

The names of the functions you are trying to use are exp10l and log10l. The last character in the name is a lowercase L, not another 1.

Related

Getting undeclared function and undefined symbol errors with rand_r when compiling a multithread C program on Windows

I am creating many threads and each one should output a random number.
I know that srand() with rand is not thread-safe and indeed all the output numbers are the same.
So I tried to use rand_r but I get the following error on my Windows terminal
main.c:47:16: warning: implicit declaration of function 'rand_r'; did you mean 'rand'? [-Wimplicit-function-declaration]
result= ( (rand_r(&seed) % (high+1-low) ) + low);
^~~~~~
rand
main.c: In function 'customerServe':
main.c:333:1: warning: control reaches end of non-void function [-Wreturn-type]
}
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe:
C:\Users\allys\AppData\Local\Temp\ccSslADA.o:main.c:(.text+0xe): undefined
reference to `rand_r'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe:
C:\Users\allys\AppData\Local\Temp\ccSslADA.o:main.c:(.text+0x41c):
undefined reference to `rand_r'
collect2.exe: error: ld returned 1 exit status
Thank you
I saw from the post tags that you are using the "pthreads" library which stands for POSIX threads. Therefore this project cannot be run on Windows since it does not support the "lpthread" flag on your system.
If you insist on working on a Windows machine, you could use something like this which lets the developer work on an Ubuntu terminal from windows. While having access to an Ubuntu-like system where the lpthreads library is supported, you can move on with your project. Another possible solution could be using docker to compile & run your project on an isolated ubuntu environment but this is kind of an overkill.
Let me know if this helped!
I needed to specify a late enough Posix source to avoid this warning, e.g.:
gcc -Wall -std=c11 -D_POSIX_C_SOURCE=199506L pi.c -o pi -lm -lpthread

Struggling compiling a simple c program (gcc)

I have a very old C program and want to compile to Windows. So I try doing this:
gcc -DNO_GLIBC=1 sakide.c -o sakide.exe
and this returns:
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0xa4): undefined reference to `ekiGetLibVersion'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0x6b6): undefined reference to `ekiGetLibVersion'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0x8ff): undefined reference to `ekiEncodeUrl'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0x954): undefined reference to `ekiDecodeUrl'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0x993): undefined reference to `ekiDecodeUrl'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0xa62): undefined reference to `ekiGetKeyInfo'
collect2.exe: error: ld returned 1 exit status
This ekiGetLibVersion is in a .h file:
INT EKIAPI ekiGetLibVersion(char *outBuffer, LPINT outBufferSize);
and I also have a .dll name of it.
Ive never compiled anything with C though
On windows you cannot link against directly with the .dll, you have to link the import library, name .lib. For more information, refer:
On dynamic linking:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682592(v=vs.85).aspx
On implicit linking:
https://msdn.microsoft.com/en-us/library/d14wsce5.aspx
You are getting linker errors.
You need to link the library (or object file) where those functions are defined.
Undefined reference usually means the compiler has not seen a proper declaration for this variable. Did you include the header file (which defines this variable) in your C program ?
#include "header_file.h"

make error using GNU/GCC quad precision library

When using Cygwin and GCC under Win 7 and the quad precision library:
gcc -c lquad.c
... this runs OK, but
gcc lquad.o
... produces the following error:
/tmp/ccLM2lOn.o:lquad.c:(.text+0xdb3): undefined reference to `sqrtq'
collect2: error: ld returned 1 exit status
I have #include quadmath.h in a C source, and the __float128 type works, but not the functions (e.g. sqrtq above). This header file has all the relevant externs, e.g.:
extern __float128 sqrtq (__float128) __quadmath_throw;
I found a dll cygquadmath-0.dll which definitely has these functions in it. It is in 3 places in the Cygwin installation. Additionally, I copied it to Windows\System, but that did not help.
There is a related question here, but nothing helped me there and it is not exactly the same error: Quadruple Precision in C++ (GCC)
You are looking for a compiler solution when what you need is a linker solution:
Your code is compiling as it should, so no change in the code would solve your problem:
/tmp/ccLM2lOn.o:lquad.c:(.text+0xdb3): undefined reference to `sqrtq'
collect2: error: ld returned 1 exit status
The undefined reference to errors indicate a function needed by your object is in another library.
As suggested by #Marc Glisse, try adding -lquadmath to your linker line.

Lua compilation link error

When I try to compile a little lua program, I get these errors :
/usr/lib//liblua52.so: undefined reference to `dlsym'
/usr/lib//liblua52.so: undefined reference to `dlerror'
/usr/lib//liblua52.so: undefined reference to `dlopen'
/usr/lib//liblua52.so: undefined reference to `dlclose'
Of course, I link with -ldl. I have lua5.2-dev installed on my ubuntu.
If you need any more infos ask me.
Thanks!
When I try to compile a little lua program, I get these errors
No. You get these errors when you link the program.
The fix is to add -ldl at the end of your link line.
The easy way to get this error is to have your PLAT variable set wrong in the Makefile. You need to set it in the top level Makefile and the src/Makefile.
The legal values show up about 10 lines down from the definition.
Ensure -ldl is exactly at the end of your link line as Employed Russian mentioned

How to initialize SNMP in C

Can anyone tell me how to initialize a SNMP agent in c using SNMP library?
The call to "init_agent()" is not working.
I read somewhere that "init_agent()" function should be used before "init_snmp()".
Here is what I am getting while compiling the code:
/tmp/ccEiSj2l.o: In function `main':
agent1.c:(.text+0x95): undefined reference to `init_agent'
collect2: ld returned 1 exit status
I have linked the compiler to snmp library using "-lsnmp".
Did you try passing required libraries to your compiler? Try passing output of the script net-snmp-config --libs . (Put back quotes surrounding that command).
I am used to using Net-SNMP for these things, and if you are attempting to create an agent with Net-SNMP, then you will need to link against the agent library (in addition to whatever other libraries you may be using):
-lnetsnmpagent

Resources