examples icon indicating copy to clipboard operation
examples copied to clipboard

success compiled, but can load the qt library.

Open tauruswang opened this issue 5 years ago • 9 comments

(base) JerryWs-MacBook-Pro:examples jerryw$ cargo build
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s
(base) JerryWs-MacBook-Pro:examples jerryw$ cargo run --bin form1
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s
     Running `target/debug/form1`
dyld: Library not loaded: @rpath/libQt5Widgets.5.dylib
  Referenced from: /Users/jerryw/MyCode/StudyRust/examples/target/debug/form1
  Reason: image not found
Abort trap: 6
(base) JerryWs-MacBook-Pro:examples jerryw$  otool -L /Users/jerryw/MyCode/StudyRust/examples/target/debug/form1
/Users/jerryw/MyCode/StudyRust/examples/target/debug/form1:
        @rpath/libQt5Widgets.5.dylib (compatibility version 5.12.0, current version 5.12.5)
        @rpath/libQt5Core.5.dylib (compatibility version 5.12.0, current version 5.12.5)
        @rpath/libQt5Gui.5.dylib (compatibility version 5.12.0, current version 5.12.5)
        @rpath/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.0.0)
        /usr/lib/libresolv.9.dylib (compatibility version 1.0.0, current version 1.0.0)
(base) JerryWs-MacBook-Pro:examples jerryw$ 

and I also export DYLD_LIBRARY_PATH=/usr/local/Qt-5.14.0/lib/ to spepcify the QT library path.

by the way, Does my Qt install incorrect on Mac OS 10.15.3? ** I installed QT, but None of dylib (mybe libQt5Widgets.5.dylib) files found in lib path.

in directory there are frameworks , ls /usr/local/Qt-5.14.0/lib/

Qt3DAnimation.framework QtTextToSpeech.framework libQt5GraphicsSupport_debug.prl Qt3DCore.framework QtUiPlugin.framework libQt5OpenGLExtensions.a Qt3DExtras.framework QtVirtualKeyboard.framework libQt5OpenGLExtensions.la Qt3DInput.framework QtWebChannel.framework libQt5OpenGLExtensions.prl Qt3DLogic.framework QtWebEngine.framework libQt5OpenGLExtensions_debug.a Qt3DQuick.framework QtWebEngineCore.framework libQt5OpenGLExtensions_debug.la Qt3DQuickAnimation.framework QtWebEngineWidgets.framework libQt5OpenGLExtensions_debug.prl Qt3DQuickExtras.framework QtWebSockets.framework libQt5PacketProtocol.a Qt3DQuickInput.framework QtWebView.framework libQt5PacketProtocol.la Qt3DQuickRender.framework QtWidgets.framework libQt5PacketProtocol.prl Qt3DQuickScene2D.framework QtXml.framework libQt5PacketProtocol_debug.a Qt3DRender.framework QtXmlPatterns.framework libQt5PacketProtocol_debug.la QtBluetooth.framework cmake libQt5PacketProtocol_debug.prl QtBodymovin.framework libQt5AccessibilitySupport.a libQt5PlatformCompositorSupport.a QtCharts.framework libQt5AccessibilitySupport.la libQt5PlatformCompositorSupport.la QtConcurrent.framework libQt5AccessibilitySupport.prl libQt5PlatformCompositorSupport.prl QtCore.framework libQt5AccessibilitySupport_debug.a libQt5PlatformCompositorSupport_debug.a QtDBus.framework libQt5AccessibilitySupport_debug.la libQt5PlatformCompositorSupport_debug.la QtDataVisualization.framework libQt5AccessibilitySupport_debug.prl libQt5PlatformCompositorSupport_debug.prl QtDesigner.framework libQt5Bootstrap.a libQt5QmlDebug.a QtDesignerComponents.framework libQt5Bootstrap.la libQt5QmlDebug.la QtGamepad.framework libQt5Bootstrap.prl libQt5QmlDebug.prl QtGui.framework libQt5ClipboardSupport.a libQt5QmlDebug_debug.a QtHelp.framework libQt5ClipboardSupport.la libQt5QmlDebug_debug.la QtLocation.framework libQt5ClipboardSupport.prl libQt5QmlDebug_debug.prl QtMacExtras.framework libQt5ClipboardSupport_debug.a libQt5QmlDevTools.a QtMultimedia.framework libQt5ClipboardSupport_debug.la libQt5QmlDevTools.la QtMultimediaQuick.framework libQt5ClipboardSupport_debug.prl libQt5QmlDevTools.prl QtMultimediaWidgets.framework libQt5DeviceDiscoverySupport.a libQt5ServiceSupport.a QtNetwork.framework libQt5DeviceDiscoverySupport.la libQt5ServiceSupport.la QtNetworkAuth.framework libQt5DeviceDiscoverySupport.prl libQt5ServiceSupport.prl QtNfc.framework libQt5DeviceDiscoverySupport_debug.a libQt5ServiceSupport_debug.a QtOpenGL.framework libQt5DeviceDiscoverySupport_debug.la libQt5ServiceSupport_debug.la QtPositioning.framework libQt5DeviceDiscoverySupport_debug.prl libQt5ServiceSupport_debug.prl QtPositioningQuick.framework libQt5EdidSupport.a libQt5ThemeSupport.a QtPrintSupport.framework libQt5EdidSupport.la libQt5ThemeSupport.la QtPurchasing.framework libQt5EdidSupport.prl libQt5ThemeSupport.prl QtQml.framework libQt5EdidSupport_debug.a libQt5ThemeSupport_debug.a QtQmlModels.framework libQt5EdidSupport_debug.la libQt5ThemeSupport_debug.la QtQmlWorkerScript.framework libQt5EdidSupport_debug.prl libQt5ThemeSupport_debug.prl QtQuick.framework libQt5EventDispatcherSupport.a libQt5UiTools.a QtQuick3D.framework libQt5EventDispatcherSupport.la libQt5UiTools.la QtQuick3DAssetImport.framework libQt5EventDispatcherSupport.prl libQt5UiTools.prl QtQuick3DRender.framework libQt5EventDispatcherSupport_debug.a libQt5UiTools_debug.a QtQuick3DRuntimeRender.framework libQt5EventDispatcherSupport_debug.la libQt5UiTools_debug.la QtQuick3DUtils.framework libQt5EventDispatcherSupport_debug.prl libQt5UiTools_debug.prl QtQuickControls2.framework libQt5FbSupport.a libQtRepParser.prl QtQuickParticles.framework libQt5FbSupport.la libQtRepParser_debug.prl QtQuickShapes.framework libQt5FbSupport.prl libQtUiPlugin.prl QtQuickTemplates2.framework libQt5FbSupport_debug.a libQtUiPlugin_debug.prl QtQuickTest.framework libQt5FbSupport_debug.la libQtWebEngineCore.prl QtQuickWidgets.framework libQt5FbSupport_debug.prl libQtWebEngineCore_debug.prl QtRemoteObjects.framework libQt5FontDatabaseSupport.a libqtfreetype.a QtRepParser.framework libQt5FontDatabaseSupport.la libqtfreetype.prl QtScript.framework libQt5FontDatabaseSupport.prl libqtfreetype_debug.a QtScriptTools.framework libQt5FontDatabaseSupport_debug.a libqtfreetype_debug.prl QtScxml.framework libQt5FontDatabaseSupport_debug.la libqtlibpng.a QtSensors.framework libQt5FontDatabaseSupport_debug.prl libqtlibpng.prl QtSerialBus.framework libQt5GraphicsSupport.a libqtlibpng_debug.a QtSerialPort.framework libQt5GraphicsSupport.la libqtlibpng_debug.prl QtSql.framework libQt5GraphicsSupport.prl pkgconfig QtSvg.framework libQt5GraphicsSupport_debug.a QtTest.framework libQt5GraphicsSupport_debug.la

