使用osx构建失败

时间:2017-08-19 16:15:00

标签: c macos

我的代码使用Linux和OpenBSD构建。现在我希望它用osx构建,但是我从travis-ci得到了这个我不完全理解的错误。

^

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但我不知道如何处理它。

我该怎么办?

1 个答案:

答案 0 :(得分: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版本的支持。也许这就是问题?