Header files in application
-
- Beginner
- Posts: 28
- Joined: Sun Sep 08, 2019 12:44 pm
- Contact:
Header files in application
Hello,
I have a question about using header files with an app. I saw there are some modifications in the firmware now, and the source files need to be specified by appending the "obj-y" variable. But what should one do for the header files? I see that it doesn't work anymore to add them to "INCLUDES" in the Makefile of the app - if I do that, they are not visible during compilation.
Thank you!
I have a question about using header files with an app. I saw there are some modifications in the firmware now, and the source files need to be specified by appending the "obj-y" variable. But what should one do for the header files? I see that it doesn't work anymore to add them to "INCLUDES" in the Makefile of the app - if I do that, they are not visible during compilation.
Thank you!
-
- Bitcraze
- Posts: 630
- Joined: Tue Jun 30, 2015 7:47 am
Re: Header files in application
Hi!
Object (.o) files are added to the build using Kbuild files in the new make system. Each directory must have one Kbuild file that adds the files in the directory, or a sub-directory.
In the HelloWorld example app for instance, there is a Kbuild file in the root (https://github.com/bitcraze/crazyflie-f ... rld/Kbuild) that includes the /src sub dir with
In the /src dir there is another Kbuild file (https://github.com/bitcraze/crazyflie-f ... src/Kbuild) that includes the object file
Object (.o) files are added to the build using Kbuild files in the new make system. Each directory must have one Kbuild file that adds the files in the directory, or a sub-directory.
In the HelloWorld example app for instance, there is a Kbuild file in the root (https://github.com/bitcraze/crazyflie-f ... rld/Kbuild) that includes the /src sub dir with
Code: Select all
obj-y += src/
Code: Select all
obj-y += hello_world.o
-
- Beginner
- Posts: 28
- Joined: Sun Sep 08, 2019 12:44 pm
- Contact:
Re: Header files in application
Yes, this was clear. However, in case my app also contains some sub-folders that contain header files .h, how do I specify in the Makefile the location of these .h files? Because I currently get a compilation error: the .h files are not found.
Re: Header files in application
I think easiest is to use the path to the .h file. I think that path is relative to the .c file that is including it, e.g.
Code: Select all
#include "inc/my_header_file.h"
-
- Beginner
- Posts: 28
- Joined: Sun Sep 08, 2019 12:44 pm
- Contact:
Re: Header files in application
Thank you for the reply! The solution would for sure work, but if multiple .c files include some .h files from an external library, each user would have to modify all .c files and adjust the library path. It was quite nice before when one could specify in the Makefile where the compiler should look for the .h files.
-
- Bitcraze
- Posts: 630
- Joined: Tue Jun 30, 2015 7:47 am
Re: Header files in application
I found a way
You can add
to your make file
An example added in https://github.com/bitcraze/crazyflie-f ... /pull/1001
You can add
Code: Select all
EXTRA_CFLAGS += -I$(PWD)/other
An example added in https://github.com/bitcraze/crazyflie-f ... /pull/1001
-
- Beginner
- Posts: 28
- Joined: Sun Sep 08, 2019 12:44 pm
- Contact:
Re: Header files in application
Thank you! I managed to get it working when the .h files are all in one folder. However, when I have two folders with .h files, for instance, other0 and other1, it will only detect the .h files from the folder that was first assigned to EXTRA_CFLAGS.
For example, if I have
Now only the .h files in other0 will be seen, still giving error for not finding the ones in other1.
If I change the order to
this will only see the ones in other1.
I also tried
but I get the same. Do you have any idea why this could happen?
For example, if I have
Code: Select all
EXTRA_CFLAGS += -I$(PWD)/other0 -I$(PWD)/other1
If I change the order to
Code: Select all
EXTRA_CFLAGS += -I$(PWD)/other1 -I$(PWD)/other0
I also tried
Code: Select all
EXTRA_CFLAGS += -I$(PWD)/other0
EXTRA_CFLAGS += -I$(PWD)/other1
-
- Bitcraze
- Posts: 630
- Joined: Tue Jun 30, 2015 7:47 am
Re: Header files in application
Interesting!
I pretty much have no idea why, sorry!
I pretty much have no idea why, sorry!