由于强迫症,实在受不了root权限的旧gcc才能使用boost而普通权限却是最新版gcc,经过一番折腾后,终于把配置全部弄好了,实际上就只需要把新版gcc的各个文件放到系统找到旧gcc的地方,并建立新版的gcc、g++的软链接就可以覆盖系统旧版的了,然后再重新编译boost即可。
弄好之后,我又开始折腾安装OpenCV了,可能由于最新版的gcc做了一些新改动,比如cstdlib头文件中使用了#include_next <stdlib.h>这样的方式包含了头文件stdlib.h,但OpenCV的库文件可不认识,make一会而就报错:
/usr/include/c++/8.1.0/cstdlib:75:25:致命错误: stdlib.h: No such file or directory #include_next <stdlib.h>
参考网上,将对应错误的文件中的#include_next修改#include就可以了。
。。。
但进行到92%的时候又出错了,是一个python文件的assert错:
[ 92%] Generate files for Java bindings Traceback (most recent call last): File "/home/darkchii/下载/opencv-3.4.1/modules/java/generator/../generator/gen_java.py", line 1093, in <module> copy_java_files(java_files_dir, target_path) File "/home/darkchii/下载/opencv-3.4.1/modules/java/generator/../generator/gen_java.py", line 1032, in copy_java_files src = checkFileRemap(java_file) File "/home/darkchii/下载/opencv-3.4.1/modules/java/generator/../generator/gen_java.py", line 25, in checkFileRemap assert path[-3:] != '.in', path AssertionError: /home/darkchii/下载/opencv-3.4.1/modules/java/generator/src/java/org/opencv/osgi/OpenCVNativeLoader.java.in make[2]: *** [CMakeFiles/dephelper/gen_opencv_java_source] 错误 1 make[1]: *** [modules/java_bindings_generator/CMakeFiles/gen_opencv_java_source.dir/all] 错误 2 make: *** [all] 错误 2
网上搜了一会儿也没发现相关的问题,都是关于java异常的错误。
由于找不到解决办法,于是打算自己动手修改源文件的一些代码,发现可行,下面就是我的解决办法:
将gen_java.py源文件中的25行:
assert path[-3:] != '.in', path
修改为:
assert path[-4:] != '.in', path
即可,然后重新make,又是这个文件的错误,这次是编码错误:
[ 92%] Generate files for Java bindings
JAVA: Processing OpenCV modules: 12
duplicated: CLASS cv::.Algorithm :
SKIP:void read(FileNode fn) due to ARG typeFileNode/I
SKIP:void write(Ptr_FileStorage fs, String name = String()) due to ARG typePtr_FileStorage/I
Traceback (most recent call last):
File "/home/darkchii/下载/opencv-3.4.1/modules/java/generator/../generator/gen_java.py", line 1164, in <module>
generator.gen(srcfiles, module, dstdir, jni_path, java_path, common_headers)
File "/home/darkchii/下载/opencv-3.4.1/modules/java/generator/../generator/gen_java.py", line 492, in gen
self.save(cpp_file, T_CPP_MODULE.substitute(m = module, M = module.upper(), code = moduleCppCode.getvalue(), includes = "\n".join(includes)))
File "/home/darkchii/下载/opencv-3.4.1/modules/java/generator/../generator/gen_java.py", line 441, in save
f.write(buf)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 215-216: ordinal not in range(128)
make[2]: *** [CMakeFiles/dephelper/gen_opencv_java_source] 错误 1
make[1]: *** [modules/java_bindings_generator/CMakeFiles/gen_opencv_java_source.dir/all] 错误 2
make: *** [all] 错误 2
于是将源文件中441行:
f.write(buf)
修改为:
f.write(buf.encode('utf-8'))
即可,然后重新make,于是我的问题就全解决了~
ps:安装好以后,在gcc编译使用OpenCV的实例代码的时,如果出现'xxx'未定义的引用的ld错误,则需要在编译语句后加上,链接库,例如:
g ++ -o test test.cpp `pkg-config opencv --cflags --libs`