Mac 上面编译POCO C++库

来源:互联网 发布:林非比淘宝模特 编辑:程序博客网 时间:2024/05/21 12:44

POCO C++是一个开源的C++库,这个库的功能还挺多,包括socket,http,加密,xml解析等。我们游戏里面用到这个库,但没有在mac虚拟机中编译过所以需要在mac下重新编译一下这个库。


1.我首先到http://pocoproject.org/下载源码

因为我是需要在Mac上编译,所以我下Linux版


2.把解压后的文件夹拖到桌面,打开终端,输入以后命令,跳转到Poco文件夹


3.参数解释:  --omit排除(不编译的), --prefix安装路径

> sudo ./configure --omit=Data/ODBC,Data/SQLite --prefix=/usr  --static --shared

> sudo make -s install


PS:

如果没有  --static --shared 默认为 shared 不编译静态库

如果在x64的系统下使用到静态库 .记得一定要加-fPIC,动态库不用.

>./configure --omit=Data/ODBC,Data/SQLite --prefix=/usr --cflags=-fPIC --static

>make -s install

否则会出现这类的错误:

/usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../
....
can not be used when making a shared object; recompile with -fPIC

4.编译完后:


我想要的就是这几个.a文件,这个和警告中相吻合。

如果你需要Iphone版本的编译,那么:

需要下载libpoco-all,解压后通过命令行进入poco根目录。输入以下命令编译静态库

sudo ./configure --config=iPhone --no-tests --no-samples --omit=Data/ODBC,Data/MySQL
sudo make IPHONE_SDK_VERSION_MIN=3.0 POCO_TARGET_OSARCH=armv6 -s -j4 
sudo make IPHONE_SDK_VERSION_MIN=3.2 POCO_TARGET_OSARCH=armv7 -s -j4 

sudo ./configure --config=iPhoneSimulator --no-tests --no-samples --omit=Data/ODBC,Data/MySQL
sudo make -s -j4

特别注意

1)如果编译不过,一般是找不到IphoneSDK路径,可打开Build/Config/Iphone,修改路径
TOOL_PREFIX  ?= /Applications/Xcode.app/Contents/Developer/Platforms/$(IPHONE_SDK).platform/Developer/usr/bin

  2)如果嵌入工程编译出现i386错误,就需要编译i386平台静态库(针对模拟器)

sudo ./configure --config=iPhoneSimulator --no-tests --no-samples --omit=Data/ODBC,Data/MySQL
sudo POCO_TARGET_OSARCH=i386 make -s -j4


原创粉丝点击