库包含未在包含路径中检测标题 [英] Library include not detecting header in include path

查看:185
本文介绍了库包含未在包含路径中检测标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用mbed库设置一个makefile项目,以便在稍后想要做的更大项目中使用。我有这样的项目目录...

 
| - Doxyfile
| - NUCLEO_F446RE.mk
| - Nucleo_blink.map
| - asm
| - attach.gdb
| - debug
| - gdb-pipe.cfg
| - lib
| ` - mbed
| | - AnalogIn.h
| | - ...
| | - TARGET_NUCLEO_F446RE
| | | - TARGET_STM
| | | ` - TARGET_STM32F4
| | | | - PeripheralPins.h
| | | | - TARGET_NUCLEO_F446RE
| | | | | - PeripheralNames.h
| | | | | - PinNames.h
| | | | | - PortNames.h
| | | | | - device.h
| | | | ` - objects.h
| | | ` - gpio_object.h
| | | - TOOLCHAIN_GCC_ARM
| | | | - STM32F446XE.ld
| | | | - board.o
| | | | - ...
| | | ` - system_stm32f4xx.o
| | | - arm_common_tables.h
| | | - ...
| | ` - system_stm32f4xx.h
| | - Ticker.h
| | - ...
| ` - wait_api.h
| - makefile
| - obj
| - 释放
` - src
` - main.cc

具体而言,我的错误出现在 lib / mbed / platform.h ,它试图包含 device.h 。我有一个makefile,应该将其添加到包含路径,但g ++似乎仍然无法找到它。这是确切的错误...

  arm-none-eabi-g ++ -c -o main.o source / main。 cc 
从source /../ lib / mbed / mbed.h:21:0中包含的文件,source / main.cc中的
:1:
source /../ lib / mbed / platform.h:21:20:致命错误:device.h:没有这样的文件或目录
#includedevice.h
^
编译终止。
< builtin> ;: recipe for target'main.o'failed
make:*** [main.o]错误1

main.cc的第一行是 #include../lib/mbed/mbed.h\"



NUCLEO_F446RE.mk 定义了我正在使用的设备特定包含路径,我希望能够选择根据我传递给makefile的变量使用 .mk 文件,以便我可以轻松地使用不同的mbed板。以下是 NUCLEO_F446RE.mk ...的内容。

  HARDFP = 1 

LIBRARY_PATHS = -L./lib/mbed/TARGET_NUCLEO_F446RE/TOOLCHAIN_GCC_ARM

CPU = -mcpu = cortex-m4 -mthumb -mfpu = fpv4-sp-d16 -mfloat -abi = $(FLOAT_ABI)

LINKER_SCRIPT = ./lib/mbed/TARGET_NUCLEO_F446RE/TOOLCHAIN_GCC_ARM/STM32F446XE.ld

CC_SYMBOLS = -DTARGET_M4 -DMBED_BUILD_TIMESTAMP = 1453683815.81 -DTOOLCHAIN_GCC_ARM -DTOOLCHAIN_GCC -DTARGET_RTOS_M4_M7 -DTARGET_FF_MORPHO -DTARGET_CORTEX_M -D__FPU_PRESENT = 1 -DTARGET_FF_ARDUINO -DTARGET_STM32F446RE -DTARGET_NUCLEO_F446RE -D__MBED __ = 1 -DTARGET_STM -DTARGET_STM32F4 -D__CORTEX_M4 -DARM_MATH_CM4

INCLUDE_PATHS = -I./lib/ -I./lib/ mbed / \
-I./lib/mbed/TARGET_NUCLEO_F446RE/ \
-I./lib/mbed/TARGET_NUCLEO_F44\6RE/TARGET_STM/ \
-I./lib / mbed / TARGET_NUCLEO_F446RE / TARGET_STM / TARGET_STM32F4 / \
-I./lib/mbed/TARGET_NUCLEO_F446RE/TOOLCHAIN_GCC_ARM/ \
-I./lib/mbed/TARG ET_NUCLEO_F446RE / TARGET_STM / TARGET_STM32F4 / TARGET_NUCLEO_F446RE /#< - device.h is here

SYS_OBJECTS = ./lib/mbed/TARGET_NUCLEO_F446RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_flash_ramfunc.o \
./lib /mbed/TARGET_NUCLEO_F446RE/TOOLCHAIN_GCC_ARM/board.o \
...

好测量,这里是我的makefile。

 #项目参数
PROJECT = Nucleo_blink
我一直试图尽可能保持一切。 OBJECTS = main.o
DEST = debug
VPATH = src lib $ DEST
TARGET = NUCLEO_F446RE

#编译选项
DEBUG = 1

#Tools
AS = $(GCC_BIN)arm-none-eabi-as
CC = $(GCC_BIN)arm-none-eabi-gcc
CXX = $(GCC_BIN )arm-none-eabi-g ++
LD = $(GCC_BIN)arm-none-eabi-gcc
OBJCOPY = $(GCC_BIN)arm-none-eabi-objcopy
OBJDUMP = $( GCC_BIN)arm-none-eabi-objdump
SIZE = $(GCC_BIN)arm-none-eabi-size

include $(TARGET).mk

CFLAGS = $(INCLUDE_PATHS)$(CC_SYMBOLS)$(CPU)-c -g -fno-common -fmessage-length = 0 -Wall -Wextra -fno-exceptions -ffunction-sections -fdata-sections -fomit-frame-pointer - MMD -MP

ifeq($(HARDFP),1)
FLOAT_ABI = hard
else
FLOAT_ABI = softfp
endif

ifeq($(DEBUG),1)
CFLAGS + = - DDEBUG -O0
else
CFLAGS + = -DNDEBUG -Os
endif

LD_FLAGS = $(CPU)-Wl, - gc-sections --specs = nano.specs -u _printf_float -u _scanf_float -Wl, - wrap,main -Wl,-Map = $(PROJECT).map, - cref
LD_SYS_LIBS = -lstdc ++ -lsupc ++ -lm -lc -lgcc - lnosys

LIBRARIES = -lmbed

.PHONY:全部清理大小

全部:$(PROJECT).bin $(PROJECT).hex

clean:
rm -f debug / * obj / * asm / * $(DEPS)

obj /%。o:%.c#< ---尝试修复@ user657267
$(CC)$(CC_FLAGS)$(CC_SYMBOLS)-std = c99 $(INCLUDE_PATHS)-o obj / $ @ $所提到的目标错误<
$ b obj /%。o:%.cc
$(CXX)$(CC_FLAGS)$(CC_SYMBOLS)-std = c ++ 98 -fno-rtti $(INCLUDE_PATHS)-o obj / $ @ $<
$ b obj /%。o:%.cpp
$(CXX)$(CC_FLAGS)$(CC_SYMBOLS)-std = c ++ 98 -fno-rtti $(INCLUDE_PATHS)-o obj / $ @ $<
$ b obj /%。o:%.asm
$(CC)$(CPU)-c -x汇编程序与cpp -o asm / $ @ $<
$ b $(PROJECT).elf:$(OBJECTS)$(SYS_OBJECTS)
$(LD)$(LD_FLAGS)-T $(LINKER_SCRIPT)$(LIBRARY_PATHS)-o $(DEST )/ $ @ $ ^ $(LIBRARIES)$(LD_SYS_LIBS)$(LIBRARIES)$(LD_SYS_LIBS)

$(PROJECT).bin:$(PROJECT).elf
$(OBJCOPY) )-O二进制$< $ @

$(PROJECT).hex:$(PROJECT).elf
@ $(OBJCOPY)-O ihex $< $ @

$(PROJECT).lst:$(PROJECT).elf
@ $(OBJDUMP)-Sdh $< > $ @

lst:$(PROJECT).lst

size:$(PROJECT).elf
$(SIZE)$(PROJECT).elf

DEPS = $(OBJECTS:.o = .d)$(SYS_OBJECTS:.o = .d)
-include $(DEPS)

我在这里得到的很多代码是基于在将一个简单项目导出到makefile后在线mbed IDE的输出。但是,导出将所有内容都放在一个目录中,而且,当我开始执行大型项目并添加更多库时,这将非常麻烦。奇怪的是,当我使用单目录导出版本时,该项目编译时没有任何错误。 这里发生了什么?为什么g ++在我的多目录版本中没有看到 device.h



EDITS 2016-05-09:对makefile进行了细微的调整,错误也是一样。

$ c>%。o:%.cc%.cpp

此模式规则(可能)不正确,当且仅当.cc和.cpp文件存在(或可以由其他规则创建)时,您告诉make应用此规则。由于 main.cpp 大概不存在,make会回退到它内置的隐式规则,显然不会知道 INCLUDE_PATHS 或任何其他非常规变量用于标志。



您可以通过将两个规则分开来解决此问题。

 %。o:%.cc 
$(CXX)$(CC_FLAGS)$(CC_SYMBOLS)-std = c ++ 98 -fno -rtti $(INCLUDE_PATHS)-o obj / $ @ $<
%.o:%.cpp
$(CXX)$(CC_FLAGS)$(CC_SYMBOLS)-std = c ++ 98 -fno-rtti $(INCLUDE_PATHS)-o obj / $ @ $

然而,这些规则仍然被破坏,因为其中一个匹配类似 ./lib/mbed/TARGET_NUCLEO_F446RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_flash_ramfunc.o 你将把它放到 obj /./ lib / mbed / TARGET_NUCLEO_F446RE / TOOLCHAIN_GCC_ARM / stm32f4xx_hal_flash_ramfunc.o ,这意味着make会一直重新编译这个对象,因为它不会是你所说的应该在的地方(查看非正式的 Makefile的规则,特别是2)。

I am trying to set up a makefile project using the mbed library for use in a larger project I am wanting to do later on. I have the project directory set up like this...

.
|-- Doxyfile
|-- NUCLEO_F446RE.mk
|-- Nucleo_blink.map
|-- asm
|-- attach.gdb
|-- debug
|-- gdb-pipe.cfg
|-- lib
|   `-- mbed
|       |-- AnalogIn.h
|       |-- ...
|       |-- TARGET_NUCLEO_F446RE
|       |   |-- TARGET_STM
|       |   |   `-- TARGET_STM32F4
|       |   |       |-- PeripheralPins.h
|       |   |       |-- TARGET_NUCLEO_F446RE
|       |   |       |   |-- PeripheralNames.h
|       |   |       |   |-- PinNames.h
|       |   |       |   |-- PortNames.h
|       |   |       |   |-- device.h
|       |   |       |   `-- objects.h
|       |   |       `-- gpio_object.h
|       |   |-- TOOLCHAIN_GCC_ARM
|       |   |   |-- STM32F446XE.ld
|       |   |   |-- board.o
|       |   |   |-- ...
|       |   |   `-- system_stm32f4xx.o
|       |   |-- arm_common_tables.h
|       |   |-- ...
|       |   `-- system_stm32f4xx.h
|       |-- Ticker.h
|       |-- ...
|       `-- wait_api.h
|-- makefile
|-- obj
|-- release
`-- src
    `-- main.cc