tauruswang avatar Mar 16 '20 15:03 tauruswang

(base) JerryWs-MacBook-Pro:examples jerryw$
export DYLD_LIBRARY_PATH=/Users/jerryw/anaconda3/pkgs/qt-5.12.5-h1b46049_0/lib:/usr/local/Cellar/icu4c/64.2/lib

still can not find libs file properly

(base) JerryWs-MacBook-Pro:examples jerryw$ cargo run --bin form1 Finished dev [unoptimized + debuginfo] target(s) in 0.10s Running target/debug/form1 qt.qpa.plugin: Could not find the Qt platform plugin "cocoa" in "" This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Abort trap: 6 (base) JerryWs-MacBook-Pro:examples jerryw$ export QT_QPA_PLATFORM_PLUGIN_PATH=/Users/jerryw/anaconda3/pkgs/qt-5.12.5-h1b46049_0/p phrasebooks/ plugins/

(base) JerryWs-MacBook-Pro:examples jerryw$ cargo run --bin form1 Finished dev [unoptimized + debuginfo] target(s) in 0.17s Running target/debug/form1 😳

and finally works! 💆

I just luckily that anaconda have these QT dylib files. My question is Why Qt build from source can not have these dylib files, Do I need some special config for build QT for Mac OS ?

tauruswang avatar Mar 16 '20 16:03 tauruswang

Looks like the build script failed to detect that Qt is built in framework mode.

How did you build and install Qt? Is qmake corresponding to the installation added to the current PATH?

Please show output of these commands:

qmake -query
ls /usr/local/Qt-5.14.0/lib/QtWidgets.framework

Riateche avatar Mar 16 '20 16:03 Riateche

I build my Qt from the source code repository.
After make finished, I do the make install. It seems to install all the built output files to /usr/local/Qt-5.14.0/

