5

I'm having a problem with LD_PRELOAD on Linux. I'm trying to load a library existing in a directory with spaces in its name, right before launching my application:

> export LD_PRELOAD='/home/myuser/MyApp\ Test/lib/mylib.so'

However, the path is not being taken properly. It gets split where the space exists, so it tries to preload these:

ERROR: ...: object '/home/myuser/MyApp' from LD_PRELOAD cannot be preloaded: ignored
ERROR: ...: object 'Test/lib/mylib.so' from LD_PRELOAD cannot be preloaded: ignored

I'm already escaping the space in 'MyApp Test'. What is the correct way to pass such path?

Edit: exporting without the escaped space as suggested, renders the same results:

export LD_PRELOAD='/home/myuser/MyApp Test/lib/mylib.so'

As well as (no quotes, just escaped space):

export LD_PRELOAD=/home/myuser/MyApp\ Test/lib/mylib.so

2
  • 2
    Try without the backslash: export LD_PRELOAD='/home/myuser/MyApp Test/lib/mylib.so' Commented Apr 9, 2012 at 11:40
  • 1
    I tried without the backslash, but it gives the same problem. The library path is divided in two Commented Apr 9, 2012 at 11:56

2 Answers 2

11

The dynamic loader is probably just doing a naive split on spaces, in which case it's impossible to get it to treat the space as part of your path.

You can work around it by creating a symlink to the library you want to preload that doesn't contain any spaces.

Edit:

confirmed by http://ubuntuforums.org/showthread.php?t=1142062

As other variables like PATH or LD_LIBRARY_PATH, this variable may contain list of library names separated by colons. But... for compatibility with legacy systems it is possible to separate LD_PRELOAD elements by spaces. And older systems did not understand escaping so it turns out it is impossible to put full library paths into LD_PRELOAD if they contain spaces.

Sign up to request clarification or add additional context in comments.

Comments

6

You can actually work around this by adding the path with spaces to LD_LIBRARY_PATH and then using LD_PRELOAD without the pathname. For example:

export LD_LIBRARY_PATH="/home/myuser/MyApp\ Test/lib/":${LD_LIBRARY_PATH}
export LD_PRELOAD=mylib.so

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.