Specifically, my error is in lib/mbed/platform.h, which tries to include device.h. I have a makefile that should add it to the include path, but g++ still seems to be unable to find it. Here is the exact error...

arm-none-eabi-g++    -c -o main.o source/main.cc
In file included from source/../lib/mbed/mbed.h:21:0,
                from source/main.cc:1:
source/../lib/mbed/platform.h:21:20: fatal error: device.h: No such file or directory
#include "device.h"
                    ^
compilation terminated.
<builtin>: recipe for target 'main.o' failed
make: *** [main.o] Error 1

Line 1 of main.cc is #include "../lib/mbed/mbed.h"

NUCLEO_F446RE.mk defines the device-specific include path I am using, and I hope to be able to be able to choose the .mk file to use based on a variable I pass to the makefile, so that I can easily use a different mbed board if I want. Here are the contents of NUCLEO_F446RE.mk...

HARDFP = 1

LIBRARY_PATHS = -L./lib/mbed/TARGET_NUCLEO_F446RE/TOOLCHAIN_GCC_ARM 

CPU = -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=$(FLOAT_ABI)

LINKER_SCRIPT = ./lib/mbed/TARGET_NUCLEO_F446RE/TOOLCHAIN_GCC_ARM/STM32F446XE.ld

CC_SYMBOLS = -DTARGET_M4 -DMBED_BUILD_TIMESTAMP=1453683815.81 -DTOOLCHAIN_GCC_ARM -DTOOLCHAIN_GCC -DTARGET_RTOS_M4_M7 -DTARGET_FF_MORPHO -DTARGET_CORTEX_M -D__FPU_PRESENT=1 -DTARGET_FF_ARDUINO -DTARGET_STM32F446RE -DTARGET_NUCLEO_F446RE -D__MBED__=1 -DTARGET_STM -DTARGET_STM32F4 -D__CORTEX_M4 -DARM_MATH_CM4

