集成网易云信Mac版 NIMSDK 报"_clock_gettime", referenced from:

环境:

Macbook pro 系统版本10.11.5 Xcode7.2.1

集成过程如下:

1.创建空的Mac应用,编译运行,没问题
2.到官网下载Mac版 NIMSDK(版本4.1.0) 并导入工程
3.添加其他 macOS NIM SDK 依赖库
CoreServices.framework
AVFoundation.framework
libc++.tbd
libsqlite3.0.tbd
libz.tbd
4.在 Build Settings -> Other Linker Flags 里,添加选项 -ObjC

编译~~~

报错如下:

Undefined symbols for architecture x86_64:
"_clock_gettime", referenced from:
_detect_monotonic in libevent.a(event.o)
_gettime in libevent.a(event.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

解决方法:

在工程的main.m 的main方法前加

#if defined(__MACH__) && !defined(CLOCK_REALTIME)
#include 
#define CLOCK_REALTIME 0
// clock_gettime is not implemented on older versions of OS X (< 10.12).
// If implemented, CLOCK_REALTIME will have already been defined.
int clock_gettime(int clk_id, struct timespec* t) {
    struct timeval now;
    int rv = gettimeofday(&now, NULL);
    if (rv) return rv;
    t->tv_sec  = now.tv_sec;
    t->tv_nsec = now.tv_usec * 1000;
    return 0;
}
#endif

你可能感兴趣的:(集成网易云信Mac版 NIMSDK 报"_clock_gettime", referenced from:)