简体   繁体   中英

linux - c++ makefile not using include path

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?

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

除非您的项目直接位于/下,否则应在编译器标志中添加-Include

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM