c - redefinition of 'struct timeval' in several headers -
i have several issues compile c program stream sound intel edison devices (ios , android).
i made c program : use alsa/asoundlib.h , pthread.h in program don't include sys/time.h because alsa not allow this.
i use lot of timeval in program, when compile on computer i'ts compile fine, on edison when :
gcc -std=c99 -wall -o0 -ggdb -o sender sender.c spsc_circular_queue.c -lopus -lasound -lpthread in file included /usr/include/alsa/asoundlib.h:49:0, sender.c:16: /usr/include/alsa/global.h:145:8: error: redefinition of 'struct timespec' struct timespec { ^ in file included /usr/include/alsa/global.h:34:0, /usr/include/alsa/asoundlib.h:49, sender.c:16: /usr/include/time.h:120:8: note: defined here struct timespec ^ in file included /usr/include/time.h:41:0, /usr/include/sched.h:34, sender.c:18: /usr/include/bits/time.h:30:8: error: redefinition of 'struct timeval' struct timeval ^ in file included /usr/include/alsa/asoundlib.h:49:0, sender.c:16: /usr/include/alsa/global.h:140:8: note: defined here struct timeval { ^ makefile:16: recipe target 'sender' failed make: *** [sender] error 1
how can manage stop these redifinitions ?! thank !
extra info:
i include :
#include <assert.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <signal.h> #include <errno.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #include <unistd.h> #include <alloca.h> #include <limits.h> #include <inttypes.h> #include <alsa/asoundlib.h> #include "../opus/include/opus.h" #include <pthread.h> #include "spsc_circular_queue.h"
i remove sched.h, nothing happen
alsa depends on types struct timespec
, struct timeval
. global.h
header therefore appropriately this:
/* timeval , timespec */ #include <time.h>
however, seems of opinion glibc defines structures when appropriate feature-test macro has been defined, header says:
#ifdef __glibc__ #if !defined(_posix_c_source) && !defined(_posix_source) struct timeval { time_t tv_sec; /* seconds */ long tv_usec; /* microseconds */ }; struct timespec { time_t tv_sec; /* seconds */ long tv_nsec; /* nanoseconds */ }; #endif #endif
it's hard determine under circumstances glibc declare wanted structures. indeed conditionally, appears conditions, @ least in glibc v2.17, more general alsa assumes. alsa seems have fallen out of sync glibc, if indeed ever synchronized in first place, , under conditions produces duplicate declaration problem encountered.
your best bet define the _posix_c_source
macro when compile. values supported glibc documented on linked manual page. value, except possibly 0, ought solve problem you, effects broader, may need experiment different values. start, suggest value 200809l
, inclusive among values supported glibc:
gcc -d_posix_c_source=200809l -std=c99 -wall -o0 -ggdb -o sender sender.c spsc_circular_queue.c -lopus -lasound -lpthread
alsa should rely on system's definitions instead of issuing own, duplicate ones.
Comments
Post a Comment