INCLUDE_PATHS = -I./lib/ -I./lib/mbed/ \
-I./lib/mbed/TARGET_NUCLEO_F446RE/ \
-I./lib/mbed/TARGET_NUCLEO_F44\6RE/TARGET_STM/ \
-I./lib/mbed/TARGET_NUCLEO_F446RE/TARGET_STM/TARGET_STM32F4/ \
-I./lib/mbed/TARGET_NUCLEO_F446RE/TOOLCHAIN_GCC_ARM/ \
-I./lib/mbed/TARGET_NUCLEO_F446RE/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446RE/ #<--device.h is here

SYS_OBJECTS = ./lib/mbed/TARGET_NUCLEO_F446RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_flash_ramfunc.o \
./lib/mbed/TARGET_NUCLEO_F446RE/TOOLCHAIN_GCC_ARM/board.o \
...

For good measure, here is my makefile. I have been trying to keep everything as neat as possible.

#Project parameters
PROJECT = Nucleo_blink
OBJECTS = main.o
DEST    = debug
VPATH   = src lib $DEST
TARGET  = NUCLEO_F446RE

#Compilation options
DEBUG = 1

#Tools
AS      = $(GCC_BIN)arm-none-eabi-as
CC      = $(GCC_BIN)arm-none-eabi-gcc
CXX     = $(GCC_BIN)arm-none-eabi-g++
LD      = $(GCC_BIN)arm-none-eabi-gcc
OBJCOPY = $(GCC_BIN)arm-none-eabi-objcopy
OBJDUMP = $(GCC_BIN)arm-none-eabi-objdump
SIZE    = $(GCC_BIN)arm-none-eabi-size 

