2017-08-19 4 views
-1

私のコードはLinuxとOpenBSDでビルドされています。今私はそれをosxで構築したいが、私は完全に理解していないtravis-ciからこのエラーを得る。osxでビルドエラー

^ 

In file included from edit.c:1: 

./sh.h:436:8: error: expected ')' 

/usr/include/secure/_string.h:105:44: note: expanded from macro 'strlcpy' 

    __builtin___strlcpy_chk (dest, src, len, __darwin_obsz (dest)) 

             ^

/usr/include/secure/_common.h:39:62: note: expanded from macro '__darwin_obsz' 

#define __darwin_obsz(object) __builtin_object_size (object, _USE_FORTIFY_LEVEL > 1 ? 1 : 0) 

                  ^

/usr/include/secure/_common.h:30:32: note: expanded from macro '_USE_FORTIFY_LEVEL' 

# define _USE_FORTIFY_LEVEL 2 

          ^

./sh.h:436:8: note: to match this '(' 

/usr/include/secure/_string.h:105:44: note: expanded from macro 'strlcpy' 

    __builtin___strlcpy_chk (dest, src, len, __darwin_obsz (dest)) 

             ^

/usr/include/secure/_common.h:39:53: note: expanded from macro '__darwin_obsz' 

#define __darwin_obsz(object) __builtin_object_size (object, _USE_FORTIFY_LEVEL > 1 ? 1 : 0) 

                ^

In file included from edit.c:1: 

./sh.h:436:8: warning: type specifier missing, defaults to 'int' [-Wimplicit-int] 

size_t strlcpy(char *, const char *, size_t); 

    ^

/usr/include/secure/_string.h:105:44: note: expanded from macro 'strlcpy' 

    __builtin___strlcpy_chk (dest, src, len, __darwin_obsz (dest)) 

             ^

/usr/include/secure/_common.h:39:31: note: expanded from macro '__darwin_obsz' 

#define __darwin_obsz(object) __builtin_object_size (object, _USE_FORTIFY_LEVEL > 1 ? 1 : 0) 

          ^

In file included from edit.c:1: 

./sh.h:436:8: error: conflicting types for '__builtin___strlcpy_chk' 

/usr/include/secure/_string.h:105:3: note: expanded from macro 'strlcpy' 

    __builtin___strlcpy_chk (dest, src, len, __darwin_obsz (dest)) 

^

./sh.h:436:8: note: '__builtin___strlcpy_chk' is a builtin with type 'unsigned long (char *, const char *, unsigned long, unsigned long)' 

/usr/include/secure/_string.h:105:3: note: expanded from macro 'strlcpy' 

    __builtin___strlcpy_chk (dest, src, len, __darwin_obsz (dest)) 

私のマクロは

#ifndef strlcpy 
/* Linux has no concept of strlcpy(). */ 
#define strlcpy(x, y, z) snprintf((x), (z), "%s", (y)) 
#endif 

である私は、OSX版を理解し、OpenBSDはstrlcpyを持っているが、私はそれを処理する方法がわかりません。

どうすればいいですか?

+4

関数が宣言されているかどうかテストするのに '#ifndef'を使用することはできません。プラットフォームに条件が必要です。 – molbdnilo

+1

あなたはすでに*条件コンパイル*の概念について知っています(これは '#ifndef/#endif'のものです)。これを使用してプラットフォームを検出します(コンパイラはプラットフォーム固有の特別なマクロを定義します)。 –

+1

あなたのアプリケーションをどのように設定してビルドするかによって、ある種のconfigureスクリプトやそれに類するものがあれば、機能の有無をチェックする機能が必要です。そのようなチェックを追加し、存在する場合は、ソースでチェックする特別なマクロを設定します。 –

答えて

1

このコード:

#include <string.h> 

#ifndef strlcpy 
/* Linux has no concept of strlcpy(). */ 
#define strlcpy(x, y, z) snprintf((x), (z), "%s", (y)) 
#endif 

int main() { 
    char a[1]; 
    char b[1]; 
    strlcpy(a, b, 1); 
    return 0; 
} 

はMacOSでうまくコンパイルします。私はTravis-CIが最近、古いXCodeバージョンのサポートを無効にしていることを知っています。多分これは問題ですか?