gpt4 book ai didi

c++ - 无法使用 fixup_bundle() 与 Qt 创建可移植包

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:31:38 24 4
gpt4 key购买 nike

我已经在其他帖子上搜索过这个问题,但目前还没有。所以我来了。

我想创建一个可移植的包。便携,如“我可以在任何 OS X 机器上运行它,即使我需要的库 (Qt) 没有安装”。不幸的是,我不知道如何使用 fixup_bundle()(这似乎是正确的工具)来实现这个目标。

这是我最小的 CMake 生成的 C++ 项目:

主要.cpp

#include <QString>
#include <iostream>

int main()
{
QString s("Hello, world!");
std::cout << s.toStdString() << std::endl;
return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.11)

project(test)

# That part because I use a custom build of Qt. That's not the
# relevant part (I guess?)
FILE(GLOB QTROOTS path_to_qt/Qt-4.8.1/osx/bin/qmake)
find_program(QT_QMAKE_EXECUTABLE NAMES qmake PATHS ${QTROOTS})
find_package(Qt4 COMPONENTS QtCore REQUIRED)
include(${QT_USE_FILE})

add_executable(test MACOSX_BUNDLE main.cpp)

target_link_libraries(test ${QT_LIBRARIES})

install(SCRIPT bundle.cmake)

捆绑.cmake

INCLUDE(BundleUtilities)
fixup_bundle(test.app "" "")

这是生成的 test.app 结构

test.app
- Contents
- Info.plist
- Frameworks
- QtCore.framework
- Versions
- 4
- QtCore
- MacOS
- test

所需的一切似乎都在包中。一切都顺利编译,运行良好,但是当我调用 fixup_bundle 时,这就是我得到的:

vincent@hpcd0016-lion:tmp/test_bundle/ (0) > make install

[100%] Built target test
Install the project...
-- Install configuration: ""
-- fixup_bundle
-- app='test.app'
-- libs=''
-- dirs=''
-- fixup_bundle: preparing...
-- fixup_bundle: copying...
-- 1/4: *NOT* copying '/Users/vincent/tmp/test_bundle/test.app/Contents/MacOS/test'
-- 2/4: copying 'path_to_qt/Qt-4.8.1/osx/lib//QtCore.framework/Versions/4/QtCore'
-- fixup_bundle: fixing...
-- 3/4: fixing up '/Users/vincent/tmp/test_bundle/test.app/Contents/MacOS/test'
exe_dotapp_dir/='test.app/Contents/MacOS/'
item_substring='/Users/vincent/t'
resolved_embedded_item='/Users/vincent/tmp/test_bundle/test.app/Contents/MacOS/test'

Install or copy the item into the bundle before calling fixup_bundle.
Or maybe there's a typo or incorrect path in one of the args to fixup_bundle?

CMake Error at /Applications/CMake 2.8-11.app/Contents/share/cmake-2.8/Modules/BundleUtilities.cmake:568 (message):
cannot fixup an item that is not in the bundle...
Call Stack (most recent call first):
/Applications/CMake 2.8-11.app/Contents/share/cmake-2.8/Modules/BundleUtilities.cmake:656 (fixup_bundle_item)
bundle.cmake:2 (fixup_bundle)
cmake_install.cmake:31 (INCLUDE)


make: *** [install] Error 1

有依赖路径(由 otool -L 给出):

vincent@hpcd0016-lion:test.app/Contents/ (0) > otool -L test.app/Contents/MacOS/test     
test.app/Contents/MacOS/test:
path_to_qt/Qt-4.8.1/osx/lib//QtCore.framework/Versions/4/QtCore (compatibility version 4.8.0, current version 4.8.1)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)

vincent@hpcd0016-lion:tmp/test_bundle/ (0) > otool -L test.app/Contents/Frameworks/QtCore.framework/Versions/4/QtCore
test.app/Contents/Frameworks/QtCore.framework/Versions/4/QtCore:
path_to_qt/Qt-4.8.1/osx/lib//QtCore.framework/Versions/4/QtCore (compatibility version 4.8.0, current version 4.8.1)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 41.0.0)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 635.15.0)
/System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 55010.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1094.0.0)
/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 53.0.0)

显然,fixup_bundle 没有修复二进制文件的包,它们的 id 仍然设置为我机器的路径。

我在这个简单的例子中做错了什么?

最佳答案

我在 CMakeLists.txt 的顶部添加了这一行

set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR})

就是这样。

显然,默认情况下,CMAKE_INSTALL_PREFIX 在我的机器上设置为/usr/local。如果将其更改为我当前的工作目录解决了问题,则意味着 CMake 正在尝试对/usr/local 执行一些操作(这是不允许的)。那么为什么报错信息中没有提到这样的权限访问错误呢?

不知道是我看的文档不够多,还是文档需要一些精确...

关于c++ - 无法使用 fixup_bundle() 与 Qt 创建可移植包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17974439/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com