您的位置:首页 > 其它

POCO库 安装

2016-06-22 15:46 399 查看
安装环境:

CentOS7、阿里云

1、文档

官网:http://pocoproject.org/documentation/

2、下载到服务器

wget

3、使用yum安装ODBC、mysql

# yum -y install unixODBC
# yum -y install unixODBC-devel
# yum -y install mysql
# yum -y install mysql-devel


注意,最好不要自定义安装位置,报http错误

4、安装POCO

# gunzip poco-X.Y.tar.gz
# tar -xf poco-X.Y.tar
# cd poco-X.Y
# ./configure
# gmake -s install


我自定义了安装位置,但是最好不要这样。

./configure --prefix=/customServes/poco/install --cflags=-fPIC --static --shared


5、在安装过程中会报错

/usr/bin/ld: cannot find -lpthread
/usr/bin/ld: cannot find -ldl
/usr/bin/ld: cannot find -lrt
/usr/bin/ld: cannot find -lstdc++
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find -lc


可以用locate libXXX的命令来查询相应库的安装位置,不过我都安装了也会报错,应该是版本太低了。

locate命令有时会报错,updatedb就可以。

可以用yum search XXX查找yum可以安装的库。

yum search pthread
yum search libc
yum search stdc++


然后使用yum安装

yum install glibc-common
yum install glibc-devel
yum install glibc-static
yum install libstdc++-static


总之是缺少什么库就安装什么库。。

6、写个demo测试

网上随便找的。。注意头文件使用poco最好使用<>

#include <Poco/Net/ServerSocket.h>
#include <Poco/Net/SocketStream.h>
#include <Poco/Net/StreamSocket.h>
#include <iostream>

int main(int argc, char **argv)
{
//绑定端口,并开始监听:
Poco::Net::ServerSocket srv(9000);
//服务主循环:
while (true)    {
//接受连接:
Poco::Net::StreamSocket streamSocket = srv.acceptConnection();
//向 Socket 发送数据:
Poco::Net::SocketStream socketStream(streamSocket);
socketStream << "HTTP/1.0 200 OK\r\n"
<< "Content-Type: text/html\r\n"
<< "\r\n"
<< "<html><head><title>My 1st Web Server</title></head></html>"
<< std::flush;
}
return 0;
}


7、设置系统变量

由于我是自定义安装位置,编译的时候找不到头文件的位置,我是修改了系统的环境变量

在目录 /etc/profile.d 中随便加一个 .sh 文件 ,例如我的 my.sh

CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/customServes/poco/install/include
export CPLUS_INCLUDE_PATH

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/customServes/poco/install/lib
export LD_LIBRARY_PATH


或者:

export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"


8、编译demo

如果安装poco时选择的是系统默认的路径就很简单、如果自定义了安装路径需要在编译的时候指定动态链接库的路径

我的安装路径是:/customServes/poco/install

编译指令就是: g++ temp.cpp -o t -L/customServes/poco/install/lib/ -lPocoNet

9、总结

出了问题最好google,百度没多大用。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  服务器 poco