【问题标题】:How to build cmake-gui with a custom path to qt?如何使用 qt 的自定义路径构建 cmake-gui?
【发布时间】:2016-05-09 12:36:12
【问题描述】:

我正在尝试使用自定义路径构建 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 的示例:

如果 Qt4 和 Qt5 安装在 /opt 中,使用 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  

【问题讨论】:

  • 嗯,你应该在构建过程中使用-rpath链接器选项,或者在执行之前将库的路径添加到LD_LIBRARY_PATH环境变量中。
  • 如果你输入ls /opt | grep qt,你会得到什么?我不知道 LFS,但似乎你必须在开始构建 cmake 之前运行source setqt4
  • 所以它不是cmake的一部分?

标签: qt gcc compilation cmake


【解决方案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 构建文件。正确配置的构建应在Source/QtDialog/CMakeFiles/cmake-gui.dir/link.txt 的链接器调用命令中包含-Wl,-rpath,<specified-path>

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

【讨论】:

    猜你喜欢
    • 2017-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 2022-01-01
    相关资源
    最近更新 更多