编译一个开源软件遇到的问题总结

一、开源软件Supra

需要编译一个开源的软件Supra,它需要的前置条件是:
1、cmake ≥ 3.4
2、gcc ≥ 4.8 or min. Visual Studio 2015 (Compiler needs to be supported by CUDA! For that, see the CUDA installation instructions.)
3、QT ≥ 5.5
4、TBB
5、CUDA ≥ 10.0
这个软件需要的依赖项还是比较多的,而且在图像处理中使用了TBB和CUDA,这两个本身就比较麻烦,所以总结一下,把这次编译的过程遇到的主要问题记录下来。
安装的环境为Ubuntu22.04桌面版本。

二、依赖安装

1、先说一下可以使用apt来安装的,包括Gcc,c++,GDB,这些都可以使用apt install来完成,默认的安装版本为Gcc11.3,GDB为gdb12.0.90。TBB也可以安装,默认安装的是libtbb12,坑儿在这儿埋下了,后面咱们再分析。cmake同样也可以使用apt来安装,默认版本是3.22.1.
2、CUDA这个比较好安装去官网按照指定的步骤选择对应的OS版本,就会出现安装下载的
安装步骤:
a) 查看显卡驱动信息
执行命令:

ubuntu-drivers devices

会显示出一个列表,来显示支持的驱动,一般推荐使用recommended版本的相关驱动。
查看当前显卡驱动的版本,并根据版本来安装相关的驱动,安装驱动可以使用apt-install来完成.

sudo apt install nvidia-driver-xxx

b) 验证
安装完成后输入nvidia-smi命令,会出现一个列表框,显示当前的显卡相关版本及驱动和CUDA的版本信息。

在这里插入图片描述

c) 官网下载并安装

https://developer.nvidia.com/cuda-toolkit-archive

在这里插入图片描述

选择Runfile格式安装:

wget https://developer.download.nvidia.com/compute/cuda/12.1.1/local_installers/cuda_12.1.1_530.30.02_linux.run
sudo sh cuda_12.1.1_530.30.02_linux.run

安装过程有两个注意,一个是开始要选择Continue,另外一个就是在安装选项时,要去除驱动安装,因为前面已经安装了驱动。所以说,其实前面也可以不安装驱动在这里一起安装。安装完成后会有一个配置的方法让你进行环境变量的配置,在当前用户路径下的.bashrc中配置即可,记得要source ~/.bashrc一下,不同的终端也要如此。所以最好同一终端下或者启动一个新的终端。

d) 再次验证
执行命令:

nvcc -V

出现相关的版本信息即为安装成功。

3、Qt的安装
从Qt5.15开始,安装Qt开始使用Online方式,去清华大学的镜像地址下载:

https://mirrors.tuna.tsinghua.edu.cn/qt/archive/online_installers/4.5/

在这里插入图片描述

下载后:

sudo chmod 777 qt-unified-linux-x64-4.5.2-online.run
./qt-unified-linux-x64-4.5.2-online.run

安装的选项比较复杂,可以同时安装Qt6.5和Qt5.15。具体的安装过程这里就忽略,网上太多了。有两个注意点:一是安装时如果需要登陆帐号,可提前断网处理;二是安装完成后会有一个工具,不用每次执行这个Run包。这有点类似于VS中的Installer。

三、编译及问题解决

1、执行依赖选项准备

apt-get install cmake cmake-gui qt5-default libtbb-dev libopenigtlink-dev git

如果已经安装可以略过,比如Qt,cmake等。

2、编译
此处有两种编译方式,一种使用官网的方式:

mkdir -p $HOME/git && cd $HOME/git #(or your favorite directory for repositories)
git clone https://github.com/IFL-CAMP/supra.git
cd supra
mkdir -p build && cd build
cmake-gui ..

# 弹出窗口后首先在下拉列表框中选择编译目标为“Unix Makefiles”,其它都略过
a、 Configure    #在弹出的GUI界面选择指定的编译文件路径和输出路径,其下两个根据情况,配置好就不需要了
b、 For systems with multiple gcc versions, make sure to select one supported by the installed CUDA version
c、 You might need to specify the CUDA toolkit directory (usually "/usr/local/cuda")
d、 Configure & Generate, then close cmake and build  #此处会出现找不到Qt5的路径
e、 Build SUPRA
f、 make -j5

Start SUPRA: See below

第二种方法是直接建立build文件夹,然后进入后cmake …,同样会报找不到QT5路径的问题。
问题1:其现象为:

