I want to use libpfm4 library for Perf_Event
but compiling program which have library function
throws following error.
/tmp/ccYD603t.o: In function `main':
encod.c:(.text+0x44): undefined reference to `pfm_initialize'
encod.c:(.text+0x57): undefined reference to `pfm_strerror'
encod.c:(.text+0x97): undefined reference to `pfm_get_perf_event_encoding'
encod.c:(.text+0xaa): undefined reference to `pfm_strerror'
collect2: ld returned 1 exit status
please can any one tell me how configure library in system to resolve this error.
As noted in the comments, you're looking at a linker error. Because this is a common error we have a reference question for this:
What is an undefined reference/unresolved external symbol error and how do I fix it?
To tell you more about exactly what you're doing wrong we'll need to see how you're compiling. Briefly, you're likely #includeing library headers but not linking the library. The compiler is telling the linker that the compiled code will need entities declared in the library headers but then the linker chokes because it doesn't know the definitions of those entities.
Related
while compiling the code with compiler flag -fsanitize=bounds for clang-4.0 , i seem to be getting this linking error although there is no out of bound access that the code is doing.
Any help here when does the compiler throw this error - undefined reference to __ubsan_handle_out_of_bounds_abort.
Most likely you forgot to add -fsanitize=bounds to your linker flags.
I have some core libraries compiled in icc and I am using those libraries to build my code with the help of gcc.
I have included the -lm in linking command but I am still getting he following undefined references:
undefined reference to __libm_sse2_sin
undefined reference to __libm_sse2_sincos
undefined reference to __libm_sse2_pow
Does anyone know how to resolve this? According to my investigation this is happening due to use of different compilers but using icc instead of gcc is not an option for me.
Is there any extra library I need to add which have definition for these undefined references?
Whenever I include math.h to my c code I can't compile without the -lm option. I get this error message:
d.o: In function `refresh_position':
d.c:(.text+0x4df): undefined reference to `sqrt'
d.c:(.text+0x524): undefined reference to `sqrt'
collect2: error: ld returned 1 exit status
I can compile it with just typing -lm but my teacher says that if code doesn't work i will get 0 point from that homework. I want to know is this error occurs because of my code or because of my computer or c library. I have to be sure about it will run without any error on my teachers computer.
Some implementations such as gcc do not link the math library (called libm.a on most *nix implementations) by default, which is why you need to include the -lm when building the code.
Your teacher should be aware of issues like this, and as long as your code is using sqrt and other math routines correctly (using the right type for the inputs and output), he or she should be able to build your code such that it will run.
Banging my head against a wall with making a quick proof of concept app which links to a third party .so file.
I've produces a simple C file which calls a simple function in the .so file, it includes the header file also supplied by the vendor. Linking produces the following errors:
/usr/local/lib/xxx.so: undefined reference to `sprintf_s'
/usr/local/lib/xxx.so: undefined reference to `sendWCmdThread'
/usr/local/lib/xxx.so: undefined reference to `pthread_create'
/usr/local/lib/xxx.so: undefined reference to `pthread_cancel'
I can handle the pthread issues (-pthread option) but I'm at a loss for the other two errors. Expecially as Google provides zero results for 'sendWCmdThread'
Anyone help?
I'm writing a program dealing with threads that I've almost got working completely. Unfortunately, I'm hitting an error (repeated 4 times) who's syntax I'm not familiar with. Here's a quick snip-it of my compile commands, and the errors that follow:
gcc -o threads threads.cpp -pthread<br>
/tmp/ccy8maS0.o: In function `tenPercentA()':
threads.cpp:(.text+0xde): undefined reference to `ceil'
/tmp/ccy8maS0.o: In function `tenPercentB()':
threads.cpp:(.text+0x1c6): undefined reference to `ceil'
/tmp/ccy8maS0.o: In function `fiftPercentC()':
threads.cpp:(.text+0x2ae): undefined reference to `ceil'
/tmp/ccy8maS0.o: In function `fiftPercentD()':
threads.cpp:(.text+0x396): undefined reference to `ceil'
/tmp/ccy8maS0.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
I've already included the math.h library in my program, and I'm using the correct syntax for the call:
ceil(tempA);
Where tempA is a double holding the value I need to be rounded up.
Any suggestions? I've tried Google'ing these errors but, like most errors, it's hard to find specific examples with the same pattern as yours.
EDIT: I've solved all of the ceil related errors (using -lm on the command line) however the last error still remains, and I have no idea what it means, or how to fix it.
Referring the undefined reference to ceil():
You seem to be missing to link against libm.
Adding the option -lm to your call to gcc should solve this problem.
#includeing math.h is for the compiler to get to know ceil()'s defintion. The linker then later needs to know where ceil()'s implementation actually resides, namely in libm.