Calling MATLAB from C++ dyld: Library not loaded error - c++

I'm trying to run the following example found at http://www.box.net/shared/xmazi14uv2.
But when I make and try to run the executable, I encounter the following error:
./demo
dyld: Library not loaded: #rpath/libeng.dylib
I've had no success searching the web. I'm running MATLAB_R2014b on a MacBook Pro Air.

I don't use or even have access to a Mac, but I think you need to setup some environment variables when you run applications using the MATLAB Engine:
export PATH='/path/to/MATLAB_R2014b.app/bin':$PATH
export DYLD_LIBRARY_PATH='/path/to/MATLAB_R2014b.app/bin/maci64:/path/to/MATLAB_R2014b.app/sys/os/maci64':$DYLD_LIBRARY_PATH

Related

How to open Command Line application built from Xcode outside of Xcode?

I have a console application project which uses my own framework. When I build and run the application from Xcode it's executed successfully. However when I try to open the executable from terminal outside of Xcode I get the following error:
dyld: Library not loaded: #rpath/Logic.framework/Versions/A/Logic
Referenced from: /Users/semyon/Library/Developer/Xcode/DerivedData/VocalTrainer-fyzwymbxfxusrqejhssrjfeovnqg/Build/Products/Debug/./MvxGenerator
Reason: image not found
zsh: abort ./MvxGenerator
The question is: How to deliver the release build of my command line application which uses a framework?
You need to install the framework/ dynamic library at #executable_path/../Resources/lib folder. If you share a .app bundle, just copy it in Contents/MacOS/Resources/lib folder. If a binary, make sure your installer keeps the framework at the right place.
You may want to inspect other open source app bundles which do this:
Cmake
Visual Studio Code
etc

Loading a torchscript model in C++: Cannot initialize CUDA without ATen_cuda library

I have built a CNN with Pytorch with GPU support. It works fine in python and I would like to import it in my C++ application using VS2017. I am following these instructions here and here.I can build and run the application, but I get this error when loading the model:
error loading the model
Cannot initialize CUDA without ATen_cuda library. PyTorch splits its backend into two shared
libraries: a CPU library and a CUDA library; this error has occurred because you are trying to use
some CUDA functionality, but the CUDA library has not been loaded by the dynamic linker for some
reason. The CUDA library MUST be loaded, EVEN IF you don't directly use any symbols from the CUDA
library! One common culprit is a lack of -Wl,--no-as-needed in your link arguments; many dynamic
linkers will delete dynamic library dependencies if you don't depend on any of their symbols. You
can check if this has occurred by using ldd on your binary to see if there is a dependency on
*_cuda.so library. (initCUDA at
C:\w\1\s\windows\pytorch\aten\src\ATen/detail/CUDAHooksInterface.h:63)
(no backtrace available)
I cannot find any ATen_cuda file in the C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1.Has anyone a Windows C++ VS2017 Pytorch with GPU working sample?
I solved using the nightly build, that ships pytorch with all the needed cuda dlls.It looks like the conda installer for Windows does not install the latest pytorch stable 1.2 but an older 1.0.1. Nightly build for Windows conda python 3.7 installs a newer 1.3.

Qt5 cannot find platform plugins Mac OS X

I am trying to deploy a Qt program on Mac according to this link. After going through with otool -L on my executable and all of the libraries that it depends on, which I copied into the application bundle, I get this error in QtCreator's application output when I try to run it.
This application failed to start because it could not find or load the Qt platform plugin "cocoa".
Reinstalling the application may fix this problem.
The program has unexpectedly finished.
I've tried copying the qt platform plugins libqcocoa.dylib and changing the plugins directory in qt.conf, according to this, but it still fails.
Also worth pointing out, I first tried to use qt's macdeployqt tool, but it fails with this message, despite being the first time I run it on the executable:
ERROR: Could not find bundle binary for "MyProgram.app/Contents/MacOS/MyProgram"
ERROR: "otool: can't open file: (No such file or directory)"
WARNING:
WARNING: Could not find any external Qt frameworks to deploy in "MyProgram.app/Contents/MacOS/MyProgram"
WARNING: Perhaps macdeployqt was already used on "MyProgram.app/Contents/MacOS/MyProgram" ?
WARNING: If so, you will need to rebuild "MyProgram.app/Contents/MacOS/MyProgram" before trying again.
ERROR: Could not find bundle binary for "MyProgram.app/Contents/MacOS/MyProgram"
ERROR: file copy failed from "/Developer/Applications/Qt/plugins/platforms/libqcocoa.dylib"
ERROR: to "MyProgram.app/Contents/MacOS/MyProgram/Contents/PlugIns/platforms/libqcocoa.dylib"
ERROR: file copy failed from "/Developer/Applications/Qt/plugins/printsupport/libcocoaprintersupport.dylib"
ERROR: to "MyProgram.app/Contents/MacOS/GraphiteMiniEditor/Contents/PlugIns/printsupport/libcocoaprintersupport.dylib"
Re macdeployqt fails: it seems like, for the argument to macdeployqt you are passing the path to the executable instead of the path to the bundle. I.e. just pass .../MyProgram.app instead of .../MyProgram.app/Contents/MacOS/MyProgram.
(But I am also unable to get it find libqcocoa, in a sandboxed app. I may resort to linking that statically into my app.)
To give Kamil Klimek's solution some more attention (It solved the problem for me):
I had the same problem when I installed QtCreator (Qt 5.x) with the offline installer, but apparently also had Qt (4.x) installed through Homebrew (probably pulled in as a dependency). Compiling the code with 5.x, and deploying it with the 4.x macdeployqt script doesn't work.
So, make sure that e.g.:
which macdeployqt
calls macdeployqt from the same Qt version / path used to compile the code.
I had this error with OS X Lion, using Qt 5.4.2. When I installed the Xcode command line utilities, then the error went away and macdeployqt worked.

Lua C++ development files on Linux (/usr/bin/ld: cannot find -llua5.1)

I am building a C++ application that embeds the Lua scripting engine. I am developing on Linux (Ubuntu).
I have already installed Lua on my dev machine (by imstalling the lua5.1 package). I can run the Lua intepreter succesfully (via the cmd line).
However, when building, I get the following link error:
/usr/bin/ld: cannot find -llua5.1
I have searched the Ubuntu forums/package repositories etc but I cannot seem to find the required package. Can anyone help?
PS: I also need to install the development files for tolua++ (I'm not sure which Ubuntu package is the required one either).
I am on Ubuntu 10.0.4
Install the liblua5.1-dev package, and if that does not work compile Lua from sources.
Or you can try -llua instead of -llua5.1.
on Fedora 17 problem fixed:
sudo ln /usr/lib/liblua-5.1.so /usr/lib/liblua5.1.so
For tolua++, it looks like libtolua++5.1-dev is the package you want.

Running in the Terminal a build made in XCode, how?

Im creating a project in Xcode using OpenCV as a framework. It works great with the Build&Run option from Xcode, but now I need to run it in the Terminal and it gives me this error:
dyld: Library not loaded: #executable_path/../Frameworks/OpenCV.framework/Versions/A/OpenCV
Referenced from: /Users/Victor/Documents/PFC/src/opencv/blob/build/Release/./test3
Reason: image not found
Trace/BPT trap
I look for the build and just execute it with ./
So, any clue?
You need to run it from the build directory rather than the Release directory (assuming Frameworks is a directory in blob)