Dlib安装教程
[if !supportLists]1. [endif]系统环境
CentOs 7. 64位
[if !supportLists]2. [endif]需要安装的文件
boost、gcc-4.8.5、 cmake 3.10.1、dlib 19.7
[if !supportLists]3. [endif]相关文件下载链接
3.1 Dlib下载地址
3.2 Dlib版本:19.7
3.3 GCC下载地址
3.4 Centos升级gcc4.4.7到gcc4.8教程
https://www.mudbest.com/centos%E5%8D%87%E7%BA%A7gcc4-4-7%E5%8D%87%E7%BA%A7gcc4-8%E6%89%8B%E8%AE%B0/
3.5 boost下载地址
https://dl.bintray.com/boostorg/release/1.66.0/source/
[if !supportLists]4. [endif]安装步骤
4.1 GCC
本次安装选用GCC-4.8.5
*注意1:
在编译安装GCC之前,系统里必须先要通过 yum 安装老版本的 GCC 和依赖库。如果是在 x86_64 系统下编译的话,还需要安装 libgcc.i686 glibc-devel.i686 才行。
在x86_64系统安装老版本GCC
# yum install -y gcc texinfo-tex flex zip libgcc.i386 glibc-devel.i386
*注意2:
编译安装GCC内存不小于 1GB,Swap 不小于 1GB,硬盘最低不小于 10GB,否则极有可能会中途报错退出。编译安装完后,目录 gcc-4.8.5 将会有 5GB 之多。
4.1.1下载源码
命令行下载:
# wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.8.5/gcc-4.8.5.tar.gz
或者直接在官网下载,然后上传压缩包。
4.1.2下载依赖包
编译安装GCC需要依赖 mpc,mpfr,gmp包。这个不需要下载,源码包自带脚本可以自动下载,我们只需要执行脚本就可以。
# tar zxf gcc-4.8.5.tar.gz
# cd gcc-4.8.5
# ./contrib/download_prerequisites
4.1.3编译安装
# mkdir gcc-build-4.8.5
# cd gcc-build-4.8.5
# ../configure --prefix=/usr
# make && make install
说明:
为了避免安装后系统里出现多个版本的GCC,这里直接将编译安装的目录指定为 /usr,如果不指定 --prefix,则会默认安装到 /usr/local 下。
GCC 4.8.5光是源代码就有105MB,因此可以预见整个编译过程需要很长时间(差不多 2 个小时左右)。
Install error安装期间若出现下面问题可以参考:
errer1:
configure: error: C++ compiler missing orinoperational
make[2]: \*** [configure-stage1-libcpp]Error 1
make[2]: Leaving directory`/home/liukk/gcc-4.8.1'
make[1]: \*** [stage1-bubble] Error 2
make[1]: Leaving directory `/home/liukk/gcc-4.8.1'
make: \*** [all] Error 2
解决办法:
安装如下内容:
# yum install gcc-c++
4.1.4查看版本
# which gcc
/usr/bin/gcc
# which g++
/usr/bin/g++
4.1.5测试程序
创建一个main.cpp文件,内容如下:
#include
using namespace std;
int main() {
cout << "Hello world!" << endl;
return 0;
}
编译main.cpp,执行如下命令:
# g++ main.cpp -o main
执行生成的文件:
# ./main
Hello world!
4.1.5最后在检查GCC包安装情况
4.2 boost
本次安装boost_1_66_0
boost安装比较简单,一次执行如下命令即可
# tar -zxvf boost_1_66_0.tar.gz ----(解压缩)
# cd boost_1_66 ----(进入boost_1_59_0)
# ./bootstrap.sh ----(执行boost脚本)
# ./b2 ----(编译,编译过程中,可忽略未声明定义等错误)
# ./b2 install ----(执行安装,大概执行5-10分钟)
4.3 cmake
本次安装使用cmake-3.10.1
4.3.1下载源码
4.3.2解压之后,进入解压目录
# ./bootstrap
# make
# make install
安装完成之后查看版本,即成功。
参考:
4.4 Dlib
本次安装dlib-19.7
4.4.1下载源码,并解压
进入dlib-19.7路径
说明:上图,dlib路径存放库的相关头文件
examples路径存放库自带的例子程序,编译完成之后,可执行文件在路径./examples/build ,库文件在./examples/build/dlib-build
4.4.2编译
# cd examples
# mkdir build
# cd build
# cmake ..
# cmake --build . --config Release
编译过程错误
[if !supportLists]1. [endif]内存无法分配问题:virtual memory exhausted:无法分配内存
[ 71%] Building CXX object CMakeFiles/dnn_metric_learning_on_images_ex.dir/dnn_metric_learning_on_images_ex.cpp.o
virtual memory exhausted:无法分配内存
gmake[2]: *** [CMakeFiles/dnn_metric_learning_on_images_ex.dir/dnn_metric_learning_on_images_ex.cpp.o]错误 1
gmake[1]: *** [CMakeFiles/dnn_metric_learning_on_images_ex.dir/all]错误 2
gmake: *** [all]错误 2
[root@localhost build]#
问题原因:由于物理内存本身很小,且阿里云服务器并没有分配swap空间,当物理内存不够用时,物理内存中暂时不用的内容没地方转存。
解决方法:手动分配一个swap空间
dd if=/dev/zero of=/swap bs=1024 count=1M #创建一个大小为1G的文件/swap mkswap /swap #将/swap作为swap空间 swapon /swap #enable /swap file for paging and swapping echo "/swap swap swap sw 0 0" >> /etc/fstab #Enable swap on boot,开机后自动生效
操作记录:
[root@localhost icooper]# dd if=/dev/zero of=/swap bs=1024 count=1M
记录了1048576+0 的读入
记录了1048576+0 的写出
1073741824字节(1.1 GB)已复制,4.06152 秒,264 MB/秒
[root@localhost icooper]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 10G 1.1G 9.0G 11% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 152K 1.9G 1% /dev/shm
tmpfs 1.9G 9.0M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-usr 10G 3.2G 6.9G 32% /usr
/dev/mapper/centos-icooper 891G 870M 890G 1% /icooper
/dev/mapper/centos-home 4.9G 37M 4.9G 1% /home
/dev/mapper/centos-var 10G 127M 9.9G 2% /var
/dev/sda1 2.0G 164M 1.8G 9% /boot
tmpfs 373M 12K 373M 1% /run/user/1000
tmpfs 373M 0 373M 0% /run/user/0
[root@localhost icooper]# ls /swap
/swap
[root@localhost icooper]#
[root@localhost icooper]# mkswap /swap
正在设置交换空间版本1,大小 = 1048572 KiB
无标签,UUID=9d5b0082-b46c-402b-aa33-066357f20ca4
[root@localhost icooper]# swapon /swap
swapon: /swap:不安全的权限 0644,建议使用 0600。
[root@localhost icooper]# free -m
total used free shared buff/cache available
Mem: 3722 619 506 10 2596 2746
Swap: 5023 0 5023
[root@localhost icooper]#
内存太小,增加内存可以解决。
使用完毕后可以关掉swap:
[if !supportLists]1. [endif][root@hz mnt]# swapoff swap
[if !supportLists]2. [endif][root@hz mnt]# rm -f /swap
swap文件也可以不删除,留着以后使用,关键是你的虚拟机硬盘够用。
[if !supportLists]2. [endif]头文件包含问题
1 #error "Don't put the dlib folder in your include path"
2 /*
3 You are getting this error because you have added the dlib folder to your
4 compiler's include search path.
5
6 You should *NOT* add the dlib folder itself to your compiler's include path.
7 Doing so will cause the build to fail because of name collisions (such as
8 dlib/string.h and string.h from the standard library). Instead you should
9 add the folder that contains the dlib folder to your include search path
10 and then use include statements of the form #include or
11 #include "dlib/queue.h". This will ensure that everything builds correctly.
12
13 XCode:
14 The XCode IDE often puts all folders that it knows about into
15 the compiler search path. So if you are using XCode then either 16 don't drag the whole dlib folder into the project or alternatively 17 modify your XCode project settings to not auto-add all folders to
18 the include path. Instead just make sure that the dlib folder is
19 itself inside a folder in your include path.
20 */
��\&,�K�,s����









网友评论