cherrybombuc
Posts: 24
Joined: Mon Feb 25, 2013 4:59 pm

makefile WiringPi

Thu Aug 28, 2014 2:03 pm

Hi
I'm new on c, I want to add WirringPi on this makefile. I don't know the way. please.

Code: Select all

CFLAGS = -O2 -Wall
CC = gcc
INSTALL = install
TARGET = /usr/sbin

LIB_OBJS=command.o controller.o emitter.o init.o log.o monitor.o navdata.o network.o pilot.o web.o
PROG_OBJS=arpilot.o
LIB=arpilot.a
PROG=arpilot

all: lib arpilot 

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

lib: $(LIB_OBJS)
	ar r $(LIB) $(LIB_OBJS)

arpilot: $(PROG_OBJS) lib
	$(CC) $(CFLAGS) $(PROG_OBJS) $(LIB) -o $(PROG)

install: $(PROG)
	$(INSTALL) $(PROG) $(TARGET)/$(PROG)

clean:
	rm -f $(PROG_OBJS) $(LIB_OBJS) $(PROG) $(LIB)

User avatar
gordon@drogon.net
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: makefile WiringPi

Thu Aug 28, 2014 5:38 pm

cherrybombuc wrote:Hi
I'm new on c, I want to add WirringPi on this makefile. I don't know the way. please.

Code: Select all

CFLAGS = -O2 -Wall
CC = gcc
INSTALL = install
TARGET = /usr/sbin

LIB_OBJS=command.o controller.o emitter.o init.o log.o monitor.o navdata.o network.o pilot.o web.o
PROG_OBJS=arpilot.o
LIB=arpilot.a
PROG=arpilot

all: lib arpilot 

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

lib: $(LIB_OBJS)
	ar r $(LIB) $(LIB_OBJS)

arpilot: $(PROG_OBJS) lib
	$(CC) $(CFLAGS) $(PROG_OBJS) $(LIB) -o $(PROG)

install: $(PROG)
	$(INSTALL) $(PROG) $(TARGET)/$(PROG)

clean:
	rm -f $(PROG_OBJS) $(LIB_OBJS) $(PROG) $(LIB)
Add a separate line after your LIB=arpilot.a line:

Code: Select all

EXTRA_LIBS=-lwiringPi
then in your link section (make target arpilot: append

Code: Select all

$(EXTRA_LIBS)
so it looks like:

Code: Select all

arpilot: $(PROG_OBJS) lib
   $(CC) $(CFLAGS) $(PROG_OBJS) $(LIB) -o $(PROG) $(EXTRA_LIBS)
If using trig/math functions, you can add -lm after -lwiringPi too (and any other system libs if needed)
-Gordon
--
Gordons projects: https://projects.drogon.net/

cherrybombuc
Posts: 24
Joined: Mon Feb 25, 2013 4:59 pm

Re: makefile WiringPi

Fri Aug 29, 2014 3:41 am

thank you so much!!!!

hassanahmed
Posts: 1
Joined: Sun Oct 01, 2017 9:55 am

Re: makefile WiringPi

Sun Oct 01, 2017 8:51 pm

bro i got the same errors in making the file :(

undefined reference to "wiringPiSetup"
undefined reference to "pinMode"
undefined reference to "digitalRead"
undefined reference to "serialOpen"

how can i remove this errors please help

jahboater
Posts: 5759
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: makefile WiringPi

Mon Oct 02, 2017 8:03 am

Did you follow Gordon's instructions exactly? to the letter?
Perhaps double check it, and post your makefile.

Return to “C/C++”