Building SUPRA Graphic Interface
CMake Error at src/GraphicInterface/CMakeLists.txt:8 (find_package):

By not providing "FindQt5.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Qt5", but
  CMake did not find one.

  Could not find a package configuration file provided by "Qt5" with any of
  the following names:

    Qt5Config.cmake
    qt5-config.cmake

  Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR"
  to a directory containing one of the above files.  If "Qt5" provides a
  separate development package or SDK, be sure it has been installed.

Configuring incomplete, errors occurred!

解决方式:
Ubuntu Add the installation prefix of “Qt5“ to CMAKE_PREFIX_PATH or set “Qt5_DIR

解决方法为:

#设置进.bashrc 中
export CMAKE_PREFIX_PATH=/home/xxx/Qt5.xx.x/5.xx.xx/gcc_64/  #xx处根据实际情况确定

设置好后继续编译
问题2:其现象为:

Make Error at src/CommandlineInterface/CMakeLists.txt:27 (ADD_EXECUTABLE):
  Target "SUPRA_CMD" links to target "Threads::Threads" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

CMake Error at src/SupraExecutor/CMakeLists.txt:25 (ADD_EXECUTABLE):
  Target "SUPRA_EXECUTOR" links to target "Threads::Threads" but the target
  was not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

CMake Error at src/GraphicInterface/CMakeLists.txt:124 (add_executable):
  Target "SUPRA_GUI" links to target "Threads::Threads" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

CMake Error at src/Wrapper/CMakeLists.txt:22
(ADD_EXECUTABLE):
  Target "SUPRA_Wrapper" links to target "Threads::Threads" but the target

编译找不到Threads库,解决方法为
(https://discourse.cmake.org/t/cmake-3-21-rc-1-threads-threads-not-found/3630):

find_package(Threads REQUIRED)
target_link_libraries(foo PRIVATE Threads::Threads)  ---foo修改为编译执行名称

解决过程:

步骤:

1、直接在Supra根目录下CMakefilelist.txt,增加,无法处理foo,配置报错。
2、直接改到根目录下的SRC目录中包含的四个CMakefilelist.txt的Add an executable后增加,并将Foo修改为 Add an executable中的名字,如SUPRA-GUI等 。
又报:
  he keyword signature for target_link_libraries has already been used with   the target "SUPRA_GUI".
 All uses of target_link_libraries with a target   must be either all-keyword or all-plain.
  这时将添加Threads  移到最前面去,如下:
TARGET_LINK_LIBRARIES(SUPRA_GUI
Threads::Threads                     ----------------此处
${SUPRA_Lib_LIBRARIES}
${CAMPVIS_LIB}
${NodeEditor_LIBRARIES}
	-----------原来在此处
)
3、将其移植到默认(原有之处 )的中去:
 CMake Error at /home/fpc/Qt515/5.15.2/gcc_64/lib/cmake/Qt5Core/Qt5CoreMacros.cmake:454 (target_link_libraries):
  The keyword signature for target_link_libraries has already been used with
  the target "SUPRA_GUI".  All uses of target_link_libraries with a target
  must be either all-keyword or all-plain.
  The uses of the keyword signature are here:
   * src/GraphicInterface/CMakeLists.txt:156 (TARGET_LINK_LIBRARIES)
Call Stack (most recent call first):
将错误 的地方那个 CmakeFilelist .txt 中的PRIVATE删除即可。

继续编译。
问题3:其现象为:
(https://github.com/linuxdeepin/deepin-system-monitor/issues/34)

CMake Error at /home/fpc/code/supra/build/src/GraphicInterface/NodeEditor_stamp/NodeEditor-build-.cmake:49 (message):
  Command failed: 2
   'make'
  See also
    /home/fpc/code/supra/build/src/GraphicInterface/NodeEditor_stamp/NodeEditor-build-*.log

其内容为:
    In file included from /home/fpc/code/supra/build/src/GraphicInterface/NodeEditor/include/nodes/internal/DataModelRegistry.hpp:12,
                 from /home/fpc/code/supra/build/src/GraphicInterface/NodeEditor/include/nodes/internal/FlowScene.hpp:13,
                 from /home/fpc/code/supra/build/src/GraphicInterface/NodeEditor/src/ConnectionGraphicsObject.cpp:9:
/home/fpc/code/supra/build/src/GraphicInterface/NodeEditor/include/nodes/internal/QStringStdHash.hpp:11:8: error: redefinition of ‘struct std::hash<QString>’
   11 | struct hash<QString>
      |        ^~~~~~~~~~~~~
In file included from /home/fpc/Qt515/5.15.2/gcc_64/include/QtCore/qlist.h:47,
                 from /home/fpc/Qt515/5.15.2/gcc_64/include/QtCore/qobject.h:49,
                 from /home/fpc/Qt515/5.15.2/gcc_64/include/QtWidgets/qgraphicsitem.h:44,
                 from /home/fpc/Qt515/5.15.2/gcc_64/include/QtWidgets/QGraphicsObject:1,
                 from /home/fpc/code/supra/build/src/GraphicInterface/NodeEditor/include/nodes/internal/ConnectionGraphicsObject.hpp:7,
                 from /home/fpc/code/supra/build/src/GraphicInterface/NodeEditor/src/ConnectionGraphicsObject.cpp:1:
/home/fpc/Qt515/5.15.2/gcc_64/include/QtCore/qhashfunctions.h:204:1: note: previous definition of ‘struct std::hash<QString>’

重定义问题,解决方法:
直接进入到具体文件,将冲突重定义类全部注释


/*
namespace std {
template<>
struct hash<QString>{
inline std::size_t
operator()(QString const &s) const {
return qHash(s);
*/

这里需要注意的是,这个是编译动态生成的,所以在修改后不能重新cmake,而是要

make clean
make -j5

一定要注意,否则还得重新修改,陷入了死循环。

继续编译,遇到了TBB的问题。
问题4:其现象为:

/usr/include/oneapi/tbb/profiling.h:229:15: error: expected unqualified-id before ‘)’
token
  229 |     void emit() { }
      |              
 ^
/usr/include/oneapi/tbb/profiling.h:231:22: error: expected unqualified-id before ‘const’
  231
 |     static void emit(const std::string &) { }
      |                      
^~~~~
/usr/include/oneapi/tbb/profiling.h:231:22: error: expected ‘)’ before ‘const’
  231 |     
