Fire Crow
Fire Crow

Reputation: 7729

Make failes to find source file, works if cc is run directly

I have an issue where make fails even though running the commands directly succeeds:

$ make
cc -o ./bin/cams cams.c
cc: error: no such file or directory: 'cams.c'
cc: error: no input files
*** Error code 1

Stop.
make: stopped in /usr/psrc/cams

even though

cc -o ./bin/cams cams.c

suceeds

here is my Makefile

SHELL = /usr/local/bin/bash
cams: 
    cc -o ./bin/cams cams.c
clean:
    rm ./bin/cams

Upvotes: 0

Views: 48

Answers (2)

Fire Crow
Fire Crow

Reputation: 7729

it turns out the presence of a directory name 'obj' was to blame

Upvotes: 0

joshmeranda
joshmeranda

Reputation: 3261

We would need to see the Makefile you are using to be able to troubleshoot. The following Makefile should work assuming that you only have the one file and do not need to specify any additional include locations.

CC=cc
SOURCES=cams.c
OBJECTS=$(SOURCES:.c=.o)
EXECUTABLE=bin/cams

all: $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS) 
    $(CC) $(OBJECTS) -o $@

%.o : %.cpp
    $(CC) -c $< -o $@

clean:
    rm -fv $(OBJECTS) $(EXECUTABLE)

To include for any additional c files written, simply append the filename to the end of sources. Make sure to use tabs instead of spaces. Look at this Linux man page for more information make(1p).

Upvotes: 1

Related Questions