Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22000

compilation error on clock_gettime and CLOCK_MONOTONIC

$
0
0

I'm using clock_gettime in a program. I've tried including as well as but neither works. I have also added -lrt to my compiler arguments but still I get the same errors.

This is on

CentOS Linux release 7.2.1511 (Core)
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)
GNU ld version 2.23.52.0.1-55.el7 20130226
ldd (GNU libc) 2.17

Compiler output:

gcc -o main packet.c connect.c transport.c accept.c main.c close.c util.c receive.c send.c congestion.c -Wall -g -std=c99 -lrt
util.c: In function ‘millis’:
util.c:42:21: error: storage size of ‘t’ isn’t known
     struct timespec t;
                     ^
util.c:43:5: warning: implicit declaration of function ‘clock_gettime’ [-Wimplicit-function-declaration]
     clock_gettime(CLOCK_MONOTONIC_RAW, &t);
     ^
util.c:43:19: error: ‘CLOCK_MONOTONIC_RAW’ undeclared (first use in this function)
     clock_gettime(CLOCK_MONOTONIC_RAW, &t);
               ^

Makefile

CFLAGS = -Wall -g -std=c99
LIBS = -lrt

# Should be equivalent to your list of C files, if you don't build selectively
SRC=$(wildcard *.c)

main: $(SRC)
    gcc -o $@ $^ $(CFLAGS) $(LIBS)

Top of util.h

#ifndef UTILS_438_H_
#define UTILS_438_H_

#include "const.h"
#include "data.h"
#include "transport.h"

#include <time.h>

Top of util.c

#include "util.h"

#include <time.h>
#include <stdio.h>
#include <string.h>

Please let me know if I can supply more information to help answer this


Viewing all articles
Browse latest Browse all 22000

Trending Articles