Akshay Jindal
Akshay Jindal

Reputation: 115

Unable to understand the errors given by running make

My directory structure is /home/akshayaj/Desktop/System Programs/dictionary/

Inside dictionary I have 3 files:

Both C files include the header file

Now I wrote a make file for the above project. It goes like this:-

CFLAGS=-I /home/akshayaj/Desktop/System Programs/dictionary/
libdict: libentrypoint.o libdictionary.o
    cc $(CFLAGS) -o libdict libentrypoint.o libdictionary.o
libentrypoint.o: libentrypoint.c libdictionary.h
    cc $(CFLAGS) -c libentrypoint.c
libdictionary.o: libdictionary.c libdictionary.h
    cc $(CFLAGS) -c libdictionary.c

Now when I ran it, I got these errors:-

cc -I /home/akshayaj/Desktop/System Programs/dictionary/ -c libentrypoint.c


cc: error: Programs/dictionary/: No such file or directory


make: *** [libentrypoint.o] Error 1

Where am I going wrong?

Note:- In CFLAGS I have given the whole path because I saw it in a similar question, but that didn't work. Here is the link to that question.

C Compile Error (No such file or directory, compilation terminated)

Upvotes: 0

Views: 85

Answers (2)

Karl Nicoll
Karl Nicoll

Reputation: 16419

Think about how that command line would be parsed...

cc -I /home/akshayaj/Desktop/System Programs/dictionary/ -c libentrypoint.c
^^ ^------------------------------^ ^------------------^ ^-----------------^
 |               |                           |                     |
Command       -I arg                      BAD ARG               -c arg

As you can see, the space between "System" and "Programs" is read as a separator between two command args.

Your options are either:

  1. Change the path so that the space is removed (recommended). e.g. /home/akshayaj/Desktop/System-Programs/dictionary/.

  2. Add a backslash before the space to escape it. e.g.:

    /home/akshayaj/Desktop/System\ Programs/dictionary/
    

As a general rule, it's not wise to use paths with spaces in them when building stuff using make, or just building stuff in general. It makes ambiguities like this hard to solve.

Upvotes: 1

SpaceCowboy
SpaceCowboy

Reputation: 563

Try to use path /home/akshayaj/Desktop/System\ Programs/dictionary/, where \ handles the space.

Upvotes: 1

Related Questions