记录一次难搞的编译错误-- qml-rust 项目编译无法找到QtCore库的问题

本文主要是介绍记录一次难搞的编译错误-- qml-rust 项目编译无法找到QtCore库的问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

记录一次难搞的编译错误-- qml-rust 项目编译时无法找到QtCore库的问题

  • 背景
  • 开始处理问题
    • 1 看日志找关键点
    • 2 写最简单测试用例
    • 3 写最简单CMake编译的Qt
    • 4 发现问题
    • 5 开始处理错误
    • 过程 1
    • 过程2
    • 过程3
  • 反思
  • 开始找资料,解决自己的困惑。
  • 第二次开始解决问题
  • 第三次解决问题
  • 总结

背景

平台:Mac
项目管理方式:CMake cargo
项目github:CXX-QT
这个项目主要是一个Qt /Qml 和 rust互操作的一个实现。
在编译项目时,链接阶段报错:

QtCore not found.

日志文件:

[main] Building folder: cxx-qt
[build] Starting build
[proc] Executing command: /opt/homebrew/bin/cmake --build /Users/allen/Projects/RustProjects/cxx-qt/build --config Debug --target _cargo-build_qml-features –
[build] [1/2 0% :: 0.002] cd /Users/allen/Projects/RustProjects/cxx-qt/examples/qml_features/rust && /Applications/CMake.app/Contents/bin/cmake -E env CXXQT_EXPORT_DIR=/Users/allen/Projects/RustProjects/cxx-qt/build/examples/qml_features/cxxqt DYLD_FRAMEWORK_PATH=/opt/homebrew/Cellar/qt@5/5.15.12_1/lib QMAKE=/opt/homebrew/Cellar/qt@5/5.15.12_1/bin/qmake CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER=/usr/bin/clang CC_aarch64-apple-darwin=/usr/bin/clang CXX_aarch64-apple-darwin=/usr/bin/clang++ SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk CORROSION_BUILD_DIR=/Users/allen/Projects/RustProjects/cxx-qt/build/examples/qml_features CARGO_BUILD_RUSTC=/Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc /Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo rustc --lib --target=aarch64-apple-darwin --package qml-features --manifest-path /Users/allen/Projects/RustProjects/cxx-qt/examples/qml_features/rust/Cargo.toml --target-dir /Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build – -Cdefault-linker-libraries=yes
[build] Compiling cxx-qt-lib v0.6.0 (/Users/allen/Projects/RustProjects/cxx-qt/crates/cxx-qt-lib)
[build] Compiling qml-features v0.1.0 (/Users/allen/Projects/RustProjects/cxx-qt/examples/qml_features/rust)
[build] error: linking with /usr/bin/clang failed: exit status: 1
[build] |
[build] = note: env -u IPHONEOS_DEPLOYMENT_TARGET -u TVOS_DEPLOYMENT_TARGET LC_ALL=“C” PATH=“/Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Users/allen/.cargo/bin:/Users/allen/Library/Application Support/JetBrains/Toolbox/scripts:/Users/allen/Library/Python/3.9/bin” VSLANG=“1033” ZERO_AR_DATE=“1” “/usr/bin/clang” “-arch” “arm64” “/var/folders/hw/lc023pr55psdqktjg68xvnkw0000gn/T/rustc7cGQY5/symbols.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.10fl17pzfgknotu.rcgu.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.119okv1xmy7z81f6.rcgu.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.137xat5v19szbkn0.rcgu.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.15oph1vhrzhh5e5j.rcgu.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.19opgb164thgeyxk.rcgu.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.1vlp0hyqz47obvqu.rcgu.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.1yhg74qrm5jbn57.rcgu.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.26tes9igtz8fy7rn.rcgu.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.2mfoke3mrp14psgs.rcgu.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.2xsado67lvou67qs.rcgu.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.2zb7b71tju74uh5j.rcgu.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.37xis5uwom24c582.rcgu.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.3qh0u66rpovuphck.rcgu.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.4186phjz8kddzw0h.rcgu.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.42i2ewundsav9ojs.rcgu.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.45d9edr6wy3brpeh.rcgu.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.4aqs871owq9ftsf1.rcgu.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.4zbmzfjwshprgoiz.rcgu.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.4zm0s84o8zrdyxpo.rcgu.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.55605lsdx0j8mjk3.rcgu.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.55mmkitcjyl348i7.rcgu.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.5663x8hp4g2zm7jf.rcgu.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.59c517g8ydpmusil.rcgu.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.xhcy1h0fk613fhe.rcgu.o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7.4qr33kompxeqtcjw.rcgu.o” “-L” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/deps” “-L” “/opt/homebrew/Cellar/qt@5/5.15.12_1/lib” “-L” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-cd4fe937a4be2c39/out” “-L” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-201f66f53e1e6176/out” “-L” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/link-cplusplus-71603c78c2dde3e1/out” “-L” “/Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libcxx_qt_lib_headers-d9912cca892c1c19.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libcxx_qt_build-6ab1336d900c684d.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libversion_check-9f51aa7577df62b5.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libcxx_qt-d2c539d1a4753f86.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libstatic_assertions-21ebe0eb3cea606d.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libcxx-0dae514a5f69b4e8.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/liblink_cplusplus-29d675dabc421268.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libqt_build_utils-906dd61ff2dbfcbc.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libversions-8466793749c2eea6.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libnom-718756c2487eced8.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libmemchr-e6b5ebc697c65687.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libitertools-e621136652a36976.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libeither-f70f4bfdd6077160.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libcc-4f7e5addbf99ef3e.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libjobserver-dd4b614b2cf16aea.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/liblibc-dd2450870a8e46be.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libcxx_gen-5eee1925fa27fac5.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libcxx_qt_gen-8d441a361f4b6960.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libclang_format-089b44882994e1ab.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libthiserror-dd35499ccfe2017d.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libconvert_case-35c30cdcabc87c2a.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libunicode_segmentation-7d3ed2ca008d237f.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libsyn-ac3b92559e3bce53.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libquote-f7d359d29bfc9b4a.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libcodespan_reporting-16803727eb35ee92.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libunicode_width-16a1984432142341.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libtermcolor-3d23a97142594491.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libproc_macro2-950e5ceb51725b27.rlib” “/Users/allen/Projects/RustProjects/cxx-qt/build/cargo/build/debug/deps/libunicode_ident-2260bb06186abcf3.rlib” “/Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libproc_macro-c7150b0669ad7a0f.rlib” “/Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd-4f192af08beaa759.rlib” “/Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libpanic_unwind-401344856f0fc3c5.rlib” “/Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libobject-9e012890a70780c2.rlib” “/Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libmemchr-60338fe528589910.rlib” “/Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libaddr2line-a2e883cf5bcf6347.rlib” “/Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libgimli-df8440ef641907f8.rlib” “/Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_demangle-fa2288bf7728f91c.rlib” “/Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libstd_detect-f39c850853dd7dfe.rlib” “/Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libhashbrown-c5b1930e10569ddd.rlib” “/Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_alloc-96bad2fc8f58f610.rlib” “/Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libminiz_oxide-06eec439eca0e252.rlib” “/Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libadler-023007819562a373.rlib” “/Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libunwind-7254491d238c3b3e.rlib” “/Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcfg_if-9f474e4309122405.rlib” “/Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liblibc-0bfd536a501ea558.rlib” “/Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/liballoc-d56621fef414e9f8.rlib” “/Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_core-60d6843fd08e9533.rlib” “/Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcore-62a9b4d83244cb2b.rlib” “/Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-4010f8e9d1f7f9aa.rlib” “-framework” “QtCore” “-framework” “DiskArbitration” “-framework” “IOKit” “-lc++” “-liconv” “-lSystem” “-lc” “-lm” “-L” “/Users/allen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib” “-o” “/Users/allen/Projects/RustProjects/cxx-qt/build/./cargo/build/debug/build/cxx-qt-lib-6020208f1a041cc7/build_script_build-6020208f1a041cc7” “-Wl,-dead_strip” “-nodefaultlibs”
[build] = note: ld: framework ‘QtCore’ not found
[build] clang: error: linker command failed with exit code 1 (use -v to see invocation)
[build]
[build]
[build] error: linking with /usr/bin/clang failed: exit status: 1
[build] |

