第一种(第一次安装)
1、下载autoreconf对应的三个编译软件
你需要安装很多东西,请按照以下顺序安装:
安装的版本包也不能错:
curl -O http://mirrors.kernel.org/gnu/m4/m4-1.4.13.tar.gz
tar -xzvf m4-1.4.13.tar.gz
cd m4-1.4.13
./configure --prefix=/usr/local
make
sudo make install
cd ..
curl -O http://mirrors.kernel.org/gnu/autoconf/autoconf-2.65.tar.gz
tar -xzvf autoconf-2.65.tar.gz
cd autoconf-2.65
./configure --prefix=/usr/local # ironic, isn't it?
make
sudo make install
cd ..
# here you might want to restart your terminal session, to ensure the new autoconf is picked up and used in the rest of the script
curl -O http://mirrors.kernel.org/gnu/automake/automake-1.11.tar.gz
tar xzvf automake-1.11.tar.gz
cd automake-1.11
./configure --prefix=/usr/local
make
sudo make install
cd ..
curl -O http://mirrors.kernel.org/gnu/libtool/libtool-2.2.6b.tar.gz
tar xzvf libtool-2.2.6b.tar.gz
cd libtool-2.2.6b
./configure --prefix=/usr/local
make
sudo make install
2、下载protobuf版本
3、编译protobuf
./configure --prefix=/usr/local/
make
make install
lianhengdeMac-mini:protobuf-2.5.0 lianheng$ src/protoc --proto_path=src --cpp_out=test src/AuthMsg.pro
4、删除 protobuf中所有以*unittest*的文件;
find ./ -name "*unittest*"
cd /
rm -rf *unittest*
pwd
cd src/google/
5、删除testing目录
find ./ -name "testing"
eg: protobuf-2.5.0/src/google/protobuf/testing (cd protobuf-2.5.0/src/google/protobuf/)
rm -rf testing
6、注释掉stringprintf.cc中的 #include <google/protobuf/testing/googletest.h>(可以直接注释掉含有stringprint的类)
7、将google/protobuf目录拷贝到自己的工程目录下;
8、拷贝config.h到你的工程目录中
9、拷贝确实的*.h到/usr/local/include/google/protobuf/响应目录中
eg. cp protobuf/io/*.h /usr/local/include/google/protobuf/io/
cp protobuf/stubs/*.h /usr/local/include/google/protobuf/stubs/
删除 complimer;
10、删除stringprint.cc和.h
11.在工程的buildseting中的
search paths->header search paths 添加 /usr/local/include
search paths->library search paths 添加 /usr/local/lib
12、添加libz.dylib到 Build Phases > Link Binary With Libraries
13、根据pro文件生成自己的.cc .h;
14、编译工程,完成;
15、做完上面以后你的程序就可以畅通的运行到真机调试, 但是在打包时会出现问题
解决办法:
1)前往/usr/local/include 在google--> protobuf —> stubs —> 找到platform_macros.h 文件
在他的
注释掉 ——>#error Host architecture was not detected as supported by protobuf
在他下面加上
#define GOOGLE_PROTOBUF_ARCH_X64 1
#define GOOGLE_PROTOBUF_ARCH_64_BIT 1
详细参考 http://stackoverflow.com/questions/10277576/google-protocol-buffers-on-ios
1、autoreconf:command not found
在你的电脑中已经配置过protobuf之后(就是在你的系统的/usr/local/include和/usr/local/lib已经有了所需要的文件之后)直接用我所给的protobuf(拖进你的工程里面去还有config.h)
1、在工程的buildseting 中的
search paths->header search paths 添加 /usr/local/include
search paths->library search paths 添加 /usr/local/lib
2、添加libz.dylib到 Build Phases > Link Binary With Libraries
注释:如果有报错是关于test和unittest的找到类名中含有这两个字样的直接删掉(我给的里面我已经删过了)