LAStools 配置过程、遇到的问题及解决方法

说明


  • 虽然网上有很多编译 LASTools 的教程,但是这些博客或多或少都有些问题,现将我自己的配配置经验分享出来,方便后来人使用
  • 如果有任何问题,请与博主联系
  • 博主用的编译环境
    • VS2013
    • Win 10

libLAS 、LAStools 和 LASlib 的关系


  • libLAS 和 LAStools 是两个不一样的库,LAStools 是一个大学教授维护的 ,libLAS 是一个工程师维护的
  • LAStools 里面包含有 LASlib ,所以就把 libLAS 给干掉了,所以 libLAS 不维护了,被淘汰了**
  • libLAS 自己官网都说了直接用 LAStools了
  • 但是 libLAS 不服 LAStools ,索性就发起了 pdal 准备干掉 LAStools

以上引用自:PengPengBlog 的 liblas和lastools的关系

配置过程


1. 下载 LAStools

不要在 Github 上下载,下载的貌似不能用

2. 解压

  • 解压至 D:\

路径尽量不要带中文和空格

3. 用 VS 编译 LAStools

  • 用 VS2013 打开 D:\LAStools\lastools.dsw

其实这里用 VS 哪个版本都无所谓,相差无几

  • 出现复查项目和解决方案更改,直接确定

  • XXXX.XXX 已损坏无法打开,直接确定若干次

  • 选中加载失败的工程,右键移除(DEL)

  • 修改 LASlib 的属性,配置全部修改成 Release ,平台全部修改成 x64

  • C/C++ -> 常规 -> 附加包含目录下 删除 …las\zip\stl

有的教程说还要添加预编译器,经测试,没必要添加,添加后会报错

  • 修改 LASlib -> Header Files ->mydefs.hpp 的内容,见下代码(约代码 69-73行):

行数只是个大概,找自己的即可,有的可能显示的不是 #if defined(_MSC_VER) || defined (MINGW32),没什么关系,只留下#if defined(_MSC_VER)即可

修改前

#if defined(_MSC_VER) || defined (__MINGW32__)
typedef int                BOOL;
#else
typedef bool               BOOL;
#endif

 
 

修改后

#if defined(_MSC_VER) // || defined (__MINGW32__)
typedef int                BOOL;
#else
typedef bool               BOOL;
#endif

 
 

有的博客说把这部分全部注释掉,改成
typedef int Bool
经测试,这样改并不正确

建议将运行时库改为多线程DLL

  • 建议将运行时库改为多线程DLL

在这里插入图片描述

  • 将安全周期检查改为否,否则会出现C4996报错
  • 右键 LASlib 清理,然后重新生成完成编译,正常情况下编译成功,报错请转到编译错误及解决办法

编译错误及解决办法


  1. 错误 35 error C2660: “LASindex::seek_next”: 函数不接受 1 个参
  • 是否自己在预编译器里添加了其他文件
  1. “严重性 代码 说明 项目 文件 行 禁止显示状态 错误 MSB8036 找不到 Windows SDK 版本8.1。请安装所需的版本的 Windows SDK 或者在项目属性页中或通过右键单击解决方案”
  • 参考以下博客

参考博客:visual studio 2017出现MSB8020,MSB8036等SDK版本选择的错误

  1. 出现了“无法打开源文件<stdio.h>”等错误
  • 只需要重新添加包含目录即可
  • 参考以下博客

参考博客:VS2017不能打开stdio.h等文件

测试用例


  • 新建工程 TestLasTools
  • 属性管理器 Release | x64 下新建属性表
  • 设置属性表:
    • VC++目录 -> 包含目录:D:\LAStools\LASzip\srcD:\LAStools\LASlib\inc
    • VC++目录 -> 库目录:D:\LAStools\LASlib\lib
    • 链接器 -> 输入 -> 附加依赖项:LASlib.lib
    • 快速设置键下方
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup>
    <IncludePath>D:\LAStools\LASzip\src;D:\LAStools\LASlib\inc;$(IncludePath)</IncludePath>
    <LibraryPath>D:\LAStools\LASlib\lib;$(LibraryPath)</LibraryPath>
  </PropertyGroup>
  <ItemDefinitionGroup>
    <Link>
      <AdditionalDependencies>LASlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup />
</Project>

 
 
  • 新建 main.cpp 文件
#include <iostream>
#include "lasreader.hpp"
void foo(){
//laslib只允许'\\'格式的文件路径。
	std::string lasFile("E:\\test_LAStools.las");  //替换成自己的路径
//打开las文件
	LASreadOpener lasreadopener;
	lasreadopener.set_file_name(lasFile.c_str());
	LASreader* lasreader = lasreadopener.open();
	//size_t count = lasreader->header.number_of_point_records;
int loop_time = 0;
	while (lasreader->read_point() && loop_time < 10)  //只让输出前 10 行坐标
	{
		std::cout << lasreader->point.get_x() << "  "
			<< lasreader->point.get_y() << "  "
			<< lasreader->point.get_z() << std::endl;
        loop_time++;
	}
	lasreader->close();
	delete lasreader;
}
int main(){
	foo();
	return 0;
}

 
 
  • 运行看是否成功,失败的话请看下面

调用库失败原因及其详解


  1. error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MDd_DynamicDebug”不匹配值“MTd_StaticDebug”
  • 右键 工程 -> 属性 -> C/C++ -> 代码生成 -> 运行库 改成多线程(/MT)
  • 详情请见

参考一:error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MDd_DynamicDebug”不匹配值“MTd_StaticDebug”

参考二:值“MD_DynamicRelease”不匹配值“MDd_DynamicDebug”的问题

  1. 1>ConsoleApplication3.obj : error LNK2001: 无法解析的外部符号 "public: __cdecl LASreadOpener::~LASreadOpener(void)" (??1LASreadOpener@@QEAA@XZ)
  • 尝试检查属性表配置的是否正确
  1. error LNK2005: ___xi_a 已经在 msvcrt.lib(cinitexe.obj) 中定义
  • 参考以下博客

参考博客:error LNK2005: ___xi_a 已经在 msvcrt.lib(cinitexe.obj) 中定义

  1. 待补充

打包下载编译好的工程及测试代码


或者

常用命令

  1. las2txt -i lidar.laz -o lidar.txt -parse xyzRGB

converts LAZ file to ASCII and places the x, y, and z coordinates at the 1st, 2nd, and 3rd entry and the r, g, and b value of the RGB color as the 4th, 5th, and 6th entry of each line. the entries are separated by a space. note that lidar.las should be format 1.2 or higher (because 1.0 and 1.1 do not support RGB colors).

  1. las2txt -i lidar.las -o lidar.txt -parse xyz

converts LAS file to ASCII and places the x, y, and z coordinate of each point at the 1st, 2nd, and 3rd entry of each line. the entries are separated by a space.

  1. las2txt -i lidar.laz -o lidar.txt -parse xyzcu -sep tab -header percent

converts LAZ file to ASCII and places the x, y, and z coordinate at the 1st, 2nd, and 3rd entry, the classification at the 4th and the user data as the 5th entry of each line. the entries are separated by a semicolon. at the beginning of the file we print the header information as a comment starting with a ‘%’ symbol.

参考博客


  1. LASlib在VS2015 x64平台下的编译
  2. LASlib编译和配置LASlib (VS2013 release win7 64位)
  3. VS2017+win10编译LASTools库

联系作者


邮箱:Neverland-LY@163.com

                                </div>
            <link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-e44c3c0e64.css" rel="stylesheet">
                </div>
  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值