连接池, 多线程, 用时: 8174353854纳秒, 8174毫秒
连接池, 单线程, 用时: 18725899085纳秒, 18725毫秒
非连接池, 多线程, 用时: 52480313253纳秒, 52480毫秒
非连接池, 单线程, 用时: 144784425519纳秒, 144784毫秒
- 刚开始只通过
yum install mysql-community-server
安装了MySQL的服务器和客户端 - 要想使用MySQL C API,在CentOS中需要通过
yum install mysql-devel
安装。ubuntu中需要安装libmysqlclient-dev
- Liunx系统中:存在于/usr/lib64和/usr/local/lib64下的库文件会被自动搜寻,无需手动指定这两个目录,使用时直接指定动态库名即可。
- mysql-devel安装完后,在/usr/lib64/mysql下有其库文件,在/usr/include/mysql下有其头文件。
- jsoncpp安装完之后,在/usr/local/lib64/下有其库文件,在/usr/local/include/json下有其头文件
- 对于g++命令:
g++ main.cpp src/connectionPool.cpp src/databaseConnect.cpp -Iinclude -lmysqlclient -ljsoncpp -lpthread -o main -Wall -std=c++11
- 编译时找不到到动态库-lmysqlclient:需要将动态库文件链接到/usr/lib64/或/usr/local/lib64/目录下,不能在其子目录下。因此要使用
ln -s /usr/lib64/mysql/libmysqlclient.so.21.2.34 /usr/lib64/libmysqlclient.so
- 通过CMake在编译时不需要这样做。
- 运行时找不到动态库error while loading shared libraries: libjsoncpp.so.25: cannot open shared object file: No such file or directory:需要将jsoncpp动态库所在路径/usr/local/lib64/添加进/etc/ld.so.conf.d/jsoncpp.conf文件中,并使用
ldconfig
使其生效。 - 通过CMake在编译时也需要这样做。
- 编译时找不到到动态库-lmysqlclient:需要将动态库文件链接到/usr/lib64/或/usr/local/lib64/目录下,不能在其子目录下。因此要使用
- 报错原因:在 GCC 11: Dwarf Error 和 GCC 11 Release Series Changes, New Features, and Fixes 中可以看到GCC 11编译器在调试时默认-gdwarf-5为调试选项,而汇编器as需要2.35.2以上才支持-gdwarf-5选项。
- 解决办法:
- 法1:在设置Debug调试选项时,指定-gdwarf-2选项。
- 法2:通过源码编译安装最新版的Binutils工具集,以此来升级as汇编器。"as: unrecognized option '--gdwarf-5'"