static void emit(const std::string &) { }
      |                     
~^~~~~
      |                      )
In file included from /usr/include/oneapi/tbb/spin_mutex.h:23,

from /usr/include/oneapi/tbb/flow_graph.h:26,

from /usr/include/tbb/flow_graph.h:17,

from /home/fpc/code/supra/src/SupraLib/AbstractInput.h:21,

from /home/fpc/code/supra/src/SupraLib/SupraManager.h:23,

from /home/fpc/code/supra/src/GraphicInterface/parametersWidget.cpp:
10:
/usr/include/oneapi/tbb/profiling.h:229:15:
error: expected unqualified-id before ‘)’ token
  229 |     
void emit() { }
      |               
^
/usr/include/oneapi/tbb/profiling.h:231:22: error: expected unqualified-id before ‘const’
  231 |  
   static void emit(const std::string &) { }
      |                    
  ^~~~~
/usr/include/oneapi/tbb/profiling.h:231:22: error: expected ‘)’ before ‘const’
  231 |    
 static void emit(const std::string &) { }
      |                     ~^~~~~
      |                      )

[ 94%] Built target SUPRA_CMD

这个就比较恶心了,后来通过前面对apt的使用方式来判断当前版本其实安装的为libtbb12,即使用:

sudo apt install libtbb-dev

使用:

sudo apt list |grep libtbb*

可以列出发现安装版本为oneTbb,到具体的库路径和头文件下都可以看到有oneapi的名称。此时再使用制裁的命令:

sudo apt remove libtbb-dev
sudo apt autoremove

apt search libtbb-dev
sudo apt install libtbb2-dev

再查找一下相关软件包列出来,安装指定的libttb2即可。
再次整体编译,即可发现成功。如果有什么问题,可以执行:

make clean
make -j5

这个重复了数次才算成功,不太顺手。

四、启动软件

按照github上的方法:

src/GraphicInterface/SUPRA_GUI -c data/configDemo.xml -a

出现运行界面即OK。

五、总结

安装这个软件遇到了两个比较麻烦的事情,一个是Threads这个问题,在百度上几乎没有解决方法,即使有的,也不全,只有部分。可怜的国内程序员,解决问题都如此难。第二个是TBB的版本问题,搞得不得安生,亏得有人帮忙,才解决了。国内的软件安装太麻烦了,好多软件都下载不了,包括Github也经常断网,更别提别的了。下个虚拟机,也得等上半天。在线安装Qt,不断让重试。
而且使用的Gcc版本有点高,即使Supra编译成功了,也有大量的警告,如果使用Gcc9就没有这些警告。看来还是需要比较好的确定各种版本,这样才会少走弯路。这也是Linux下开发的一个痛点吧。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值