开始处理问题

1 看日志找关键点

首先查看日志数据,发现

“-L” “/opt/homebrew/Cellar/qt@5/5.15.12_1/lib”

说明CMake已经找到了qt的lib目录,查看对应目录的内容,

tree -L 1 /opt/homebrew/Cellar/qt@5/5.15.12_1/lib | grep QtCore
output:
QtCore.framework

发现有对应的库,但是库是framework结构,而不是.a 或.lib等结构。

再看编译命令:

“-framework” “QtCore” “-framework” “DiskArbitration” “-framework” “IOKit”

发现已经添加了-framework标记来链接这个库,按理说应该可以找到这个库。

2 写最简单测试用例

写一个最简单的my_demo.cpp

#include <iostream>
#include <QtCore/qobject.h>int main(int argc,char** argv)
{QObject* obj = new QObject();obj->setObjectName("obj");std::cout<<"Hello world !"<<std::endl;return 0;
}

my_demo.cpp

从上面的clang命令中提取关键编译信息,
执行如下命令进行编译这个项目:

/usr/bin/clang -arch arm64 -o my_demo my_demo.cpp
-L/opt/homebrew/Cellar/qt@5/5.15.12_1/lib
-framework QtCore -framework DiskArbitration -framework IOKit
-lc++

output:

