简体   繁体   English

Linux-C ++ Makefile不使用包含路径

[英]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. 我在运行我的makefile时遇到麻烦,它似乎没有使用我指定的include路径。 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 假设您的Makefile实际上放置在rootfolder下,并且这是编译器调用的工作目录,则需要指定include路径(不是绝对路径,而是相对路径)

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

or 要么

CFLAGS  = -Wall -fPIC -g -Iinclude

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

This Makefile works for me: 这个Makefile对我Makefile

$ 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. 请注意-I dir是预处理器的标志,而-Wall通常是C ++编译器的标志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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