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?

  • This answer on stackoverflow answers the question: http://stackoverflow.com/questions/786376/how-do-i-run-a-program-with-a-different-working-directory-from-current-from-lin. –  Sep 04 '16 at 06:58

2 Answers2

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
Lekensteyn
  • 174,277
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.