qbs dylib: library not loaded, image not found - c++

I'm trying to build a qbs project using the leap motion library but on running the project am given the following error:
dyld: Library not loaded: #loader_path/libLeap.dylib
Referenced from: /Users/pball/Work/Code/Qt/build-LeapTest-Desktop-Debug/qtc_Desktop_95cbad6a-debug/install-root/LeapTest
Reason: image not found
My qbs file:
import qbs
CppApplication {
consoleApplication: true
files: "main.cpp"
Group { // Properties for the produced executable
fileTagsFilter: product.type
qbs.install: true
}
cpp.includePaths: [".","/Users/pball/LeapSDK/include"]
cpp.libraryPaths: ["/Users/pball/LeapSDK/lib"]
cpp.dynamicLibraries: "Leap"
}
libLeap.dylib is in that location.
Using Qt 5.6.0
New to using qbs so any help / pointers greatly appreciated.

This is not a qbs-specific issue, but rather requires understanding of how dynamic libraries are loaded on macOS. Please check the documentation on dyld and Run-Path Dependent Libraries.
That said, based on the install name of your dependent shared library libLeap.dylib, if you copy it to the same directory as your LeapTest application binary, it should be loaded successfully.

Related

Error while deploying Qt5.10 App on linux

I'm trying to deploy a simple example on linux manually.
I copied the dependecies required by running
ldd ./binaryFile
inside the app directory
├── app.sh
├── lib
└── testApp
inside the lib directory I have
├──lib
├── plugins
├── qml
└── other .so files from ldd
and then I run the bash script
#!/bin/sh
export LD_LIBRARY_PATH=`pwd`/lib
export QML_IMPORT_PATH=`pwd`/lib/qml
export QML2_IMPORT_PATH=`pwd`/lib/qml
export QT_QPA_PLATFORM_PLUGIN_PATH=`pwd`/lib/plugins/platforms
#export QT_DEBUG_PLUGINS=0
./testApp
but I get this error
This application failed to start because it could not find or load the Qt platform plugin "xcb" in "/home/zed/Desktop/testDep/lib/plugins/platforms".
Available platform plugins are: eglfs (from /home/zed/Desktop/testDep/lib/plugins/platforms), linuxfb (from /home/zed/Desktop/testDep/lib/plugins/platforms), minimal (from /home/zed/Desktop/testDep/lib/plugins/platforms), minimalegl (from /home/zed/Desktop/testDep/lib/plugins/platforms), offscreen (from /home/zed/Desktop/testDep/lib/plugins/platforms), vnc (from /home/zed/Desktop/testDep/lib/plugins/platforms), webgl (from /home/zed/Desktop/testDep/lib/plugins/platforms), xcb (from /home/zed/Desktop/testDep/lib/plugins/platforms).
Reinstalling the application may fix this problem. ./app.sh: line 7: 1948 Aborted (core dumped) ./testApp
Even though the "xcb" plugin is inside the platforms directory
when I run it using
export QT_DEBUG_PLUGINS=1
I get this debug message
Got keys from plugin meta data ("xcb") QFactoryLoader::QFactoryLoader() checking directory path "/home/zed/Desktop/testDep" ... QFactoryLoader::QFactoryLoader() looking at "/home/zed/Desktop/testDep/app.sh" QElfParser: '/home/zed/Desktop/testDep/app.sh' is not an ELF object "'/home/zed/Desktop/testDep/app.sh' is not an ELF object"
not a plugin QFactoryLoader::QFactoryLoader() looking at "/home/zed/Desktop/testDep/testApp" "Failed to extract plugin meta data from '/home/zed/Desktop/testDep/testApp'"
not a plugin Cannot load library /home/zed/Desktop/testDep/lib/plugins/platforms/libqxcb.so: (/usr/lib/libQt5XcbQpa.so.5: symbol
_ZNK15QPlatformWindow15safeAreaMarginsEv version Qt_5_PRIVATE_API not defined in file libQt5Gui.so.5 with link time reference) QLibraryPrivate::loadPlugin failed on "/home/zed/Desktop/testDep/lib/plugins/platforms/libqxcb.so" : "Cannot load library /home/zed/Desktop/testDep/lib/plugins/platforms/libqxcb.so: (/usr/lib/libQt5XcbQpa.so.5: symbol
_ZNK15QPlatformWindow15safeAreaMarginsEv version Qt_5_PRIVATE_API not defined in file libQt5Gui.so.5 with link time reference)" QFactoryLoader::QFactoryLoader() checking directory path "/home/zed/Desktop/testDep/lib/plugins/platforms/platforms" ... QFactoryLoader::QFactoryLoader() checking directory path "/home/zed/Desktop/testDep/platforms" ... This application failed to start because it could not find or load the Qt platform plugin "xcb" in "/home/zed/Desktop/testDep/lib/plugins/platforms".
Is there a way to fix this ?
PS:
Qt Version : 5.10
Compiled on : Kubuntu 18.4
Tested on : Manjaro XFCE 17.1
It appears that there's a mismatch between Qt Versions used on both machines
/home/zed/Desktop/testDep/lib/plugins/platforms/libqxcb.so: (/usr/lib/libQt5XcbQpa.so.5:
It was looking for that file in the OS libs not the libs I provided, I copied the required files from Kubuntu machine to the lib directory deployment machine and that fixed the issue

Error "/usr/bin/ld: cannot find library: File format not recognized" when application is built as part of a collection of products

I have a QBS Project which is a collection of subprojects, including static libraries, shared libraries, and a Qt GUI applications. The Qt GUI application has been giving me issue in that the linking stage fails, throwing several "/usr/bin/ld: cannot find {library}: File format not recognized" errors for libraries that are built earlier in the project chain. It does not do this for all libraries though, including libraries with near identical .qbs files as those which do throw this error.
Oddly enough, if I build the application on it's own, that is to say I run qbs from within the application's project directory rather than at the top level, it builds fine (assuming the dependent libraries all exist within their install directories). The main difference I see is that when building the full project, the cpp.libraryPaths for the application are ignored for all products in the project and the application attempts to link against the lib files produced in the build directory, while when building the application on it's own the cpp.libraryPaths are used as intended, and the files in the install directory are linked against successfully.
I have no idea why the lib files in the install directory can be linked against while files in the build directory throw errors. What could be causing the linking to fail in the first place? Additionally, how can I fix my project configuration so that I can build everything by calling qbs at the top level. Am I perhaps going about this in the wrong manner?
Here is the command I use to start the build:
qbs qbs.installRoot:. release
And a visual representation of the issue:
Poject <-- calling qbs here throws errors at linking application
|- LibraryOne
|- LibraryTwo
|- Application <-- calling qbs here works if libraries already built
And here is a very simplified reproduction of the relevent qbs files
-- SubOne.qbs and SubTwo --
// These are identical excluding the files
StaticLibrary {
name: // "One" or "Two"
files: [/*Files...*/]
Depends {
name: "Qt"
submodules: [/*core, etc...*/]
}
Depends { name: "cpp" }
// cpp depends and properties
Group {
fileTagsFilter: product.type
qbs.installDir: "lib"
qbs.install: true
}
}
-- App.qbs --
QtGuiApplication {
name: "App"
files: [/*Files...*/]
Depends { name: "One" } // I comment out these depends when building the Application on it's own
Depends { name: "Two" }
Depends { name: "cpp" }
cpp.includePaths: ["../One/include","..Two/include"]
cpp.libraryPaths: ["../lib"] // <-- Ignored during full project build
cpp.staticLibraries: ["One","Two"]
Group {
fileTagsFilter: product.type
qbs.installDir: "bin"
qbs.install: true
}
}
Never run qbs from a subdirectory. You should always run it on the top-level project file. In your root directory you should have a file like this:
// project.qbs
import qbs
Project {
// order doesn't matter here
references: [
"LibraryOne/SubOne.qbs",
"LibraryTwo/SubTwo.qbs",
"Application/App.qbs"
]
}
Secondly, you should not set the cpp.libraryPaths and cpp.staticLibraries in your application, as the Depends items which you have in your application, will already handle this (never comment them out).
Your cpp.includePaths properties should also not be set in the application, instead they should go into an Export item in each of your respective static libraries, like so:
StaticLibrary {
...
Export {
Depends { name: "cpp" }
cpp.includePaths: [product.sourceDirectory + "/include"]
}
...
}
Then run qbs -f project.qbs and everything should be built correctly.

Qt qbs project settings with library not found compile error

I am working on a project which has several levels. Personally, I am new to qbs and there are not many document and examples on the internal about qbs.
environment:
Qt5.6.1; Qt creator 4.01; Ubuntu 16.04; Qbs 1.5.1
Here is the hierarchy of the project. On the top level, it has project.qbs:
import qbs
import qbs.File
Project{
var binaries = [
"component1/component1.qbs",
"component2/component2.qbs",
"subpro/subpro.qbs", // <- 1. the project I am working on
"ourlib/ourlib.qbs", // <- 2. the library I am using
]
return binaries
}
The subpro.qbs is something like:
import qbs
Project {
name: subpro
references:[
"app1/app1.qbs"
"app2/app2.qbs"
"myapp/myapp.qbs" //<- 3. the application I am working on
]
}
The myapp.qbs is like:
import qbs
CppApplication{
type: "application"
name: "myapp"
Group{
name: "project-install"
fileTagsFilter: "application"
qbs.install: false
qbs.install: "bin"
}
Depends {name:"cpp"}
Depends {name:"blah1"}
Depends {name:"ourlib"}
cpp.libraryPaths:["path_of_lib3rdParty"] // 4. set the 3rd party lib path
cpp.staticLibraries:["lib3rdParty.a"] // 5. set the 3rd party lib name
files["myapp.cpp","f2"...]
}
finally the qbs for our lib:
import qbs
DynamicLibrary{
name: "ourlib"
Group{
name: "project-install"
fileTagsFilter: "dynamiclibrary"
qbs.install: false
qbs.installDir: "debug"
}
Depends {name: "cpp"}
cpp.includePath:["..."]
cpp.libraryPaths:["path_of_lib3rdParty"] // 6. same as 4
cpp.staticLibraries:["lib3rdParty.a"] // 7. same as 5
}
When I run "qbs debug" under the project root folder.
The qbs shows:
linking ourlib.so
compiling myapp.cpp
ERROR: ...
/usr/bin/ld: cannot find -llib3rdParty_s.a
So, based on the error message, the qbs failed to build myapp.cpp and trying to find the lib3rdParty in myapp project. I added 4 and 5, still having the same error. It seem 6 and 7 are correct since there is no linking error from ourlib.so. How should I config the qbs to make the building process working?
Another question is about the keyword "references". Can I reference other qbs file in any level in a project? How it work? I got the same question about "Depends" as well.
Thanks
Rong
The cpp.dynamicLibraries and cpp.staticLibraries properties take a list of library names to be linked, i.e. the library name without the lib prefix or .so suffix.
For example, you'd use:
cpp.libraryPaths: ["/home/r0ng/tools/myapp/libs/relic/lib"]
cpp.dynamicLibraries: ["relic"]
However, since you already have the full file path of the dynamic library you wish to link, you can simply pass the full file path without having to specify cpp.libraryPaths at all, like so:
cpp.dynamicLibraries: ["/home/r0ng/tools/myapp/libs/relic/lib/librelic.so"]
That second method is preferred because it specifies the exact library to link to, rather than relying on the search path which may not necessarily pick the type of library you expect (if both a static and dynamic version exist).
I concede that our cpp.dynamicLibraries and cpp.staticLibraries properties should be better documented to explain their intended use.
Regarding references, yes, you can reference any file path regardless of its file system location.
Regarding Depends, that item's name property specifies the name of a product or module to create a dependency on. Such a product or module must already be present in your project tree, for example having been loaded as a result of using the qbsSearchPaths or references properties.

Statically link framework to an Xcode command line tool

I am a mac user running 10.10.5 Yosemite and Xcode 6.3.2. In Documents there is a folder (generated by a command line tool project written in C++) called 'Game' with this structure:
Game:
Game.xcodeproj (my project)
Game:
main.cpp (my c++ source)
Build:
Products:
Debug:
Game (an executable)
SDL2.framework (a development library)
I want to link to the SDL2.framework in Build/Products/Debug in such a way that it will run on any Mac, from this specific folder.
I have performed these steps:
I dragged SDL2.framework from Build/Products/Debug into my Project Navigator. I unchecked 'copy if needed.'
This automatically added the 'Link Binary with Libraries' build phase in which SDL2.framework is included.
SDL2.framework is referenced relative to group- in 'Build/Products/Debug/SDL2.framework,' as desired.
In my main.cpp I write:
# include "SDL2/SDL.h"
The generated executable runs on my machine no matter where the 'Game' folder highest in the hierarchy is.
My project is not referencing the SDL2.framework in /Library/Frameworks. I can change the name of the SDL2.framework there and the program still runs. This suggests it is taking it from /Build/Products/Debug as I want it to.
However, when I take this whole folder onto a mac identical to mine the executable runs, but fails with this error:
Last login: Sat Mar 26 11:32:08 on ttys002
[~/ 1> /Volumes/NO\ NAME/Game/Build/Products/Debug/Game ; exit;
dyld: Library not loaded: #rpath/SDL2.framework/Versions/A/SDL2
Referenced from: /Volumes/NO NAME/Game/Build/Products/Debug/Game
Reason: image not found
Trace/BPT trap
logout
[Process completed]
Having spent hours searching for a solution, I am dumbfounded. What am I doing wrong?

dyld: Library not loaded: lib/libopencv_core.3.0.dylib Reason: image not found

I am getting the following issue:
/Users/luke/Desktop/trainHOG/trainhog ; exit;
dyld: Library not loaded: lib/libopencv_core.3.0.dylib
Referenced from: /Users/luke/Desktop/trainHOG/trainhog
Reason: image not found
Trace/BPT trap: 5
logout
I am using a Mac running OSX v10.9.5 with openCV 3.0 alpha.
The library in question is definitely in the folder. I have tried deleting it and pasting it back into the folder, I have completely deleted and reinstalled openCV and macports, and I have tried the export DYLD_LIBRARY_PATH = "path to dynamic libs here..", but nothing has worked. I have even rebooted my computer on several occasions!
Does anyone have any further suggestions? I am out of ideas
OpenCV 3.3
OSX 10.13
fist have a test, you can use clang++ -o a -I ./include -L ./lib
-lopencv_core.your.version
then you can generate executable file a ,run it ,if have the error massage.
you will find the error reason cannot find the lib when you are link.
if you want to solve error on terminal
you can use export DYLD_LIBRARY_PATH=your/lib:$DYLD_LIBRARY_PATH
if you want to solve error on Xcode
in build page , go to "Runpath Search Paths"
add you lib path
If you use
export DYLD_LIBRARY_PATH = "path to dynamic libs here.."
is it applied to the environment of your program?
You can check the environment variables of a running process with
ps -p <pid> -wwwE
Does this help?
If you are having this Problem:
dyld: Library not loaded: *.dylib ... Reason: no suitable image found.
Means your *.dylib files are not signed with your Apple iD develop account, and
There is two ways to solve that:
1) The right way: Code sign all your files with errors with this command:
codesign -f -s "Mac Developer: YOURDEVELOPEREMAIL" /usr/local/opt/*/lib/*.dylib
2) The temporary way(until you don't deploy to App Store): Inside Xcode, go to:
[YourProjectFile] --> [YourTargetFile] --> "Signing & Capabilities" --> and Enable "Disable Library Validation"
Done :D
Seems to be a bug in some versions of OpenCV's CMake configuration files which incorrectly record relative paths in the installed dylibs, reasonably easy to fix.
This answer on answers.opencv.org addresses the issue. In OpenCVModule.cmake and every instance of CMakeLists.txt replace INSTALL_NAME_DIR lib with INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib.