mac 安装 muduo

最近在看陈硕先生的muduo开源库,很实用的库,书里也有很多可学习的知识。推荐一下。陈硕的博客【http://blog.csdn.net/solstice】
muduo的安装依赖cmake,作者的主系统环境是linux,但是也提供了几个patch【http://en.wikipedia.org/wiki/Patch_(Unix)】的文件包含macos。
在没有patch diff的情况下mac编译muduo会有很多问题,不一一列举。
现在的muduo版本已经更新到了0.9.7【https://code.google.com/p/muduo/downloads/list】。但是尝试0.9.7 patch后的编译有很多问题:
mutex.h:
#ifdef CHECK_PTHREAD_RETURN_VALUE
#ifdef NDEBUG
__BEGIN_DECLS
extern void __assert_perror_fail (int errnum,
                                  const char *file,
                                  unsigned int line,
                                  const char *function)
    __THROW __attribute__ ((__noreturn__));
__END_DECLS
#endif
#define MCHECK(ret) ({ __typeof__ (ret) errnum = (ret);         \
                       if (__builtin_expect(errnum != 0, 0))    \
                         __assert_perror_fail (errnum, __FILE__, __LINE__, __func__);})
#else  // CHECK_PTHREAD_RETURN_VALUE
#define MCHECK(ret) ({ __typeof__ (ret) errnum = (ret);         \
                       assert(errnum == 0); (void) errnum;})
#endif // CHECK_PTHREAD_RETURN_VALUE

makefile :

 -DCHECK_PTHREAD_RETURN_VALUE

#set(CMAKE_CXX_COMPILER "g++")
set(CMAKE_CXX_COMPILER "clang++")
set(CMAKE_CXX_FLAGS_DEBUG "-O0")
#set(CMAKE_CXX_FLAGS_RELEASE "-O2 -finline-limit=1000 -DNDEBUG”)
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")

编译会报错 : /Users/Kinly/Downloads/muduo/muduo-master/muduo/base/Condition.h:47:5: error: use of undeclared identifier '__assert_perror_fail'
    MCHECK(pthread_cond_broadcast(&pcond_));
    ^
/Users/Kinly/Downloads/muduo/muduo-master/muduo/base/Mutex.h:28:26: note: expanded from macro 'MCHECK'
                         __assert_perror_fail (errnum, __FILE__, __LINE__, __func__);})
本身是没有问题的,但是要修改编译条件。总感觉不妥。
后来邮件给陈硕先生咨询,换到0.9.4的版本,下面列出编译的问题及修改方案:
使用0.9.4版本,过程中出现过:


1、


[ 63%] Building CXX object examples/roundtrip/CMakeFiles/roundtrip_udp.dir/roundtrip_udp.cc.o


/Users/Kinly/Downloads/muduo-094/examples/roundtrip/roundtrip_udp.cc:20:47: error: use of undeclared identifier 'SOCK_NONBLOCK'


  int sockfd = ::socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC, IPPROTO_UDP);


                                              ^


/Users/Kinly/Downloads/muduo-094/examples/roundtrip/roundtrip_udp.cc:20:63: error: use of undeclared identifier 'SOCK_CLOEXEC'


  int sockfd = ::socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC, IPPROTO_UDP);






修改为:int sockfd = ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); 解决


2、


已经安装了protobuf,不过还是报了找不到lib文件的error


ld: library not found for -lprotobuf


clang: error: linker command failed with exit code 1 (use -v to see invocation)


make[2]: *** [bin/protobuf_client] Error 1


make[1]: *** [examples/protobuf/codec/CMakeFiles/protobuf_client.dir/all] Error 2


暂且注释掉了CMakeList里的 protobuf 相关内容

你可能感兴趣的:(C/C++)