网站建设期间注意事项,石大远程网页设计与网站建设答案,公司建设网站的分录,做外贸的女生干净吗提示#xff1a;文章写完后#xff0c;目录可以自动生成#xff0c;如何生成可参考右边的帮助文档 文章目录 前言 一、--prefix命令 二、安装过程 1、shell脚本#xff1a; 2、gcc编译环境 执行过程 三、linux下执行cpp程序 总结 前言
提示#xff1a;这里可以添加本文… 提示文章写完后目录可以自动生成如何生成可参考右边的帮助文档 文章目录 前言 一、--prefix命令 二、安装过程 1、shell脚本 2、gcc编译环境 执行过程 三、linux下执行cpp程序 总结 前言
提示这里可以添加本文要记录的大概内容
例如随着人工智能的不断发展机器学习这门技术也越来越重要很多人都开启了学习机器学习本文就介绍了机器学习的基础内容。 提示以下是本篇文章正文内容下面案例可供参考
一、--prefix命令
--prefix命令是什么意思
如果指定 --prefix
比如 --prefix/usr/local/keepalived 则此软件的所有文件都到 /usr/local/keepalived 目录下很整齐。
二、安装过程
在linux上安装boost库
1、shell脚本
#!/bin/bash
PREFIX_INC_PATH$(cd $(dirname $0);pwd)
tar xzvf boost-1.79.0.tar.gz
#git git地址
mv boost-1.79.0 boost
chmod -R 777 boost
cd boost
./bootstrap.sh --with-librariesall --with-toolsetgcc
./b2 cxxflags-fPIC cflags-fPIC toolsetgcc linkstatic
./b2 install --prefix../boost_install/
cd ..
rm -rf ${PREFIX_INC_PATH}/../include ${PREFIX_INC_PATH}/../lib
mkdir -p ${PREFIX_INC_PATH}/../lib/linux
cp -rf boost_install/include ../
cp -f boost_install/lib/libboost_date_time.a ../lib/linux/
cp -f boost_install/lib/libboost_filesystem.a ../lib/linux/
cp -f boost_install/lib/libboost_log.a ../lib/linux/
cp -f boost_install/lib/libboost_regex.a ../lib/linux/
cp -f boost_install/lib/libboost_serialization.a ../lib/linux/
cp -f boost_install/lib/libboost_system.a ../lib/linux/
cp -f boost_install/lib/libboost_thread.a ../lib/linux/
cp -f boost_install/lib/libboost_iostreams.a ../lib/linux/
rm -rf boost_install
rm -rf boost
2、gcc编译环境
gcc 8.2.0
执行过程
执行bash build.sh
因为安装时指定了路径./b2 install --prefix../boost_install/
所以编译出的静态库都在../lib/linux/路径中。 三、linux下执行cpp程序
按照教程编写cpp文件
#include iostream
#include boost/bind.hpp
#include string
using namespace std;class Hello
{
public:void say(string name) { cout name say: hello world! endl; }
};int main()
{Hello h;auto func boost::bind(Hello::say, h, zhang san);func();return 0;
}
Linux编译安装boost库_linux编译boost-CSDN博客
按照上述教程写好cpp程序将test-boost.cpp文件导入linux环境
按照这个教程执行编译程序指令
Linux下编译使用boost库 - 代码先锋网
按照他的教程执行g test-boost.cpp -o test -I /home/johnchen/boost_1_56_0/include -L /home/johnchen/boost_1_56_0/lib -l:libboost_system.a -l:libboost_filesystem.a指令但是报错 /usr/local/bin/ld: cannot find -l:libboost_system.a /usr/local/bin/ld: cannot find -l:libboost_filesystem.a collect2: error: ld returned 1 exit status 百度这个报错理解为执行器还是从/usr/local/bin/ld路径下寻找静态库了
理解为没有正确链接景泰路但是我的静态库文件在../lib/linux路径下所以需要正确指定静态库路径于是现在的问题就是怎么正确链接静态库于是但是百度静态链接百度关键词【linux gcc 链接静态库的几种方式】找到这个教程linux gcc 链接静态库的几种方式_yygr的博客-CSDN博客
文中说到 注意上面的说明中红框标注的内容如果-l:filename格式指定一个文件名连接程序直接去找这个文件名了不会再像使用-lname时将name扩展成libname.a格式的文件名. 所以使用 -l:libpng.a这样的形式来指定连接库就指定了静态连接png库。 当然如果库的位置不在gcc默认搜索路径中要用-L参数另外指定搜索库的路径否则连接程序不知道该从哪里找到filename。 -L/your/library/path -l:libmylib.a 将编译指令更改为
g test-boost.cpp -o test -L /root/data/lib/linux -l:libboost_system.a -l:libboost_filesystem.a
执行成功路径下增加test*文件 执行文件./test 成功到此boost库安装成功并正确编译程序。OK
四、linux/windows环境编译boost库
Boost库编译指南_boost 编译_Jelin大魔王的博客-CSDN博客 总结
boost库安装成功并正确编译程序