0

I downloaded cs50 library for C per the instructions on cs50 docs site.

I then unzip it and run sudo make install but it display the error below:

No superuser binary detected. Are you rooted?

I'm running Termux app on Android, and uses vim as editor.

How do I fix the above? If I decide to root my device will this be solve or is there a workaround to this without having to root my device? TIA.

1

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"
...
...

8
  • Hi @Morrison Chang thanks for the guide. However, Step 1 worked fine. But in step 2 after I ran make install it showed the error as you pointed out. And running man get_string didn't display the CS50 man page for get_string rather it displayed the error man: No entry for get_string in the manual. Should I ignore this and continue with step 3 or was something broken that I need to fix before proceeding? Jun 19 '20 at 12:10
  • You can ignore the failure of the man files copying. Just in case check the MANDIR for other man files. If the directory looks fine, you can just copy the CS50 man files from the docs directory. My worry is that the path I have is different from yours (perhaps an older version of Termux). Jun 19 '20 at 15:17
  • Once again, thanks @Morrison Chang for your time and response this far. Just before, step 4 in your earliest comment, I guess you meant > ls not ln after creating the symbolic link. Secondly, in step 5 about running test code, when I tried the cc -lcs50 hackerrank.c. It generated 1 error about get_string (i.e 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 . Please, how can I fix this? Jun 19 '20 at 22:32
  • Check that /data/data/com.termux/files/usr/local/include directory has cs50.h file. If not there copy from build/include directory (post step 2). Realize that I'm just following: github.com/cs50/libcs50#troubleshooting but replacing the path with one which will work with Termux. Also double check what you did as typos will break things. Jun 19 '20 at 22:44
  • I just cd into the directory "/data/data/com.termux/files/usr/local/include" and found cs50.h in there. Jun 19 '20 at 22:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .