2017-04-06 6 views
0

インテルEdisonからデバイス(iOSとAndroid)にサウンドをストリームするCプログラムをコンパイルするには、いくつかの問題があります。複数のヘッダで 'struct timeval'を再定義する

Cプログラムを作成しました: 私のプログラムではalsa/asoundlib.hとpthread.hを使用しますが、ALSAではこれを許可しないため、sys/time.hは含まれません。

私は自分のコンピュータ上でそれをコンパイルするとき、私はi'ts罰金コンパイル、私のプログラムでは体timevalの多くを使用しますが、私のエジソンにする場合I:

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を停止するために管理することができますか?! ありがとうございます!

追加情報:

私は、次のとおりです。

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

私は何もALSAがタイプstruct timespecstruct timevalに依存

+0

'/ usr/include/sched.h'は'/usr/include/time.h'を含む18行目のsender.cに含まれています。 – mch

+0

これを削除する変更はありません。 – maathor

+0

あなたは '#include 'を実行しました。これは '#include 'です。それが問題です。 '#include 'を削除すると、エラーメッセージが変わって次の問題につながります。 – mch

答えて

1

を起こりません、sched.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

残念ながら、これは少なくとも私のためには機能しません。次に、 'time.h'に型が不完全な' it_interval'と 'it_value'についていくつかのエラーが発生します。 – Timmmm

関連する問題