Ubuntu 编译 fanvanzh/3dtiles

default

背景

为了在 Linux 环境下针对模型文件切片,编译 Releases · fanvanzh/3dtiles (github.com) 的 Linux 环境可执行文件。

  • Ubuntu 环境的编译由于时间因素,终止在了编译 OSG;
  • Centos 环境的编译已成功;

Ubuntu 编译

安装 GCC 编译环境

1
2
3
4
5
6
7
apt-get update

apt-get install -y gcc

apt-get install -y g++

apt-get install -y make

安装 curl

1
apt install -y curl

安装 rust

1
2
3
4
5
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

source $HOME/.cargo/env

rustc --version

修改 Cargo 代理源

1
vim ~/.cargo/config
1
2
3
4
5
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with="ustc"
[source.ustc]
registry = "https://mirrors.ustc.edu.cn/crates.io-index"

编译 OpenSceneGraph

1
2
3
4
5
6
# 太漫长了, 仓库里有编译好的 Centos7.3 OSG,换成 Centos7.3 的环境编译
git clone https://github.com/openscenegraph/OpenSceneGraph.git
cd OpenSceneGraph
cmake .
make
sudo make install

编译

1
cargo build --release

问题处理

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# cargo:warning=./src/osg/osg/GL:114:10: fatal error: GL/gl.h: No such file or directory
apt update
apt install -y libgl1-mesa-dev


# error: failed to run custom build command for `_3dtile v0.1.0 (/opt/3dtiles-linux_osg_370)`
#   cargo:warning=In file included from ./src/shp23dtile.cpp:6:
#  cargo:warning=./src/earcut.hpp: In member function 'mapbox::detail::Earcut<N>::Node* mapbox::detail::Earcut<N>::findHoleBridge(Node*, Node*)':
#  cargo:warning=./src/earcut.hpp:460:23: error: 'numeric_limits' is not a member of 'std'
#  cargo:warning=  460 |     double qx = -std::numeric_limits<double>::infinity();
#  cargo:warning=      |                       ^~~~~~~~~~~~~~
#  cargo:warning=./src/earcut.hpp:460:38: error: expected primary-expression before 'double'
#  cargo:warning=  460 |     double qx = -std::numeric_limits<double>::infinity();
#  cargo:warning=      |                                      ^~~~~~
#  cargo:warning=./src/earcut.hpp:489:26: error: 'numeric_limits' is not a member of 'std'
#  cargo:warning=  489 |     double tanMin = std::numeric_limits<double>::infinity();
#  cargo:warning=      |                          ^~~~~~~~~~~~~~
#  cargo:warning=./src/earcut.hpp:489:41: error: expected primary-expression before 'double'
#  cargo:warning=  489 |     double tanMin = std::numeric_limits<double>::infinity();
#  cargo:warning=      |                                         ^~~~~~##
#
#  --- stderr
#   error occurred: Command "c++" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "./src" "-I" "./src/osg" "-std=c++11" "-o" "/opt/3dtiles-linux_osg_370/target/release/build/_3dtile-89abe1733ae2bb5b/out/341629401c88030c-shp23dtile.o" "-c" "./src/shp23dtile.cpp" with args c++ did not execute successfully (status code exit status: 1).
# 在文件头里添加 #include <limits>
vi src/earcut.hpp


#   = note: /usr/bin/ld: /opt/3dtiles-linux_osg_370/target/release/build/_3dtile-89abe1733ae2bb5b/out/lib_3dtile.a(341629401c88030c-osgb23dtile.o): in function `get_all_tree(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) [clone .localalias]':
#          osgb23dtile.cpp:(.text._Z12get_all_treeRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x2b9): undefined reference to `osgDB::readNodeFiles(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, osgDB::Options const*)'
#          /usr/bin/ld: /opt/3dtiles-linux_osg_370/target/release/build/_3dtile-89abe1733ae2bb5b/out/lib_3dtile.a(341629401c88030c-osgb23dtile.o): in function `osgb2glb_buf(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, MeshInfo&)':
#          osgb23dtile.cpp:(.text._Z12osgb2glb_bufNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS4_R8MeshInfo+0x128): undefined reference to `osgDB::readNodeFiles(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, osgDB::Options const*)'
#          collect2: error: ld returned 1 exit status
#  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
#  = note: use the `-l` flag to specify native libraries to link
#  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib)
apt install openscenegraph
apt install libopenscenegraph-dev

Centos 7.3 编译 3dtiles 工具

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
yum update

yum install -y gcc gcc-c++

yum install git

git clone https://github.com/fanvanzh/3dtiles.git

cd 3dtiles
git checkout linux_osg_370

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

source $HOME/.cargo/env

rustc --version

yum install -y mesa-libGL-devel

cargo build --release

# 编译好的可执行文件为 /opt/3dtiles/target/release/_3dtile
# 需要将 lib 加入环境变量
export LD_LIBRARY_PATH=/path/to/directory:$LD_LIBRARY_PATH
# 执行切片程序
cd /opt/3dtiles/target/release
./_3dtile
Licensed under CC BY-NC-SA 4.0
Gear(夕照)的博客。记录开发、生活,以及一些不足为道的思考……