// fatal error: ‘QtCore/qobject.h’ file not found

发现确实有这个问题,但是明明指定了链接的目录-L 也指定了链接的库 -framework
那么为什么不行呢?

3 写最简单CMake编译的Qt

通过QtCreator创建一个CMkae管理的Qt项目,然后进行编译,查看build目录下的compile_commands.json
查看具体执行的编译命令。

4 发现问题

最后发现,可以编译通过的Qt项目,

-iframework /Users/allen/Soft/Qt/6.5.3/macos/lib

他们指定目录时用的是-iframework 参数,而不是-L。
查看clang手册,

-iframework
Add directory to SYSTEM framework search path

发现-iframework和-L确实不一样,-iframework是mac平台下专门为了查找framework指定目录的一个参数,需要用-iframework指定framework的所在目录,然后使用-framework才能链接到这个库。

继续翻,发现

-F
Add directory to framework include search path

就是说俩有点区别,但都是用来指定framework目录的,用my_demo 发现都可以编译通过。

5 开始处理错误

已经找到了错误问题,开始着手处理问题。
回头查看日志,发现报错是在

[build] Compiling qml-features v0.1.0 (/Users/allen/Projects/RustProjects/cxx-qt/examples/qml_features/rust)

进入对应的CMakeLists.txt文件,找一下对应的地方:

set(CRATE qml-features)
corrosion_import_crate(MANIFEST_PATH rust/Cargo.toml CRATES ${CRATE})
set(CXXQT_EXPORT_DIR "${CMAKE_CURRENT_BINARY_DIR}/cxxqt")
corrosion_set_env_vars(${CRATE}"CXXQT_EXPORT_DIR=${CXXQT_EXPORT_DIR}""QMAKE=${QMAKE}"$<$<BOOL:${CMAKE_RUSTC_WRAPPER}>:RUSTC_WRAPPER=${CMAKE_RUSTC_WRAPPER}>
)

发现这里通过使用CMake的函数corrosion_import_crate 将rust的Cargo.toml导入进去,应该是这里处理的rust项目。

进入corrosion库目录,查看对应的函数、文档,发现了很多接口,如下是我试验的一些过程:

过程 1

CMakeLists.txt的改动
结果是不生效。
对于实际执行的clang命令没有任何改变!

过程2

rustflags = ["-C", "link-arg=-F/opt/homebrew/Cellar/qt@5/5.15.12_1/lib"]

在根目录增加.cargo/config文件,添加上述内容。

结果是不生效。
对于实际执行的clang命令没有任何改变!

过程3

qml-feature/rust/build.rs
在这里qml-feature/rust/build.rs
增加rust的编译内容。
结果是不生效。
对于实际执行的clang命令没有任何改变!

反思

当天搞到了晚上一点多,虽然找到了问题,但是却怎么弄都不行,睡了一觉第二天回想一下这个问题,发现自己有这么几点没搞明白:
1 为什么cmake不会改变clang的执行命令?
2 cmake是如何调用了rust的编译器,又是如何调用到最后的clang命令的?

开始找资料,解决自己的困惑。

通过查看corrosion这个库的函数,发现CMake最后通过run_custom_command的方式,调用了cargo , 然后cargo调用rustc 然后调用了clang。我去,给我整郁闷了。

第二次开始解决问题

打开对应的corrosion库,在里面的多个地方增加对应的函数,尝试编译。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
发现都没有效果😭

第三次解决问题

为什么就是不能用呢?
去cargo 官方搜索文档,
google

cargo link framework

发现buildscript中有这么一个参数:

cargo:rustc-link-search=[KIND=]PATH
The rustc-link-search instruction tells Cargo to pass the -L flag to the compiler to add a directory to the library search path.

The optional KIND may be one of dependency, crate, native, framework,
or all. See the rustc book for more detail.

These paths are also added to the dynamic library search path
environment variable if they are within the OUT_DIR. Depending on this
behavior is discouraged since this makes it difficult to use the
resulting binary. In general, it is best to avoid creating dynamic
libraries in a build script (using existing system libraries is fine).

