cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Participant
Participant
9,295 Views
Registered: ‎02-25-2014

How can I include header files outside of my current directory

Dear all

 

I am using Petalinux 2014.4. I try to include a header file out of my current directory. The following is the Makefile:

 

ifndef PETALINUX

$(error "Error: PETALINUX environment variable not set. Change to the root of your PetaLinux install, and source the settings.sh file")

endif

include apps.common.mk

APP = dspclient

 

INC_DIR =  ../../include/

CCFLAGS = -c -Wall  -I$(INC_DIR))

DFPS = /include/ctrlreq.h

 

# Add any other object files to this list below

APP_OBJS = dspclient.o

APP_OBJS += process_mb_message.o

APP_OBJS += process_ps_message.o

APP_OBJS += process_analog_data.o

 

all: build install

build: $(APP)

$(APP): $(APP_OBJS)

$(CC) $(LDFLAGS) -o $@ $(APP_OBJS) $(LDLIBS)

clean:

-rm -f $(APP) *.elf *.gdb *.o

.PHONY: install image

install: $(APP)

$(TARGETINST) -d $(APP) /bin/$(APP)

%.o: %.c

$(CC) -c $(CFLAGS) -o $@ $<

 

This Makefile and all four source files are located in the current directory called dspclient. The dspclient.c contains a line that includes a head file (ctrlreq.h) outside of the current directory as below:

 

// in dspclient.c

#include "include/ctrlreq.h"

 

The head file is located at two level above the current directory and then in a subdirectory called include. When I built the project using petalinux-build. I got the following error message.

 

fatal error: include/ctrlreq.h: no such file or directory

#include "include/ctrlreq.h"

 

compilation terminated

 

I have searched the forum, it seems I cannot find the information. I am very grateful if anybody can help me out.

 

Lee

 

 

0 Kudos
2 Replies
Highlighted
Xilinx Employee
Xilinx Employee
9,254 Views
Registered: ‎02-20-2014

Re: How can I include header files outside of my current directory

Hi ,

 

Ensure that INC_DIR is added as a compiler search option.

 

NOTE: "myapp" is the name of sample application.

Edit : myapp/Makefile

%.o: %.c
$(CC)  -I$(INC_DIR)  -c $(CFLAGS) -o $@ $<

 

 

And include path is relative to build directory.

build/linux/rootfs/apps/myapp

INC_DIR= ../../../../../include

 

Hope it helps.

-Radhey

0 Kudos
Highlighted
Participant
Participant
9,235 Views
Registered: ‎02-25-2014

Re: How can I include header files outside of my current directory

Hi, Radhey

 

The problem solved after I manually copied the "include" directory from the " <pln_proj_roots>/component" directory to the "<pln_proj_roots>/build/linux/rootfs". Is there any way I can generate an "include" director in " <pln_proj_roots>/component" directory which includes all the common header files using petalinux-create and then this directory can be copied to the "<pln_proj_roots>/build/linux/rootfs" directory automatically when I run petalinux-build?

 

Many thanks.

 

Lee

0 Kudos