日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

centos7.2 安装poco

發布時間:2023/12/9 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 centos7.2 安装poco 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

下載地址:?https://pocoproject.org/releases/poco-1.7.8/poco-1.7.8p3-all.tar.gz

安裝:

#!/bin/sh# 安裝依賴庫 # yum install openssl-devel mysql++-devel# 默認方式不支持mysql #./configure --everything --omit=Data/ODBC,Data/SQLitemake -s#make -s install


具體安裝時要使用什么參數,可執行 "./configure --help" 查看!


安裝后,可以編寫程序進行測試了。

如果程序運行時,發現找不到運行的動態庫,記得將/usr/local/lib 添加到庫的搜索 目錄下,并執行ldconfig

---------------------------------------------------------------------------------------------------------------------------------

以下為測試程序:main.cpp

#include <iostream> #include "Poco/String.h" #include "Poco/Format.h" #include "Poco/Exception.h" #include "Poco/Data/StatementImpl.h" #include "Poco/Data/MySQL/Connector.h" #include "Poco/Data/MySQL/MySQLException.h" #include "Poco/Data/Session.h" #include "Poco/Data/SessionPool.h" #include "Poco/Data/SessionFactory.h" #include "Poco/Data/LOB.h" #include "Poco/Data/MySQL/MySQLStatementImpl.h" #include "Poco/DateTime.h" #include "Poco/Data/RecordSet.h" #include "Poco/Data/Column.h"using namespace Poco::Data::Keywords; using namespace Poco::Data;using Poco::Data::Session; using Poco::Data::MySQL::ConnectionException; using Poco::Data::MySQL::StatementException; using Poco::NotFoundException; using Poco::Data::Statement; using Poco::DateTime; using Poco::Data::RecordSet;//給出訪問數據庫的信息 std::string _dbConnString = "host=192.168.2.2;port=3306;" "user=root;password=123456;" "db=test;" "compress=true;auto-reconnect=true";int main(int argc, char** argv) {MySQL::Connector::registerConnector();//與數據庫建立一個連接池Poco::Data::SessionPool pool(MySQL::Connector::KEY, _dbConnString,1,32,10);//從數據庫存連接池中獲得一個數據庫連接Poco::Data::Session ses(pool.get());//如果與數據庫建立會話成功,輸出連接信息if(ses.isConnected())std::cout << "*** Connected to " << '(' << _dbConnString << ')' << std::endl;//如果有為名ddjj的表,先刪除,方便下面調試ses << "DROP TABLE IF EXISTS ddjj", now;//把查詢結果存儲到容器中std::vector<std::string> names;ses << "show databases", into(names), now;//輸出查詢結果,此處列出所有數據庫名稱for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); ++it){std::cout << *it << std::endl;}// 建立一個表,名為ddjj,字段名:name,birthses << "create table ddjj(name VARCHAR(20),birth VARCHAR(20));", now;//實現數據紀錄的插入DateTime bd(1980, 4, 1);DateTime ld(1982, 5, 9);ses << "INSERT INTO ddjj VALUES('Bart Simpson', ?)", use(bd), now;ses << "INSERT INTO ddjj VALUES('Lisa Simpson', ?)", use(ld), now;//實現查詢的方法,并輸出查詢結果std::vector<std::string> names1;ses << "select * from ddjj where name like 'Bart Simpson' ",into(names1),now;for (std::vector<std::string>::const_iterator it = names1.begin(); it != names1.end(); ++it){std::cout << "*** tables: " << *it << std::endl;}Statement select(ses);select << "SELECT * FROM ddjj";select.execute();//創建紀錄集RecordSet rs(select);std::size_t cols = rs.columnCount();//輸出列名for (std::size_t col = 0; col < cols; ++col){std::cout << rs.columnName(col) << std::endl;}//輸出所有查詢到的結果bool more = rs.moveFirst();while (more){ #if 0 // 通過下標取數據for (std::size_t col = 0; col < cols; ++col){std::cout << rs[col].convert<std::string>() << "\t";} #else // 通過列名取數據printf("name=%s, birth=%s", rs["name"].convert<std::string>().c_str(), rs["birth"].convert<std::string>().c_str()); #endifstd::cout << std::endl;more = rs.moveNext();}ses.close();MySQL::Connector::unregisterConnector();return 0; }
Makefile

CC = gcc CXX = g++ RM = rm -fINCLUDE=-I/usr/include/mysql LDFLAGS = -lPocoData -lPocoFoundation -lPocoDataMySQL CFLAGS = -g -std=c++11 ALL = aa: main.o$(CXX) -o $@ $^ $(CFLAGS) $(LDFLAGS)%.o: %.cpp$(CXX) -c $< $(CFLAGS) -o $@ $(INCLUDE)clean:$(RM) $(ALL) *.o

編譯過程:

[zcm@localhost poco1]$ make g++ -c main.cpp -g -std=c++11 -o main.o -I/usr/include/mysql g++ -o a main.o -g -std=c++11 -lPocoData -lPocoFoundation -lPocoDataMySQL

總結

以上是生活随笔為你收集整理的centos7.2 安装poco的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。