PTAM及第三方依赖库编译问题记录

  • Post author:
  • Post category:其他

整体编译参考
一个ptam的cmake项目:这个项目把所有的安装步骤放到了一个脚本里,有时候上一部错了,还要执行下一步,不好定位问题。建议把脚本文件中的内容分开执行

1. array重复声明问题

在编译三方库libcvd是,发生一个关于array声明的错误,详细信息如下:

cvd_src/image_io/cvdimage.cxx:233:52: error: reference to ‘array’ is ambiguous
  233 | void create_normalized_hist(const Image<byte>& im, array<size_t,256>& h)
      |                                                    ^~~~~
In file included from /usr/include/c++/9/tuple:39,
                 from /usr/include/c++/9/bits/unique_ptr.h:37,
                 from /usr/include/c++/9/memory:80,
                 from ./cvd/internal/io/cvdimage.h:7,
                 from cvd_src/image_io/cvdimage.cxx:4:
/usr/include/c++/9/array:94:12: note: candidates are: ‘template<class _Tp, long unsigned int _Nm> struct std::array’
   94 |     struct array
      |            ^~~~~
In file included from cvd_src/image_io/cvdimage.cxx:26:
/usr/include/c++/9/tr1/array:57:12: note:                 ‘template<class _Tp, long unsigned int _Nm> struct std::tr1::array’
   57 |     struct array
      |            ^~~~~
cvd_src/image_io/cvdimage.cxx:233:52: error: ‘array’ has not been declared
  233 | void create_normalized_hist(const Image<byte>& im, array<size_t,256>& h)
      |                                                    ^~~~~
cvd_src/image_io/cvdimage.cxx:233:57: error: expected ‘,’ or ‘...’ before ‘<’ token
  233 | void create_normalized_hist(const Image<byte>& im, array<size_t,256>& h)
      |                                                         ^
cvd_src/image_io/cvdimage.cxx: In function ‘void CVD::CVDimage::create_normalized_hist(const CVD::Image<unsigned char>&, int)’:
cvd_src/image_io/cvdimage.cxx:235:14: error: ‘h’ was not declared in this scope
  235 |         fill(h.begin(), h.end(), 0);
      |              ^

解决方法:
此问题应该是关于其他库中有多个地方声明array导致的,因此推断可能由于版本变动导致源代码中include部分有问题,采取暴力方法试错,将cvd_src/image_io/cvdimage.cxx文件下的以下代码注释被并进行替换,问题就被解决。

//#if defined WIN32 && !defined __MINGW32__
//	#include <array>
//	namespace std{namespace tr1{}}
//	typedef __int64 int64_t;
//	typedef unsigned __int64 uint64_t;
//	typedef unsigned __int16 uint16_t;
//#else
//	#include <stdint.h>
//
//	//#ifdef __GNUC__
//	#if defined __GNUC__ && !defined __clang__
//		#include <tr1/array>
//		using namespace std::tr1;
//	#else
//		#include <array>
//	#endif
//#endif
#include <stdint.h>
#include <array>
using namespace std;

版权声明:本文为weixin_40918019原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。