pyinstaller Adafruit DHT library raspberry_Pi_Driver.so: cannot open shared object - raspberry-pi

I'm using Adafruit_DHT library in a file and when I try to use pyinstaller to compile, I get an error that Raspberry_Pi_Driver.so: cannot open shared object file
I'm using normal RPi (not model 2) and raspbian. The file that I'm trying to compile works by itself fine. The Raspberry_Pi_Driver.so is there I did find ./ | grep Raspberry_Pi_Driver.so and it existed. I tried also to use the --hidden-import=Adafruit_DHT when compiling the pyinsatller and that did not work too. When compiling it does not give any error.
I noticed after compilation and in the build folder thee is an Adafruit_DHT folder that has the driver and etc.
Any idea what's going on? Could it be that the library has been recreated under build folder and this is confusing when executing the file?

I found a resolution for this (thanks to: k4ml.me/posts/pyinstaller.html) I just added '-p /path/to/mylib' when creating the exe file and mylib was the directory that Adafruit_DHT folder was (that Adafruit_DHT_Driver.so file was there).

Related

Distributing pybind11 extension linked to third party libraries

I'm working on a pybind11 extension written in C++ but I'm having a hard time understanding how should it be distributed.
The project links to a number of third party libraries (e.g. libpng, glew etc.).
The project builds fine with CMAKE and it generates a .so file. Now I am not sure what is the right way of installing this extension. The extension seems to work, as if I try copy the file into the python lib directories it is picked up (I can import it, and it works correctly). However, this is clearly not the way to go I think.
I also tried the setuptools route (from https://pybind11.readthedocs.io/en/stable/compiling.html) by creating a setup.py files like this:
import sys
# Available at setup time due to pyproject.toml
from pybind11 import get_cmake_dir
from pybind11.setup_helpers import Pybind11Extension, build_ext
from setuptools import setup
from glob import glob
files = sorted(glob("*.cpp"))
__version__ = "0.0.1"
ext_modules = [
Pybind11Extension("mylib",
files,
# Example: passing in the version to the compiled code
define_macros = [('VERSION_INFO', __version__)],
),
]
setup(
name="mylib",
version=__version__,
author="fab",
author_email="fab#fab",
url="https://github.com/pybind/python_example",
description="mylib",
long_description="",
ext_modules=ext_modules,
extras_require={"test": "pytest"},
cmdclass={"build_ext": build_ext},
zip_safe=False,
python_requires=">=3.7",
)
and now I can build the extension by simply calling
pip3 install
however it looks like all the links are broken because whenever I try importing the extension in Python I get linkage errors, as if setuptools does not link correctly the extension with the 3rd party libs. For instance errors in linking with libpng as in:
>>> import mylib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /home/fabrizio/.local/lib/python3.8/site-packages/mylib.cpython-38-x86_64-linux-gnu.so: undefined symbol: png_sig_cmp
However I have no clue how to add this link info to setuptools, and don't even know if that's possible (it should be the setuptools equivalent of CMAKE's target_link_libraries).
I am really at a loss after weeks of reading documentation, forum threads and failed attempts. If anyone is able to point me in the right way or to clear some of the fog it would be really appreciated!
Thanks!
Fab
/home/fabrizio/.local/lib/python3.8/site-packages/mylib.cpython-38-x86_64-linux-gnu.so: undefined symbol: png_sig_cmp
This line pretty much says it clearly. Your local shared object file .so can't find the libpng.so against which it is linked.
You can confirm this by running:
ldd /home/fabrizio/.local/lib/python3.8/site-packages/mylib.cpython-38-x86_64-linux-gnu.so
There is no equivalent of target_link_libraries() in setuptools. Because that wouldn't make any sense. The library is already built and you've already linked it. This is your system more or less telling you that it can't find the libraries it needs. And those most likely need to be installed.
This is also one of the reasons why Linux distributions provide their own package managers and why you should use the developer packages provided by said distributions.
So how do you fix this? Well your .so file needs to find the other .so files against which you linked to understand how this works I will refer you to this link.
My main guess is based on the fact that when you manually copy the files it works - That during the build process you probably specify the rpath to a local directory. Hence what you most likely need to do is specify to your setuptools that it needs to copy those files when installing.

How to let IDE know a certain folder should be mapped into a certain package path?

I use PyCharm and Eclipse with PyDev.
To be specific, I am using Odoo and setting up project.
https://github.com/odoo/odoo
Here is the folder structure.
odoo-12
|-addons
| '-web
| '-...
|-odoo
'-addons
'-...
In source code for example:
addons/purchase/controllers/portal.py
# Unresolved yet this is the official source code
from odoo.addons.web.controllers.main import Binary
# Resolved perfectly
from addons.web.controllers.main import Binary
I understand the reason why this one works
from addons.web.controllers.main import Binary
but how can I make this works instead?
from odoo.addons.web.controllers.main import Binary
I cannot and should not modify any Odoo source code to make IDE resolving path correctly
In Eclipse/PyDev you should be able to set your source folder to the folder containing odoo and it should work...

How to build Qtkeychain with Windows?

I'm trying to build my OwnCloud client. I'm using "Generic Build Instructions" from this link - https://doc.owncloud.org/desktop/2.5/building.html.
I'm stuck at 3 step with an error:
Could NOT find Qt5Keychain (missing: QTKEYCHAIN_LIBRARY)
I downloaded Qtkeychain and compiled it using this link - https://github.com/frankosterfeld/qtkeychain/wiki.
Everything is in my C disk. PATHS are set correctly. Can someone tell me what am missing here.
Adding PATH photo:
Adding a photo to be clear what am talking about:
How did you compile qtkeychain?
With the environment variable %QTDIR% set correctly, e.g. C:\Qt\Qt5.6.0\5.6\msvc2015, you should be able to compile qtkeychain
cmake -G "MinGW Makefiles" .
mingw32-make
and get a 32bit file named "libqt5keychain.dll.a".
You can then add the directory containing this file to your Windows path environment variable. This should work (it does for Nextcloud, at least).

libswiftDemangle.so on Linux

While compiling Swift on Mac machine, there is a dynamic library libswiftDemangle.dylib created. I need the dynamic library created on Linux machine as well, however, the dynamic library isn't created after a compilation of a source code.
The file CMakeLists.txt at lib/SwiftDemangle/CMakeLists.txt contains:
add_swift_library(swiftDemangle SHARED
SwiftDemangle.cpp
MangleHack.cpp
LINK_LIBRARIES swiftBasic)
directive, however the library isn't created.
I use this command ./swift/utils/build-script -R -c --build-subdir build --install-prefix /mnt/servers/swift/install -j4 to build the project, eventually it runs cmake and ninja to build the project.
Any ideas?
I can take a shot at explaining why the library is not getting built on Linux, even if it's late probably.
The main subdirectory containing the library you mention is:
https://github.com/apple/swift/tree/master/lib
To build the libs in that directory, which are organized in subdirectories, the following CMakeLists.txt is used:
https://github.com/apple/swift/blob/master/lib/CMakeLists.txt.
As can be clearly seen in this file, the library that you mention is only built if the system is OSX/Darwin and not in the Linux case. The relevant code in the aforementioned CMakeLists.txt is:
add_subdirectory(RemoteAST)
add_subdirectory(Sema)
add_subdirectory(Serialization)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_subdirectory(SwiftDemangle)
endif()
add_subdirectory(SIL)
add_subdirectory(SILGen)
As you can see it,
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_subdirectory(SwiftDemangle)
endif()
prevents SwiftDemangle to be built on Linux.
A superficial double check can be to look at:
https://github.com/apple/swift/blob/master/lib/SwiftDemangle/CMakeLists.txt
which will install or simlynk only *.dylib files.
It it worth mentioning that the swift-demangle tool (different from what you asked)
https://github.com/apple/swift/tree/master/tools/swift-demangle
is built on Linux.

What is the difference between building C++ Builder project from IDE and command line?

I have different behaviour of compiler, when building project from IDE and from command-line, which I can not explain.
The detailed issue's description is rather big, but it's really simple.
I have a C++ Builder project, which has a PAS-file included (IncludeUnits.pas). This pas-file has several units and inc-files listed. These files are located in separate folders and these folders are listed in library&include paths in project's options.
Folders layout:
C:\Demo\Bin
C:\Demo\Project
C:\Demo\Project\CBuilder5
C:\Demo\Project\Common
C:\Demo\Source
C:\Demo\Source\Common
Bin is output folder, Project/CBuilder5 holds project (bpr-file), Project/Common holds included pas-file (IncludeUnits.pas), Source and Source/Common hold other files (pas&inc). I think that it's pretty usual layout.
C:\Demo\Project\Common\ IncludeUnits.pas :
unit IncludeUnits;
interface
uses
Test;
implementation
end.
C:\Demo\Source\ Test.pas :
unit Test;
interface
{$I Test.inc}
implementation
end.
C:\Demo\Source\Common\ Test.inc :
// this file is empty
If I compile this project from C++ Builder IDE - it will compile fine. C++ Builder IDE doesn't have any additional paths in IDE settings set.
Now, I want to compile it from command-line. First, I issue
bpr2mak.exe MyProject.bpr
command.
This command creates MyProject.mak file, where I can see all paths ("....\Source" and "....\Source\Common" are the paths in question):
...
INCLUDEPATH = $(BCB)\include;$(BCB)\include\vcl;..\Common;..\..\Source;..\..\Source\Common
LIBPATH = $(BCB)\lib\obj;$(BCB)\lib;..\Common;..\..\Source;..\..\Source\Common
...
Now, I run make command:
make.exe -B -f"MyProject.mak"
It gives me the following output:
C:\PROGRA~1\Borland\CBUILD~2\BIN\dcc32 -N2....\Bin -N0....\Bin -$Y+ -$W -$R -v -JPHNE -M -UC:\PROGRA~1\Borland\CBUILD~2\bin..\include;C:\PROGRA~1\Borland\CBUILD~2\bin..\include\vcl;..\Common;..\..\Source;..\..\Source\Common -D_DEBUG;_RTLDLL;NO_STRICT -OC:\PROGRA~1\Borland\CBUILD~2\bin..\include;C:\PROGRA~1\Borland\CBUILD~2\bin..\include\vcl;..\Common;..\..\Source;..\..\Source\Common --BCB ..\Common\IncludeUnits.PAS
Borland Delphi Version 13.0 Copyright (c) 1983,99 Inprise Corporation
C:\Demo\Project\Common\IncludeUnits.pas(1) C:\Demo\Project\Common\IncludeUnits.pas(1) C:\Demo\Project\Common\IncludeUnits.pas(1) C:\Demo\Project\Common\IncludeUnits.pas(6) C:\Demo\Source\Test.pas(1) C:\Demo\Source\Test.pas(5) Fatal: File not found: 'Test.inc'
As you can see - all search path is passed to compiler and the file (Test.inc) is all here - in that Source\Common folder. But still compiler can't find it?
Of course, I run both commands from folder with bpr-file. And changing paths to absolute doesn't help.
Copying Test.inc from Source\Common to Source will help. Changing {$I Test.inc} to {$I Common\Test.inc} will also help.
Why? It seems that I'm missing something. Remember: project have no problems with compiling from IDE, Test.inc is found without copying or changing declaration. Did I miss some switch to make or dcc32?
I found the reason: command line for dcc32 misses -I switch, which specifies paths for include files.
For some reason, bpr2mak doesn't respect this option. Fortunately, it allows you to specify alternate template for conversion bpr -> mak. I edited default template and added "-I" option to it, pass new template to bpr2mak - and it worked.