G++无法更改包括-i的路径
我使用g ++ 7.5.0 / gnu在kubuntu上制作C ++。我的文件结构:
bin
| .o files
header
|archiver.h
source
|main.cpp
|archiver.cpp
makefile
我希望我的源文件能够检测标头文件而无需执行#include“ ../header/archiver.h”。我尝试使用:
g++ -I/header
但这不起作用。我得到错误:
g++: fatal error: no input files.
请求的makefile
CC = g++
CFLAGS = -c -Wall
objects = bin/main.o bin/archiver.o
all : $(objects)
$(CC) -o build $(objects)
bin/%.o : source/%.cpp
$(CC) $(CFLAGS) $?
mv *.o bin
.PHONY : clean
clean :
rm -rf all $(objects)
I'm on kubuntu using g++ 7.5.0 / GNU make for C++. My file structure:
bin
| .o files
header
|archiver.h
source
|main.cpp
|archiver.cpp
makefile
I want my source files to be able to detect header files without having to do #include "../header/archiver.h". I've tried using:
g++ -I/header
but this does not work. I get the error:
g++: fatal error: no input files.
makefile that was requested
CC = g++
CFLAGS = -c -Wall
objects = bin/main.o bin/archiver.o
all : $(objects)
$(CC) -o build $(objects)
bin/%.o : source/%.cpp
$(CC) $(CFLAGS) $?
mv *.o bin
.PHONY : clean
clean :
rm -rf all $(objects)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该命令
不会更改
g ++
的任何默认设置,包括您似乎假设的带有后续调用的搜索路径。您需要为每个C ++调用传递该编译器标志,该标志由
Make
根据您的makefile
。发出的规则。
后者是您需要适应的方法,最好使用预定义的makefile变量,例如
cxxflags
或cxxCincludes
(查看GNU-MAKE文档以获取详细信息)。对于您的具体情况
应该有效。
The command
doesn't change any default settings for the
g++
include search paths with subsequent calls, as you seem to assume.You'll need to pass that compiler flag for each individual c++ call, which are issued by
make
according the rules defined in yourmakefile
.The latter is what you need to adapt, best using a pre-defined makefile variable like
CXXFLAGS
orCXXINCLUDES
(check the GNU-make documentation for details).For your specific case
should work.