This question already has answers here:
Getting undefined reference to 'clock_gettime' error, for curl program
(2 answers)
Closed 5 years ago.
I have this piece of c code that I am in charge of speeding up. The code is put onto a RasPi and compiled. Two years ago the code was put on and compiled and it works. Now when I try to compile the same file it says there's an undefined reference to 'clock_gettime'. I looked it up and that function is defined in time.h. I thought that maybe that header wasn't installed or called in the code. At the beginning of the code it does say #include so that's not the problem. I checked if the time.h header was installed on the RasPi and it was there with the other headers. I opened it up with nano and the clock_gettime function was defined, so that's not the problem. What should I do? How do I solve this problem?
clock_gettime(2):
#include <time.h>
...
Link with -lrt (only for glibc versions before 2.17).
Related
This question already has answers here:
difference between <stdlib.h> and <malloc.h>
(6 answers)
Closed 3 years ago.
A customer's code is expecting to find an include file malloc.h in one of the "usual suspect" locations. On my Mac, AFAICT, there is no malloc.h, at least not in any place you would expect to find it, such as /usr/include, /usr/local/include, or /opt/local/include. Since the malloc() is usually defined in stdlib.h, and since the code includes stdlib.h anyway, I was able to get the code to build by just commenting out the few includes of malloc.h. I am building with gcc.
But two questions: Is my gcc messed up somehow? Should that file be there? Also, the code bombs almost immediately with a seg fault that I haven't been able to track down yet. Could this be the consequence of using the wrong malloc()?
The malloc.h is deprecated and should not be used. It contains some non-standard functions too. If you want to use malloc, then include stdlib.h. Not even the C89 standard mentions malloc.h
If it's the cause of your problems, I don't know, but it's quite probable.
The listing below can provide ideas on where the file should/could be found. I can't explain the segfault without more details, though. I do not see how it could be related to malloc() in any way.
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/malloc.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/malloc/malloc.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/malloc/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/malloc/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/usr/include/malloc/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/malloc/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include/malloc/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/malloc/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/malloc/malloc.h
$
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
This question already has answers here:
How to know (in GCC) when given macro/preprocessor symbol gets declared?
(6 answers)
Closed 7 years ago.
How can I find the include file, from which a certain preprocessor definition was found by GCC?
In a successfully compiling C file, I have a strange macro which I do not understand. For a start, I want to see the file where it comes from. The include hierarchy is very deep; is there an easy way to find the source of the macro?
A wider question has been asked, but the answers tell how to find the definition itself, not its source file.
redefine it before including anything else, the compiler will complain about a redefinition when it encounters it in your header hierachy:
#define MY_PROBLEMATIC_MACRO
#include <the_header.h>
/* code */
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What is the difference between #include <filename> and #include “filename”?
I am creating a shared C library. Is there any difference when including
#include <mylib/someheader.h>
versus
#include "mylib/someheader.h"
from *.c or *.h files of this library?
The first version is used for system headers, the second for external headers.
Most compilers will find the right header, whatever the notation, though.
Depends on compiler. Some of them can differ between "system" include path and "just" include path. <> denotes system include path
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Where to find stdio.h functions implementations ?
Hi, I am trying to find the function definitions of the functions defined in stdio.h header file, I want to learn how functions like printf() is achieved, but I can't find any preprocessor directives link in stdio.h to the implementation file elsewhere. How can a C Compiler know where to find the implementations when there are no direct references to the function definition file? (I learned that .h file may accompany with a same name .c implementation file from an objective-c book.) Could you help me? Thanks! I am using GCC on Mac OS X.
FreeBSD's libc is pretty well laid out in its src repository.
http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libc/
e.g. for printf(3):
http://svnweb.freebsd.org/base/head/lib/libc/stdio/printf.c?view=markup
http://svnweb.freebsd.org/base/head/lib/libc/stdio/vfprintf.c?view=markup
Try downloading source code for GLIBC library project. That's where definitions for standard functions are when using GCC compiler (and derivates).