4k views
in System Integration by

I have a custom driver file for that I have built for the Raspberry Pi 3. The driver file needs these includes:

#include <iostream>
#include <errno.h>
#include <wiringPiI2C.h>
#include <unistd.h>

How do I modify the makefile to know about my driver file and the location of the includes?

1 Answer

0 votes
by

Hello,

I assume you are using the Template project of our Build Environment for the Raspberry Pi. In this case, you can edit the makefile that you will find within the subdirectory /Template.

Within the section for includes you can add the path to your include files:

###############################################################################
# INCLUDES
###############################################################################
INCLUDES =                                                                     \
            -I.                                                                \
            -I$(EMWI_APP_PATH)                                                 \
            -I$(EMWI_RTE_PATH)                                                 \
            -I$(EMWI_GFX_PATH)                                                 \
            -I$(SDK_PATH)/include                                              \
            -IYourPath                                                         \

The driver C file you can add to the application part:

##############################################################################
# EMBEDDED WIZARD - APPLICATION DEMO
###############################################################################
APP_C =                                                                        \
                    main.c                                                     \
                    YourDriver.c                                               \

I hope this helps...

Best regards,

Manfred.

by

Ok, I added:

DeviceDriver.c                       \

to my make file, and the path to my include directory.

I am now presented with this error:

make: *** No rule to make target 'obj/DeviceDriver.o', needed by 'EmWiApplication'.  Stop.

 

by

Is the DeviceDriver.c file in the same directory as main.c?

Otherwise you should adapt the path for the source files:

###############################################################################
# Standard directories for C files
###############################################################################
vpath %.c           $(EMWI_APP_PATH)                                           \
                    $(EMWI_RTE_PATH)                                           \
                    $(EMWI_GFX_PATH)                                           \
                    YourPath                                                   \

 

by

Great! Thank you. I am now compiling.

I have one last question.

I need to link a library.

Right now my example file is made using this command:

gcc example.c -lwiringPi -o example

I have tried putting -lwiringPi in the Makefile right here:

###############################################################################
# DEFINES
###############################################################################
CFLAGS  = -O2 -Wall -pipe -lwiringPi                                           \
          $(CFLAG_MEMORY_USAGE)                                                \

But this doesn't work as I still get these errors while compiling:

DeviceDriver.c:(.text+0xc8): undefined reference to `wiringPiI2CSetup'
DeviceDriver.c:(.text+0xe8): undefined reference to `wiringPiI2CWrite'

 

by

I think I got it.

I added my flag to the Linking section of the Makefile:

LINKING   = $(LD) $(addprefix -L,$(LIB_PATH)) $(OBJS)                          \
            $(addprefix -L,$(EMWI_RTE_PATH))                                   \
            $(addprefix -L,$(EMWI_GFX_PATH))                                   \
            $(addprefix -l,$(LIBS))                                            \
            -lwiringPi                                                         \
            -o $(BIN_PATH)/$(APP_FILE)

 

by
Yes exactly, the linker has to be aware of the additional library by using -l

Great, that it is now working!

Embedded Wizard Website | Privacy Policy | Imprint

...