5

I've created the following symbolic link:

Source: /usr/local/android-ndk-r5/ndk-build
Destination: /usr/local/bin/ndk-build

However, when I attempt to use ndk-build from my source directory, it fails because it can't find files that the script depends on in the source directory.

How can I get the symbolic link to use the source directory as the working directory?

5

You can't, you need to make a wrapper script.

Assuming that the program relies on the filename for determining the script (likely):

#!/bin/sh
exec /usr/local/android-ndk-r5/ndk-build "$@"

Assuming that the program relies on the current working directory (unlikely):

#!/bin/sh
cd /usr/local/android-ndk-r5
exec ./ndk-build "$@"

Save one of these files in /usr/local/bin/ndk-build and make it executable:

sudo editor /usr/local/bin/ndk-build
sudo chmod 755 /usr/local/bin/ndk-build
  • FYI, it was the first option. Thanks a bunch :) – Mark Ingram Jul 4 '11 at 19:45
  • I think you mistyped "#@" – Ahmed Essam Sep 3 '16 at 14:05
  • @AhmedEssam Corrected now and also added exec to replace the current shell process. Without that, you would have an additional useless process that sits there until the child process (ndk-build) has exited. – Lekensteyn Sep 3 '16 at 18:03
0

When calling-executing a program under GNU Linux receives some command-line arguments, including the current working directory.

The code in the program decides how to use these arguments, hence the code decides if the program will use the directory of the link or the directory of the target.

Apparently the ndk-build uses the directory of the link to find its own files, so you are forced to create some kind of wrapper.

Be careful not to mix the "perception" of current working directory (under which your command runs, which is the directory returned by pwd command) with the "perception" of directory used by ndk-build to find its own files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.