MinGW 安装:
pacman -S mingw-w64-x86_64-boost
可选其他库
pacman -S mingw-w64-x86_64-openssl
pacman -S libtool
安装成功测试代码及结果截图如下:
#include<iostream>
#include <boost/shared_ptr.hpp>
#include <iterator>
#include <algorithm>
using namespace std;
int main(int argc, char* argv[]) {
boost::shared_ptr<int> myPtr(new int (1));
std::cout<<*myPtr;
return 0;
}
成功结果
备注:eclipse 调试需要配置 Include 和linker Libraries
具体可以参考如下:
Compile Include 配置E:/2017/msys64/mingw64/include/gtkmm-3.0
E:/2017/msys64/mingw64/lib/gtkmm-3.0/include
E:/2017/msys64/mingw64/include/atkmm-1.6
E:/2017/msys64/mingw64/include/gdkmm-3.0
E:/2017/msys64/mingw64/lib/gdkmm-3.0/include
E:/2017/msys64/mingw64/include/giomm-2.4
E:/2017/msys64/mingw64/lib/giomm-2.4/include
E:/2017/msys64/mingw64/include/pangomm-1.4
E:/2017/msys64/mingw64/lib/pangomm-1.4/include
E:/2017/msys64/mingw64/include/glibmm-2.4
E:/2017/msys64/mingw64/lib/glibmm-2.4/include
E:/2017/msys64/mingw64/include/gtk-3.0
E:/2017/msys64/mingw64/include/cairo
E:/2017/msys64/mingw64/include
E:/2017/msys64/mingw64/include/pango-1.0
E:/2017/msys64/mingw64/include/atk-1.0
E:/2017/msys64/mingw64/include/cairo
E:/2017/msys64/mingw64/include/cairomm-1.0
E:/2017/msys64/mingw64/lib/cairomm-1.0/include
E:/2017/msys64/mingw64/include/cairo
E:/2017/msys64/mingw64/include/pixman-1
E:/2017/msys64/mingw64/include
E:/2017/msys64/mingw64/include/freetype2
E:/2017/msys64/mingw64/include/libpng16
E:/2017/msys64/mingw64/include/harfbuzz
E:/2017/msys64/mingw64/include/glib-2.0
E:/2017/msys64/mingw64/lib/glib-2.0/include
E:/2017/msys64/mingw64/include
E:/2017/msys64/mingw64/include/freetype2
E:/2017/msys64/mingw64/include
E:/2017/msys64/mingw64/include/harfbuzz
E:/2017/msys64/mingw64/include
E:/2017/msys64/mingw64/include/libpng16
E:/2017/msys64/mingw64/include/sigc++-2.0
E:/2017/msys64/mingw64/lib/sigc++-2.0/include
E:/2017/msys64/mingw64/include/gdk-pixbuf-2.0
E:/2017/msys64/mingw64/include/libpng16
E:/2017/msys64/mingw64/include/glib-2.0
E:/2017/msys64/mingw64/lib/glib-2.0/include
E:/2017/msys64/mingw64/include
Compile Miscellaneous 配置
-c -fmessage-length=0 -mms-bitfields -pthread -mms-bitfields -I/mingw64/include/gtkmm-3.0 -I/mingw64/lib/gtkmm-3.0/include -I/mingw64/include/atkmm-1.6 -I/mingw64/include/gdkmm-3.0 -I/mingw64/lib/gdkmm-3.0/include -I/mingw64/include/giomm-2.4 -I/mingw64/lib/giomm-2.4/include -I/mingw64/include/pangomm-1.4 -I/mingw64/lib/pangomm-1.4/include -I/mingw64/include/glibmm-2.4 -I/mingw64/lib/glibmm-2.4/include -I/mingw64/include/gtk-3.0 -I/mingw64/include/cairo -I/mingw64/include -I/mingw64/include/pango-1.0 -I/mingw64/include/atk-1.0 -I/mingw64/include/cairo -I/mingw64/include/cairomm-1.0 -I/mingw64/lib/cairomm-1.0/include -I/mingw64/include/cairo -I/mingw64/include/pixman-1 -I/mingw64/include -I/mingw64/include/freetype2 -I/mingw64/include/libpng16 -I/mingw64/include/harfbuzz -I/mingw64/include/glib-2.0 -I/mingw64/lib/glib-2.0/include -I/mingw64/include -I/mingw64/include/freetype2 -I/mingw64/include -I/mingw64/include/harfbuzz -I/mingw64/include -I/mingw64/include/libpng16 -I/mingw64/include/sigc++-2.0 -I/mingw64/lib/sigc++-2.0/include -I/mingw64/include/gdk-pixbuf-2.0 -I/mingw64/include/libpng16 -I/mingw64/include/glib-2.0 -I/mingw64/lib/glib-2.0/include -I/mingw64/include
Linker Miscellaneous 配置
-L/mingw64/lib -LC:/building/msys64/mingw64/lib -L/mingw64/lib -LC:/building/msys64/mingw64/lib/../lib -L/mingw64/lib -LC:/building/msys64/mingw64/lib -L/mingw64/lib -lgtkmm-3.0 -latkmm-1.6 -lgdkmm-3.0 -lgiomm-2.4 -lpangomm-1.4 -lglibmm-2.4 -lgtk-3 -lgdk-3 -lgdi32 -limm32 -lshell32 -lole32 -Wl,-luuid -lwinmm -ldwmapi -lsetupapi -lcfgmgr32 -lz -lepoxy -lpangocairo-1.0 -lpangoft2-1.0 -lpangowin32-1.0 -lgdi32 -lusp10 -lpango-1.0 -lm -latk-1.0 -lcairo-gobject -lgio-2.0 -lz -lcairomm-1.0 -lcairo -lz -lpixman-1 -lfontconfig -lexpat -lfreetype -liconv -lexpat -lfreetype -lz -lbz2 -lharfbuzz -lgraphite2 -lpng16 -lz -lsigc-2.0 -lgdk_pixbuf-2.0 -lgmodule-2.0 -pthread -lpng16 -lz -lgobject-2.0 -lffi -lglib-2.0 -lintl -pthread -lws2_32 -lole32 -lwinmm -lshlwapi -lpcre -lintl -lpcre
由于项目中使用boost::asio作为gtkmm网络库,因此其中也包含了gtkmm相关的头文件和库文件,如果仅使用boost,可以只包含boost的相应的头文件和库文件即可。
mac 安装
brew install boost
环境配置
主要配置头文件和库文件:
/usr/local/Cellar/boost/1.65.0/include
/usr/local/Cellar/boost/1.65.0/lib
配置头文件
配置库文件
运行成功截图
运行成功CentOS安装
安装相对比较简单,一般执行命令
yum install boost boost-devel boost-doc -y
即可完成安装,具体请见如下【详细安装过程】章节
部分使用需要,指定编译库依赖:
-lpthread -lboost_system -lboost_filesystem
指定编译库依赖
运行成功结果截图
image.png
eclipse 集成使用
CentOS下,安装boost后,eclipse 使用会比较的非常简单,不需要其它太多的配置。这是因为yum命名安装,都是标准的系统安装,但最好指定一下编译器,否则虽然能编译会有警告或者其他莫名错误出现:
指定编译器测试程序源码:
//#include<iostream>
//#include <boost/shared_ptr.hpp>
//#include <iterator>
//#include <algorithm>
//
//using namespace std;
//
//int main(int argc, char* argv[]) {
// boost::shared_ptr<int> myPtr(new int (1));
// std::cout<<*myPtr;
// return 0;
//}
#include <boost/asio.hpp>
#include <boost/array.hpp>
#include <iostream>
#include <string>
boost::asio::io_service io_service;
boost::asio::ip::tcp::resolver resolver(io_service);
boost::asio::ip::tcp::socket sock(io_service);
boost::array<char, 4096> buffer;
void read_handler(const boost::system::error_code &ec, std::size_t bytes_transferred)
{
if (!ec)
{
std::cout << std::string(buffer.data(), bytes_transferred) << std::endl;
sock.async_read_some(boost::asio::buffer(buffer), read_handler);
}
}
void connect_handler(const boost::system::error_code &ec)
{
if (!ec)
{
boost::asio::write(sock, boost::asio::buffer("GET / HTTP 1.1\r\nHost: highscore.de\r\n\r\n"));
sock.async_read_some(boost::asio::buffer(buffer), read_handler);
}
}
void resolve_handler(const boost::system::error_code &ec, boost::asio::ip::tcp::resolver::iterator it)
{
if (!ec)
{
sock.async_connect(*it, connect_handler);
}
}
int main()
{
boost::asio::ip::tcp::resolver::query query("www.highscore.de", "80");
resolver.async_resolve(query, resolve_handler);
io_service.run();
}
详细安装过程
- 安装gcc,g++,make等开发环境
yum groupinstall "Development Tools"
- 安装boost
yum install boost boost-devel boost-doc
注意:默认的安装路径在/usr/lib64目录下
测试代码
#include <boost/thread.hpp>
#include <iostream>
using namespace boost;
void task1() {
// do stuff
std::cout << "This is task1!" << std::endl;
}
void task2() {
// do stuff
std::cout << "This is task2!" << std::endl;
}
int main (int argc, char ** argv) {
thread thread_1 = thread(task1);
thread thread_2 = thread(task2);
thread_2.join();
thread_1.join();
return 0;
}
- makefile
g++ -I./inlcude -L./usr/lib64 test.cpp -lboost_thread-mt -o example
注意:默认的安装路径在/usr/lib64目录下
5.结果
[root@localhost src]# ./example
This is task2!
This is task1!
[root@localhost src]#
网友评论