user776335
user776335

Reputation: 23

Getting a simple Makefile to work

So I'm having trouble getting even a simple Makefile to work. Heres what I have:

proj : driver.o
    icc -g -O3 -openmp driver.o -o proj
driver.o : driver.c driver.h
    icc -g -O3 -openmp driver.c 

I feel like it's pretty straight forward. Proj only depends on driver.o which in turn depends on driver.c and driver.h. When run, the compiler fails with 'could not open source file "driver.h" ' at the include within the driver.c file. What am I missing?

Upvotes: 2

Views: 261

Answers (3)

nimrodm
nimrodm

Reputation: 23799

Assuming you run make from the directory where all source files and headers reside, make sure you use quotes in your include directive:

#include "driver.h"

...rather than:

#include <driver.h>

The latter will search the system include path (and you will have to add the current directory to that path as larsmans suggested).

Upvotes: 2

Mario
Mario

Reputation: 36487

Is it in the correct folder? also the way you're compiling you might have to add -c to the command line to compile driver.o instead of trying to create a complete exectuable (only used to gcc so this might not be required).

Other than that (and the possible addition of the -I flag larsmans mentioned I can't see any other issue.

Upvotes: 1

Fred Foo
Fred Foo

Reputation: 363567

You should give icc a -I. option to get it to look for include files in the current directory.

icc -I. -c -g -O3 -openmp driver.c 

(I took the liberty of also adding the -c flag to prevent linking.)

Upvotes: 3

Related Questions