简体   繁体   中英

Can I set @executable_path from Python

I have an application written in Python that uses Ogre3D via a C++ wrapper module. When attempting to run my application

python /path/to/myapp.py

I get the error

dlopen(./MyOgreWrapper.so, 2): Library not loaded: @executable_path/../Frameworks/Ogre.framework/Versions/1.9.0/Ogre Referenced from: /path/to/MyOgreWrapper.so Reason: image not found

I am running it from the directory where MyOgreWrapper.so is located so that MyOgreWrapper.so can be found by Python. Ogre.framework is located in ../Frameworks relative to the location of MyOgreWrapper.so.

$otool -l MyOgreWrapper.so
MyOgreWrapper.so:
@rpath/MyOgreWrapper.so (compatibility version 0.0.0, current version 0.0.0)
@executable_path/../Frameworks/Ogre.framework/Versions/1.9.0/Ogre (compatibility version 1.9.0, current version 1.9.0)
...

I suspect that this happens because @executable_path is set to the path of the python executable.

Is there a way to set up the environment from Python so that @executable_path is the current directory?

(I know that it will all work if I change the path for Ogre in MyOgreWrapper.so and a few other dependencies to @loader_path but that is not how it comes out of the box and I'd rather not have to do that.)

No, there's no way to control @executable_path from within the executable. @executable_path is resolved by dyld , the dynamic loader, and it uses the path of the executable that it loaded. It's fixed for any given executable.

Also, if you could change it, that would probably break other stuff that the process attempts to load.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM