I have an header file, sieve.h, that has no cpp file. Here is what I have for the makefile as of right now:
bitarray_executable: bitarray.o sieve.o main.o
g++ -o bitarray.out bitarray.o sieve.o main.o
sieve.o: sieve.h
g++ -o sieve.o -c sieve.h
main.o: main.cpp bitarray.h sieve.h
g++ -o main.o -c main.cpp
clean:
rm -f *.o bitarray
I get the error when I make it:
g++ -o sieve.o -c sieve.h
sieve.h:15: error: expected `)' before ‘&’ token
make: *** [sieve.o] Error 1
This is Sieve:
#ifndef _SIEVE_H
#define _SIEVE_H
#include <iostream>
#include "bitarray.h"
using namespace std;
class Sieve
{
public:
Sieve(BitArray& x)
{
for (int i = 0; i < x.Length; i++)
x.Set(i);
}
};
#endif
Anyone have more experience writing makefiles to tell me what is wrong with this?
.o files are compiled from files like .cpp or .c or .c++
Assuming that sieve.h is included into main.cpp since you state it has no .cpp then there is nothing to compile for it, but you can specify other dependency rules as you have done with main.o
You have no details on bitarray, so I’ll assume that was a provided object file, or follows the default/implied rules for making .o
Thus your make file can be simplified to (which is almost what fazo had)
To tidy up a bit further, assuming that default rule for making .o files