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

时间:2016-05-09 12:36:13

标签: 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

所以我希望cmake-gui开始在/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 +++

我在LFS中找到了一个示例,我可以使用qtX的自定义路径:

  

如果在/ opt中安装了Qt4和Qt5,请使用source setqt4或source   setqt5选择将用于构建基于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  

1 个答案:

答案 0 :(得分:1)

要仅调整cmake-gui的rpath,您应该在Source/QtDialog/CMakeLists.txt后添加add_executable(cmake-gui....)的内容:

set_target_properties(cmake-gui PROPERTIES                
  INSTALL_RPATH "/opt/path/to/qt/shared/libs"
)

不要忘记完全重新生成CMake构建文件。正确配置的构建应在-Wl,-rpath,<specified-path>

中的链接器调用命令中包含Source/QtDialog/CMakeFiles/cmake-gui.dir/link.txt

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