Actually I run the qmake -query, it is output (base) JerryWs-MacBook-Pro:redox jerryw$ qmake -query QT_SYSROOT: QT_INSTALL_PREFIX:/Users/jerryw/anaconda3 QT_INSTALL_ARCHDATA:/Users/jerryw/anaconda3 QT_INSTALL_DATA:/Users/jerryw/anaconda3 QT_INSTALL_DOCS:/Users/jerryw/anaconda3/doc QT_INSTALL_HEADERS:/Users/jerryw/anaconda3/include/qt QT_INSTALL_LIBS:/Users/jerryw/anaconda3/lib QT_INSTALL_LIBEXECS:/Users/jerryw/anaconda3/libexec QT_INSTALL_BINS:/Users/jerryw/anaconda3/bin QT_INSTALL_TESTS:/Users/jerryw/anaconda3/tests QT_INSTALL_PLUGINS:/Users/jerryw/anaconda3/plugins QT_INSTALL_IMPORTS:/Users/jerryw/anaconda3/imports QT_INSTALL_QML:/Users/jerryw/anaconda3/qml QT_INSTALL_TRANSLATIONS:/Users/jerryw/anaconda3/translations QT_INSTALL_CONFIGURATION:/Users/jerryw/anaconda3 QT_INSTALL_EXAMPLES:/Users/jerryw/anaconda3/examples QT_INSTALL_DEMOS:/Users/jerryw/anaconda3/examples QT_HOST_PREFIX:/Users/jerryw/anaconda3 QT_HOST_DATA:/Users/jerryw/anaconda3 QT_HOST_BINS:/Users/jerryw/anaconda3/bin QT_HOST_LIBS:/Users/jerryw/anaconda3/lib QMAKE_SPEC:macx-clang QMAKE_XSPEC:macx-clang QMAKE_VERSION:3.1 QT_VERSION:5.12.5

And my build version is at /usr/local ls /usr/local/Qt-5.14.0/lib/QtWidgets.framework Headers QtWidgets QtWidgets_debug Resources Versions

I guess, the PATH environment lets qmake find Qt Library from Anaconda stuffs.

echo $PATH -bash: export: /Users/jerryw/anaconda3/bin:/Users/jerryw/anaconda3/condabin:/usr/local/opt/qt/bin:/Users/jerryw/.cargo/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/opt/local/bin:/opt/local/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware': not a valid identifier -bash: export: Fusion.app/Contents/Public:/opt/X11/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/jerryw/.rvm/bin:/Users/jerryw/Library/Android/sdk/tools:/Users/jerryw/Library/Android/sdk/platform-tools:/usr/local/opt/go/libexec/bin': not a valid identifier

and my PATH environment also looks not correct ...

tauruswang avatar Mar 18 '20 07:03 tauruswang

The qmake executable should point to the Qt installation you're trying to use. To achieve that, change your PATH variable:

export PATH=/usr/local/Qt-5.14.0/bin:$PATH

You should also set DYLD_FRAMEWORK_PATH to allow dyld to find the frameworks at runtime:

export DYLD_FRAMEWORK_PATH=/usr/local/Qt-5.14.0/lib:$DYLD_FRAMEWORK_PATH

Riateche avatar Mar 18 '20 12:03 Riateche

Yes, after I set these environment variables. export PATH=/usr/local/Qt-5.14.0/bin:$PATH export DYLD_FRAMEWORK_PATH=/usr/local/Qt-5.14.0/lib:$DYLD_FRAMEWORK_PATH but it still doesn't work, and said dyld: Library not loaded: @rpath/libQt5Widgets.5.dylib I just wondering, Do I need to recompile the Qt source code that makes sure these dylib files carry-out in DYLD_FRAMEWORK_PATH, then will works?

tauruswang avatar Mar 20 '20 07:03 tauruswang

Have you tried running cargo clean before building again with these environment variables?

Are you able to build and run C++ Qt projects (e.g. examples bundled with Qt) using this Qt build?

Riateche avatar Mar 21 '20 19:03 Riateche

dyld: Library not loaded: @rpath/libQt5Widgets.5.dylib

I just struggled with this same error for a few hours. I finally figured something out. Try this:

  • Create a file in your project .cargo/config
  • Put the following in there:
[build]
rustflags = ["-C", "link-args=-Wl,-rpath,/usr/local/Qt-5.14.0/lib"]

Make sure /usr/local/Qt-5.14.0/lib actually contains the Qt libs. I'm on Mac and my Qt libs are installed at /Users/nick/Qt/5.14.2/clang_64/lib

I can now do cargo run and import a Qt lib without error. Now onto the next step of actually trying to use it.

Nick011 avatar May 04 '20 02:05 Nick011

dyld: Library not loaded: @rpath/libQt5Widgets.5.dylib

I just struggled with this same error for a few hours. I finally figured something out. Try this:

  • Create a file in your project .cargo/config
  • Put the following in there:
[build]
rustflags = ["-C", "link-args=-Wl,-rpath,/usr/local/Qt-5.14.0/lib"]

Make sure /usr/local/Qt-5.14.0/lib actually contains the Qt libs. I'm on Mac and my Qt libs are installed at /Users/nick/Qt/5.14.2/clang_64/lib

I can now do cargo run and import a Qt lib without error. Now onto the next step of actually trying to use it.

Man, you have just saved me.

gavrilikhin-d avatar Jan 27 '24 15:01 gavrilikhin-d

Why rust even generates dependencies with @rpath? I had an issue with @rpath/libc++.1.dylib

gavrilikhin-d avatar Jan 27 '24 15:01 gavrilikhin-d