0

I'm having trouble running my makefile, it doesnt seem to use the include path i've specified. The makefile looks like this:

SHELL   = /bin/sh
CC      = g++
FLAGS   = -std=c++0x
CFLAGS  = -Wall -fPIC -g -I/include
LDFLAGS = -shared

TARGET  = TNet.so
SOURCES = $(shell echo src/*.cpp)
HEADERS = $(shell echo include/*.h)
OBJECTS = $(SOURCES:.cpp=.o)


all: $(TARGET)

$(TARGET): $(OBJECTS)
    $(CC) $(FLAGS) $(CFLAGS) $(DEBUGFLAGS) -o $(TARGET) $(OBJECTS)

clean:
    -rm *.o $(TARGET

My directory tree looks like this:

  rootfolder
   /    \
src     include

any ideas?

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190

3 Answers3

0

Supposed your Makefile is actually placed under rootfolder and this is the working directory for your compiler call, you'll need to specify your include path not as an absolute path, but relative

CFLAGS  = -Wall -fPIC -g -I./include

or

CFLAGS  = -Wall -fPIC -g -Iinclude
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
  • still doesnt quite work, still get the same error message, also when i run make i get some strange output: g++ -c -o src/client.o src/client.cpp shouldnt there be more flags there? looks like all CFLAGS are excluded – Henningsson Sep 29 '14 at 18:01
  • @Henningsson Which error message exactly? Please edit your question to add this information. Also `SOURCES = $(shell echo src/*.cpp)` doesn't look correct for me, lookup `make functions` from the info. – πάντα ῥεῖ Sep 29 '14 at 18:04
  • @Henningsson Here's more info about [`make file name functions`](http://www.gnu.org/software/make/manual/make.html#File-Name-Functions) – πάντα ῥεῖ Sep 29 '14 at 18:12
0

Unless your project is directly under / you should add -Include to the compiler flags

0

This Makefile works for me:

$ cat Makefile
CPPFLAGS = -Iinclude
CXXFLAGS = -Wall
foo: foo.cpp

$ make foo
g++ -Wall -I/include    foo.cpp   -o foo

It makes use of the already defined implicit rules. In your case the flags to look for are:

CPPFLAGS
Extra flags to give to the C preprocessor and programs that use it (the C and Fortran compilers). 
CXXFLAGS
Extra flags to give to the C++ compiler. 

Please note how the -I dir is a flag for the pre processor, whereas the -Wall is usually a flag to the C++ compiler.

Micha Wiedenmann
  • 19,979
  • 21
  • 92
  • 137
  • Thanks that worked! also follow up question: i get the compile error "undefined reference to 'main'". But i'm trying to compile a library, so shouldnt be any need for a main function? or am i missing something? – Henningsson Sep 29 '14 at 18:06
  • @Henningsson _"also follow up question ..."_ That's a completely different and unrelated question, ask another one please! Here's a hint though: [`What is an undefined reference/unresolved external symbol error and how do I fix it?`](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – πάντα ῥεῖ Sep 29 '14 at 18:09