Derek N
Derek N

Reputation: 73

cx_freeze embedding my shared object library into the binary executable?

I'm able to use cx_freeze to package my python tool, but the library I need can't be loaded. For some reason the outputted executable/binary name keeps getting included in the path.

I get the following error:

OSError: /home/derekx/sbu/build/exe.linux-x86_64-2.7/secure_boot_utility/lib/libcrypto.so.1.0.0: cannot open shared object file: Not a directory

The library gets packaged to /home/derekx/sbu/build/exe.linux-x86_64-2.7/lib/libcrypto.so.1.0.0

The created binary "secure_boot_utility" is also in the build/exe.linux86_64-2.7 dir.

My input script and setup.py are in /home/derekx/sbu.

I used "python setup.py build" to package the tool/dependencies..

Any help would be greatly appreciated. I've tried a combination of the options but still get the same error.

My setup.py is:

import sys
from cx_Freeze import setup, Executable

sys.path.append('sbu_scripts/')
sys.path.append('lib/')

binincludes = ['libcrypto.so.1.0.0']
binpaths = ['/home/derekx/sbu/lib']
includefiles = [('lib/libcrypto.so.1.0.0','lib/libcrypto.so.1.0.0'),]

exe = Executable(
    script="secure_boot_utility.py",
    )

setup(
    name = "SecureBoot",
    version = "0.1",
    description = "Test Secure Boot",
    options = {"build_exe": {'copy_dependent_files':True, 'create_shared_zip':True, 'bin_includes':binincludes, 'bin_path_includes':binpaths, 'include_files':includefiles}},
    executables = [exe]
    )

Upvotes: 3

Views: 2785

Answers (1)

Derek N
Derek N

Reputation: 73

I'm not sure why the top level directory (getcwd) is the executable name.

Anyway I was able to add something in my code with os.path.exists and readjust the value sent to LoadLibrary.

Thanks, Thomas, for taking the time to respond.

This is originally someone else's tool that I had to support. What was happening was sys.path[0] was being used to get the current working directory to construct the full path to the libraries being loaded. I'm not sure why the executable that was created with cx_freeze always embedded the executable name in the the current working directory.

How I fixed it, was checked if the full path of the library that gets constructed existed with os.path.exists:

if os.path.exists(path_to_lib) is False:
    path_to_lib = LibName

return path_to_lib

This way if the full path exists, it works and if it does not just use the LibName which should pick it up from the LD_LIBRARY_PATH environment setting.

Upvotes: 3

Related Questions