标签:lib mini turn com sudo txt har link strong
https://www.yiibai.com/postgresql/
PostgreSQL教程
https://www.yiibai.com/postgresql/postgresql_c_cpp.html
C/C++连接PostgreSQL数据库
https://www.jianshu.com/p/8f5b6b3d7b38
1: libpqxx 安装
// 下载库文件 -> 生成共享库(这一步对后面CMakeList 有用)-> 安装
wget http://pqxx.org/download/software/libpqxx/libpqxx-4.0.1.tar.gz
tar -xzvf libpqxx-4.0.1.tar.gz
cd libpqxx-4.0.1
./configure --prefix=/usr/local --enable-shared (这一步很重要,生成共享库 )
make clean
make
sudo make install
2: CMakeLists.txt 调用share 库
cmake_minimum_required(VERSION 3.0.0)
project(test_pgsql VERSION 0.1.0)
add_executable(test_pgsql main.cpp)
target_link_libraries(test_pgsql libpqxx.so )
3: 测试代码
#include <iostream>
#include <pqxx/pqxx>
using namespace std;
using namespace pqxx;
int main(int argc, char* argv[])
{
try
{
connection db(
"dbname=vslam_map user=postgres password=postgres hostaddr=127.0.0.1 port=5432");
if (db.is_open())
{
cout << "Opened database successfully: " << db.dbname() << endl;
}
else
{
cout << "Can‘t open database" << endl;
return 1;
}
db.disconnect();
}
catch (const std::exception& e)
{
cerr << e.what() << std::endl;
return 1;
}
}
标签:lib mini turn com sudo txt har link strong
原文地址:https://www.cnblogs.com/Billy-rao/p/14608633.html