include $(TARGET).mk

CFLAGS = $(INCLUDE_PATHS) $(CC_SYMBOLS) $(CPU) -c -g -fno-common -fmessage-length=0 -Wall -Wextra -fno-exceptions -ffunction-sections -fdata-sections -fomit-frame-pointer -MMD -MP

ifeq ($(HARDFP),1)
        FLOAT_ABI = hard
else
        FLOAT_ABI = softfp
endif

ifeq ($(DEBUG), 1)
        CFLAGS += -DDEBUG -O0
else
        CFLAGS += -DNDEBUG -Os
endif

LD_FLAGS = $(CPU) -Wl,--gc-sections --specs=nano.specs -u _printf_float -u _scanf_float -Wl,--wrap,main -Wl,-Map=$(PROJECT).map,--cref
LD_SYS_LIBS = -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys

LIBRARIES = -lmbed 

.PHONY: all clean lst size

all: $(PROJECT).bin $(PROJECT).hex

clean:
        rm -f debug/* obj/* asm/* $(DEPS)

obj/%.o: %.c #<---Attempt to fix target error mentioned by @user657267
        $(CC)  $(CC_FLAGS) $(CC_SYMBOLS) -std=c99 $(INCLUDE_PATHS) -o obj/$@ $<

obj/%.o: %.cc
        $(CXX) $(CC_FLAGS) $(CC_SYMBOLS) -std=c++98 -fno-rtti $(INCLUDE_PATHS) -o obj/$@ $<

obj/%.o: %.cpp
        $(CXX) $(CC_FLAGS) $(CC_SYMBOLS) -std=c++98 -fno-rtti $(INCLUDE_PATHS) -o obj/$@ $<

obj/%.o: %.asm
        $(CC) $(CPU) -c -x assembler-with-cpp -o asm/$@ $<

$(PROJECT).elf: $(OBJECTS) $(SYS_OBJECTS)
        $(LD) $(LD_FLAGS) -T$(LINKER_SCRIPT) $(LIBRARY_PATHS) -o $(DEST)/$@ $^ $(LIBRARIES) $(LD_SYS_LIBS) $(LIBRARIES) $(LD_SYS_LIBS)

$(PROJECT).bin: $(PROJECT).elf
        $(OBJCOPY) -O binary $< $@

$(PROJECT).hex: $(PROJECT).elf
        @$(OBJCOPY) -O ihex $< $@

$(PROJECT).lst: $(PROJECT).elf
        @$(OBJDUMP) -Sdh $< > $@

lst: $(PROJECT).lst

size: $(PROJECT).elf
        $(SIZE) $(PROJECT).elf

DEPS = $(OBJECTS:.o=.d) $(SYS_OBJECTS:.o=.d)
-include $(DEPS)

A lot of the code I have here is based on the output from the online mbed IDE after exporting a simple project to a makefile. However, the export had everything in a single directory, and that will be extremely messy as I start doing larger projects and possibly add more libraries. The strange part is that this project compiles without any errors when I use the single-directory exported version. What is going on here? Why is g++ not seeing device.h in my multi-directory version?

EDITS 2016-05-09: Minor tweaks to makefile, same error.

解决方案

%.o: %.cc %.cpp

This pattern rule is (probably) incorrect, you're telling make to apply this rule if and only if both the .cc and .cpp files exist (or can be made by other rules). As main.cpp presumably doesn't exist make will fall back to its built-in implicit rule, which obviously won't know about INCLUDE_PATHS or any other of the unconventional variables you're using for flags.

You can fix this by making the two rules separate

%.o: %.cc
    $(CXX) $(CC_FLAGS) $(CC_SYMBOLS) -std=c++98 -fno-rtti $(INCLUDE_PATHS) -o obj/$@ $<
%.o: %.cpp
    $(CXX) $(CC_FLAGS) $(CC_SYMBOLS) -std=c++98 -fno-rtti $(INCLUDE_PATHS) -o obj/$@ $<

These rules are still broken however, as when one of them matches something like ./lib/mbed/TARGET_NUCLEO_F446RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_flash_ramfunc.o you're going to place it into obj/./lib/mbed/TARGET_NUCLEO_F446RE/TOOLCHAIN_GCC_ARM/stm32f4xx_hal_flash_ramfunc.o, which means make will always recompile the object because it won't be where you've said it should be (check out the informal Rules of Makefiles, specifically 2).

这篇关于库包含未在包含路径中检测标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