2017-04-06 18 views
0

인텔 에디슨에서 장치 (iOS 및 Android)로 사운드를 스트리밍하기 위해 C 프로그램을 컴파일하는 데 몇 가지 문제가 있습니다.여러 헤더에서 'struct timeval'을 재정의했습니다.

C 프로그램을 만들었습니다 :내 프로그램에서 alsa/asoundlib.h와 pthread.h를 사용합니다. ALSA가 이것을 허용하지 않기 때문에 sys/time.h를 포함하지 않습니다.

gcc -std=c99 -Wall -O0 -ggdb -o sender sender.c spsc_circular_queue.c -lopus -lasound -lpthread 


In file included from /usr/include/alsa/asoundlib.h:49:0, 
       from sender.c:16: 
/usr/include/alsa/global.h:145:8: error: redefinition of 'struct timespec' 
struct timespec { 
     ^
In file included from /usr/include/alsa/global.h:34:0, 
       from /usr/include/alsa/asoundlib.h:49, 
       from sender.c:16: 
/usr/include/time.h:120:8: note: originally defined here 
struct timespec 
     ^
In file included from /usr/include/time.h:41:0, 
       from /usr/include/sched.h:34, 
       from sender.c:18: 
/usr/include/bits/time.h:30:8: error: redefinition of 'struct timeval' 
struct timeval 
     ^
In file included from /usr/include/alsa/asoundlib.h:49:0, 
       from sender.c:16: 
/usr/include/alsa/global.h:140:8: note: originally defined here 
struct timeval { 
     ^
Makefile:16: recipe for target 'sender' failed 
make: *** [sender] Error 1 

어떻게 이러한 redifinitions을 중지 관리 할 수 ​​있습니다 : 나는 경우

내 에디슨에 내가 i'ts 잘 컴파일 내 컴퓨터에서 컴파일 할 때, 내 프로그램에 timeval 형을 많이 사용하지만?! 도움을 주셔서 감사합니다.

추가 정보 :

는 I은 다음과 같습니다 : 나는 sched.h에 제거 아무것도

+0

'/ usr/include/sched.h'는'/ usr/include/time.h'를 포함하는 18 번째 줄의 sender.c에 포함 시켰습니다. – mch

+0

이것을 제거하지 않으려면 다음을 포함하십시오 : – maathor

+0

'#include '을 수행 한'#include '을 수행했습니다. 그것이 문제이다. '#include '을 제거하면 오류 메시지가 변경되어 다음 문제로 연결됩니다. – mch

답변

1

ALSA는 유형 struct timespecstruct timeval에 따라 발생하지

#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" 

.

그러나
/* for timeval and timespec */ 
#include <time.h> 

, GLIBC 그 헤더는 말했다에 적합한 기능 테스트 매크로가 정의 된 경우에만 그 구조를 정의하는 의견이 될 것 같다 : 그 global.h 헤더에 따라서 적절하게이 수행 :

#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 

그것은 어떤에서 상황 GLIBC가 실제로 원하는 구조를 선언 않는 결정하기 어렵다. 조건부로 그렇게하는 것은 사실이지만 적어도 GLIBC v2.17의 조건은 ALSA가 가정하는 것보다 더 일반적인 것으로 보입니다. 따라서 ALSA가 GLIBC와 동기화되지 않은 것처럼 보입니다. 실제로 처음부터 완벽하게 동기화 된 경우 일부 조건에서 발생하는 중복 된 선언 문제가 발생합니다.

컴파일 할 때 가장 좋은 방법은 아마도 the _POSIX_C_SOURCE macro을 정의하는 것입니다. GLIBC가 지원하는 값은 링크 된 매뉴얼 페이지에 설명되어 있습니다. 0을 제외한 모든 값은 문제를 해결해야하지만 효과는 더 넓어 지므로 다른 값으로 실험해야 할 수도 있습니다.

gcc -D_POSIX_C_SOURCE=200809L -std=c99 -Wall -O0 -ggdb -o sender sender.c spsc_circular_queue.c -lopus -lasound -lpthread 

ALSA는 다음 시스템의 정의 대신 자신의 중복 것들을 실행에 의존한다 : 시작하려면, 나는 GLIBC에 의해 지원되는 값 중 가장 포괄적 인 값 200809L을 제안한다.

+0

와우! 고맙습니다 ! 더 잘 이해하기 위해 노력할 것입니다. 프로그램이 컴파일됩니다! – maathor

+0

불행히도 적어도 나를 위해 작동하지 않습니다 - 당신은'it_interval'과'it_value'에 대해'time.h'에서 불완전한 타입을 가진 약간의 에러를 얻습니다. – Timmmm