1. Edit the Makefile
From
DESTDIR ?= /usr/local
MANDIR ?= share/man/man3
To
DESTDIR = /data/data/com.termux/files/usr/local
MANDIR = /data/data/com.termux/files/usr/share/man/man3
In the Makefile, the question mark equal sign (?=) is for asking if the variable isn't defined. In this case just force it to use the specified path.
2. Build & Install without SUDO
$ make install
You'll end up getting an error at end
ldconfig /data/data/com.termux/files/usr/local/lib
make: ldconfig: No such file or directory
make: *** [Makefile:55: install] Error 127
However the libraries are in the /data/data/com.termux/files/usr/local/lib
directory and the man files should be in the right place
$ man get_string
should display the CS50 man page for get_string
3. Add missing linking reference
More of a hack but works, as ldconfig
doesn't appear to be available in Termux.
In build/lib there should be three files:
$ ls -1
libcs50.a
libcs50.so
libcs50.so.10.1.10
These three same files should also be in:
/data/data/com.termux/files/usr/local/lib
$ cd /data/data/com.termux/files/usr/local/lib
$ ls -l
.... libcs50.a
.... libcs50.so -> libcs50.so.10.1.0
.... libcs50.so.10.1.0
You'll need to add one symbolic link for libcs50.so.10
:
$ ln -s libcs50.so.10.1.0 libcs50.so.10
$ ls -l
.... libcs50.a
.... libcs50.so -> libcs50.so.10.1.0
.... libcs50.so.10 -> libcs50.so.10.1.0
.... libcs50.so.10.1.0
4. Add needed environment variables
$ export LIBRARY_PATH="/data/data/com.termux/files/usr/local/lib"
$ export LD_LIBRARY_PATH="/data/data/com.termux/files/usr/local/lib"
You'll probably want to add these to your shell environment.
5. Run test C code
$ cd <unzip_directory>/tests
realize that the files in tests
are using an older CS50 API so
in hackerrank.c
needs to be changed from
string s = get_string();
to
string s = get_string("Type here:");
for it to compile correctly.
Otherwise you'll get errors like
hackerrank.c:6:16: error: expected expression
string s = get_string();
^
/data/data/com.termux/files/usr/local/include/cs50.h:109:53: note:
expanded from macro 'get_string'
...get_string(NULL, __VA_ARGS__)
^
1 error generated.
So once the edit is made. Compile the code.
$ cc -lcs50 hackerrank.c
$ ./a.out
Type here: <type stuff>
hello, <type stuff output>
$
Always double check your environment variables with the export
command if you are having problems compiling or running.
$ export
...
...
declare -x LIBRARY_PATH="/data/data/com.termux/files/usr/local/lib"
declare -x LD_LIBRARY_PATH="/data/data/com.termux/files/usr/local/lib"
...
...