2

This is the first time I install a library. I followed the instructions here. It's from an online course on programming.

I'm not very Unix savvy. When I tried to compile one of the sample c files, one that #includes the cs50.h file, I get:

cc1: error: /usr/local/include: not a directory

Also, if I write cd /usr/local/include or cd /usr/local/lib, it tells me it's not a directory again, even though when I ls /usr/local they both show up.

Any ideas?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
iDontKnowBetter
  • 443
  • 1
  • 7
  • 19

1 Answers1

3

Given that the instructions in the header are:

  • To compile as a static library on your own system:
  • % gcc -c -ggdb -std=c99 cs50.c -o cs50.o
  • % ar rcs libcs50.a cs50.o
  • % rm -f cs50.o
  • % cp cs50.h /usr/local/include
  • % cp libcs50.a /usr/local/lib

Note the use of '%' as a prompt. It indicates that the operations should be done as root.

Unless your system is misconfigured, you will need to use root privileges to copy the files into the directories under /usr/local. For example, you might use sudo as a prefix to the commands:

sudo cp cs50.h /usr/local/include
sudo cp libcs50.a /usr/local/lib

We can deduce (with fairly high confidence) that you did not already have directories /usr/local/include and /usr/local/lib, and that you now have two files (not directories) called:

  • /usr/local/include that contains the header cs50.h
  • /usr/local/lib that contains the static library

You should validate this observation with ls -l /usr/local and perhaps file /usr/local/*. Then you should remove the files, create the directories, and copy the files into the newly created directories.

The only thing this explanation does not account for is the missing leading slash in the error message (which originally said 'cc1: error: usr/local/include: not a directory'). At the moment, I put that down to a transcription error in asking this question. (And a comment and edit confirms that diagnosis.)

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • Normally a `#` prompt, not `%`, indicates root. – Keith Thompson Aug 08 '11 at 04:36
  • 1
    @Keith: oh...bother...yes, you're right...'%' means the other sin - using a C Shell. It isn't the prompt I get... – Jonathan Leffler Aug 08 '11 at 04:38
  • Thanks, that seems to have solved the original problem. Though I still had to sudo when copying the files. Now I also get a new error altogether lol. When I `gcc -o f2c.o f2c.c -lcs50`. "undefined symbols" – iDontKnowBetter Aug 08 '11 at 04:44
  • @fakaff: which symbols are undefined? Also, your output file name is aconventional: you'd normally write `gcc -o f2c f2c.c -lcs50` (or, perhaps, `gcc -o f2c.o -c f2c.c`). – Jonathan Leffler Aug 08 '11 at 04:50
  • I get: `Undefined symbols: "_getfloat", referenced from: _main in ccG8nNEz.o ld: symbol(s) not found` – iDontKnowBetter Aug 08 '11 at 05:00
  • @fakaff: since the code in cs50.c defines `GetFloat()` and C is case-sensitive, there will be no `getfloat()` unless you write it. – Jonathan Leffler Aug 08 '11 at 05:03
  • @Jonathan D'oh! I changed that to getfloat() about two hours ago, for reasons I no longer remember, and forgot to change it back. Thanks for all the help! – iDontKnowBetter Aug 08 '11 at 05:10