如何使用qt的自定义路径构建cmake gui?

如何使用qt的自定义路径构建cmake gui?,qt,gcc,compilation,cmake,Qt,Gcc,Compilation,Cmake,我正在尝试使用自定义路径构建cmake gui,但在运行时失败: #/opt/dev-tools-4.9/cmake-gui /opt/dev-tools-4.9/cmake-gui: error while loading shared libraries: libQtGui.so.4: cannot open shared object file: No such file or directory 所以我希望CmakeGUI开始在/opt/dev-tools-4.9搜索qtX,但它是从系

我正在尝试使用自定义路径构建
cmake gui
,但在运行时失败:

#/opt/dev-tools-4.9/cmake-gui
/opt/dev-tools-4.9/cmake-gui: error while loading shared libraries: libQtGui.so.4: cannot open shared object file: No such file or directory
所以我希望CmakeGUI开始在/opt/dev-tools-4.9搜索qtX,但它是从系统中使用的

# strace -f ./cmake-gui
execve("./cmake-gui", ["./cmake-gui"], [/* 24 vars */]) = 0
brk(0)                                  = 0x13ca000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fcfdff0b000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=53974, ...}) = 0
mmap(NULL, 53974, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fcfdfefd000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/tls/x86_64/libQtGui.so.4", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib/x86_64-linux-gnu/tls/x86_64", 0x7fffebe47810) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/tls/libQtGui.so.4", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib/x86_64-linux-gnu/tls", 0x7fffebe47810) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/x86_64/libQtGui.so.4", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib/x86_64-linux-gnu/x86_64", 0x7fffebe47810) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libQtGui.so.4", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib/x86_64-linux-gnu", {st_mode=S_IFDIR|0755, st_size=12288, ...}) = 0
open("/usr/lib/x86_64-linux-gnu/tls/x86_64/libQtGui.so.4", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib/x86_64-linux-gnu/tls/x86_64", 0x7fffebe47810) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/tls/libQtGui.so.4", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib/x86_64-linux-gnu/tls", 0x7fffebe47810) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/x86_64/libQtGui.so.4", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib/x86_64-linux-gnu/x86_64", 0x7fffebe47810) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/libQtGui.so.4", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib/x86_64-linux-gnu", {st_mode=S_IFDIR|0755, st_size=32768, ...}) = 0
open("/lib/tls/x86_64/libQtGui.so.4", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib/tls/x86_64", 0x7fffebe47810) = -1 ENOENT (No such file or directory)
open("/lib/tls/libQtGui.so.4", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib/tls", 0x7fffebe47810)        = -1 ENOENT (No such file or directory)
open("/lib/x86_64/libQtGui.so.4", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib/x86_64", 0x7fffebe47810)     = -1 ENOENT (No such file or directory)
open("/lib/libQtGui.so.4", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/lib", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
open("/usr/lib/tls/x86_64/libQtGui.so.4", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib/tls/x86_64", 0x7fffebe47810) = -1 ENOENT (No such file or directory)
open("/usr/lib/tls/libQtGui.so.4", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib/tls", 0x7fffebe47810)    = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64/libQtGui.so.4", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib/x86_64", 0x7fffebe47810) = -1 ENOENT (No such file or directory)
open("/usr/lib/libQtGui.so.4", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/usr/lib", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
writev(2, [{"./cmake-gui", 11}, {": ", 2}, {"error while loading shared libra"..., 36}, {": ", 2}, {"libQtGui.so.4", 13}, {": ", 2}, {"cannot open shared object file", 30}, {": ", 2}, {"No such file or directory", 25}, {"\n", 1}], 10./cmake-gui: error while loading shared libraries: libQtGui.so.4: cannot open shared object file: No such file or directory
) = 124
exit_group(127)                         = ?
+++ exited with 127 +++
我在一个示例中发现,我可以使用qtX的自定义路径:

如果Qt4和Qt5安装在/opt中,请使用源setqt4或源 设置qt5以选择用于构建基于Qt的GUI的选项

但没有这些文件:

~# cd cmake-3.5.2
root:~/cmake-3.5.2# ls |grep set
root:~/cmake-3.5.2#
libarchive的构建

wget http://www.libarchive.org/downloads/libarchive-3.2.0.tar.gz
tar xzvf  libarchive-3.2.0.tar.gz
./configure --prefix=/opt/dev-tools-4.9 --disable-static && \
make -j $(nproc || grep -c ^processor /proc/cpuinfo|| echo "1") && \
make install  
cmake 2.8.11的构建

wget --no-check-certificate https://cmake.org/files/v2.8/cmake-2.8.11.tar.gz
tar xzvf cmake-2.8.11.tar.gz
./bootstrap --prefix=/opt/dev-tools-4.9   \
  --no-system-libs --qt-gui         && \
  make -j $(nproc || grep -c ^processor /proc/cpuinfo|| echo "1") && \
  make install  

要仅调整cmake gui的rpath,应在
添加可执行文件(cmake gui…)
之后,向
源代码/QtDialog/CMakeLists.txt
中添加类似的内容:

不要忘记完全重新生成CMake构建文件。正确配置的生成应该在
Source/QtDialog/CMakeFiles/cmakegui.dir/link.txt中的链接器调用命令中包含
-Wl,-rpath,


注意:所有内容都是根据cmake-3.2.2进行检查的,但我认为cmake的其他版本在这方面没有显著差异。

好的,您应该在构建过程中使用
-rpath
链接器选项,或者在执行之前将libs的路径添加到LD_LIBRARY_path环境变量。如果键入
ls/opt | grep qt
,会得到什么?我不知道LFS,但似乎在开始构建cmake之前必须运行
源代码setqt4
,所以它不是cmake的一部分?
set_target_properties(cmake-gui PROPERTIES                
  INSTALL_RPATH "/opt/path/to/qt/shared/libs"
)