Ok,找到这个参数了,剩下的就是怎么给他放进去了。

其中的过程不赘述了,
在crates/cxx-qt的build.rs中
加入

println!("cargo:rustc-link-search=framework=/opt/homebrew/Cellar/qt@5/5.15.12_1/lib");

最后编译即可正常。但是这个不是最好的办法,最好应该是让他自动解决这个符号。
后续再说吧,搞了四天才搞定这个麻烦问题。

总结

没事少碰还不是很完善的东西。
我指的是QML和rust互操作。Rust还是很好用的。

这篇关于记录一次难搞的编译错误-- qml-rust 项目编译无法找到QtCore库的问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/814505

相关文章

Redis连接失败:客户端IP不在白名单中的问题分析与解决方案

《Redis连接失败:客户端IP不在白名单中的问题分析与解决方案》在现代分布式系统中,Redis作为一种高性能的内存数据库,被广泛应用于缓存、消息队列、会话存储等场景,然而,在实际使用过程中,我们可能... 目录一、问题背景二、错误分析1. 错误信息解读2. 根本原因三、解决方案1. 将客户端IP添加到Re

详谈redis跟数据库的数据同步问题

《详谈redis跟数据库的数据同步问题》文章讨论了在Redis和数据库数据一致性问题上的解决方案,主要比较了先更新Redis缓存再更新数据库和先更新数据库再更新Redis缓存两种方案,文章指出,删除R... 目录一、Redis 数据库数据一致性的解决方案1.1、更新Redis缓存、删除Redis缓存的区别二

oracle数据库索引失效的问题及解决

《oracle数据库索引失效的问题及解决》本文总结了在Oracle数据库中索引失效的一些常见场景,包括使用isnull、isnotnull、!=、、、函数处理、like前置%查询以及范围索引和等值索引... 目录oracle数据库索引失效问题场景环境索引失效情况及验证结论一结论二结论三结论四结论五总结ora

element-ui下拉输入框+resetFields无法回显的问题解决

《element-ui下拉输入框+resetFields无法回显的问题解决》本文主要介绍了在使用ElementUI的下拉输入框时,点击重置按钮后输入框无法回显数据的问题,具有一定的参考价值,感兴趣的... 目录描述原因问题重现解决方案方法一方法二总结描述第一次进入页面,不做任何操作,点击重置按钮,再进行下

解决mybatis-plus-boot-starter与mybatis-spring-boot-starter的错误问题

《解决mybatis-plus-boot-starter与mybatis-spring-boot-starter的错误问题》本文主要讲述了在使用MyBatis和MyBatis-Plus时遇到的绑定异常... 目录myBATis-plus-boot-starpythonter与mybatis-spring-b

javafx 如何将项目打包为 Windows 的可执行文件exe

《javafx如何将项目打包为Windows的可执行文件exe》文章介绍了三种将JavaFX项目打包为.exe文件的方法:方法1使用jpackage(适用于JDK14及以上版本),方法2使用La... 目录方法 1:使用 jpackage(适用于 JDK 14 及更高版本)方法 2:使用 Launch4j(

Docker集成CI/CD的项目实践

《Docker集成CI/CD的项目实践》本文主要介绍了Docker集成CI/CD的项目实践,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学... 目录一、引言1.1 什么是 CI/CD?1.2 docker 在 CI/CD 中的作用二、Docke

SpringBoot项目引入token设置方式

《SpringBoot项目引入token设置方式》本文详细介绍了JWT(JSONWebToken)的基本概念、结构、应用场景以及工作原理,通过动手实践,展示了如何在SpringBoot项目中实现JWT... 目录一. 先了解熟悉JWT(jsON Web Token)1. JSON Web Token是什么鬼

Rust中的Option枚举快速入门教程

《Rust中的Option枚举快速入门教程》Rust中的Option枚举用于表示可能不存在的值,提供了多种方法来处理这些值,避免了空指针异常,文章介绍了Option的定义、常见方法、使用场景以及注意事... 目录引言Option介绍Option的常见方法Option使用场景场景一:函数返回可能不存在的值场景

Servlet中配置和使用过滤器的步骤记录

《Servlet中配置和使用过滤器的步骤记录》:本文主要介绍在Servlet中配置和使用过滤器的方法,包括创建过滤器类、配置过滤器以及在Web应用中使用过滤器等步骤,文中通过代码介绍的非常详细,需... 目录创建过滤器类配置过滤器使用过滤器总结在Servlet中配置和使用过滤器主要包括创建过滤器类、配置过滤