C Error: undefined symbol: ftime Why?

Hello everyone!

Trying to build this (https://github.com/ArboreusSystems/...eus_library/c_src/a_time/a_time_now_handler.c) and having this error. On MacOS everything is building perfectly. What is the difference?

This is error:
Code:
ld: error: undefined symbol: ftime
>>> referenced by a_time_now_handler.c
>>>               /tmp/a_time_now_handler-d41c5b.o:(atnhMilliseconds)
>>> did you mean: ctime
>>> defined in: /lib/libc.so.7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
 
you only have to append
-lcompat
to the Makefile.
.

Maybe:
LIBS += -lcompat


Or ask the developers to stop using this deprecated function.
 
Added -lcompat

But there are another one trouble ...

ld: error: relocation R_X86_64_PC32 cannot be used against symbol '__stack_chk_guard'; recompile with -fPIC
>>> defined in /lib/libc.so.7
>>> referenced by ftime.c:40 (/usr/src/lib/libcompat/4.1/ftime.c:40)
>>> ftime.o:(ftime) in archive /usr/lib/libcompat.a

ld: error: relocation R_X86_64_PC32 cannot be used against symbol '__stack_chk_guard'; recompile with -fPIC
>>> defined in /lib/libc.so.7
>>> referenced by ftime.c:0 (/usr/src/lib/libcompat/4.1/ftime.c:0)
>>> ftime.o:(ftime) in archive /usr/lib/libcompat.a
clang: error: linker command failed with exit code 1 (use -v to see invocation)
gmake: *** [Makefile:57: build_a_time_now_nif] Error 1
gmake: Leaving directory '/home/alexandr/test_build/arboreus_library/c_src'
===> Hook for compile failed!
 
Then add -fPIC? 🤷‍♂️

BTW, looking at this code:

C:
// Return time in microseconds
int atnhMicroseconds(long long int *Pointer){
   
    struct timeval Time;
    if (!gettimeofday(&Time, NULL)) {
        *Pointer =
            ((long long int)Time.tv_sec)*1000000ll +
            (long long int)Time.tv_usec;
    } else {
        *Pointer = -1;
    }
   
    SUCCESS;
}


// Return time in milliseconds
int atnhMilliseconds(long long int *Pointer){
   
    struct timeb Time;
    if (!ftime(&Time)) {
        *Pointer =
            ((long long int)Time.time)*1000ll +
            (long long int)Time.millitm;
    } else {
        *Pointer = -1;
    }
   
    SUCCESS;
}

So, it does use gettimeofday(2) for microsecond precision. Why in the world does it then use the obsolete (mind you, according to POSIX!) ftime at all?

It could be as simple as
C:
// Return time in milliseconds
int atnhMilliseconds(long long int *Pointer){
   
    struct timeval Time;
    if (!gettimeofday(&Time, NULL)) {
        *Pointer =
            ((long long int)Time.tv_sec)*1000ll +
            ((long long int)Time.tv_usec)/1000ll;
    } else {
        *Pointer = -1;
    }
   
    SUCCESS;
}
Yes, there's integer division ... :rolleyes:
 
Back
Top