Hello everyone,
We have codes written in C language and C++ language.
We have successfully wrote wrapper code and debug using manual command and the code runs good.
Now, we need to eliminate this manual debug step by inserting them into Makefile.
Before that, let me explain the flow.
Our main running code is called
core.c. In
core.c, we called a function named
ARMWashCycle(). This function is written and saved as
arm.c. In function
ARMWashCycle(), we called functions from cpp code and we did a wrapper code for this.
Here is our
arm.c
Code:
#include <stdio.h>
#include <unistd.h>
#include "wrapper.h"
#include "arm.h"
int ARMWashCycle ( )
{
int arm=0;
libInit();
libClose();
return 0;
}
In
core.c, we did include the
arm.h header. This code is debugging fine when we do manual debug using the following command.
Step 1:
Code:
g++ -I<include path needed to compile cpp code> -c -DNUM_DRIVES=6 wrapper.cpp
Step 2:
Code:
gcc <CFLAGS> <PKG_CONFIG> -c core.c motor.c <all sub-code needed....>
Step 3:
Code:
g++ -o core <all object files needed> -lusb <Linker Flags> /home/user/rwc/Source/cmdapi/lib/libRWCCommanderApi.so.1.0.0 /home/user/rwc/Source/lib/lib/libBRBTeam.so.1.0.0
These will debug our code successfully and we can run the code.
Now, when we try to do the Makefile for this,
Makefile:
Code:
#------------------------------------------------------------------------------
# Linker Flags
#------------------------------------------------------------------------------
LDFLAGS := -L../lib
ifeq ($(OS),Linux)
LDFLAGS += -L/usr/local/lib -lusb-1.0 -lm -lm /home/user/Source/cmdapi/lib/libRWCCommanderApi.so.1.0.0 -lm /home/user/Source/lib/lib/libBRBTeam.so.1.0.0
else
LDFLAGS += -L../libusb/libusb-win32-src -lusb
endif
#------------------------------------------------------------------------------
# Common rules
#------------------------------------------------------------------------------
%.o: %.c
$(CC) -c $(CFLAGS) -o $@ $<
#------------------------------------------------------------------------------
# Target Builds
#
#------------------------------------------------------------------------------
wrapper.o : wrapper.cpp
g++ -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I../lib/include -I.moc -I. -c -DNUM_DRIVES=6 wrapper.cpp
arm.o : arm.c
g++ -Wall -c arm.c
core : core.o motor.o switch.o analog.o echoclnt.o helper.o mapping.o wrapper.o arm.o
$(CC) -o $@ $^ -lsub $(LDFLAGS)
clean:
rm -f *.o *.out *.err *.exe *.a *.so core
Then, it will give us the following error:
Code:
core.c: In function ‘main’:
core.c:160: warning: implicit declaration of function ‘ARMWashCycle’
core.o: In function `main':
/home/user/rwc/core/core.c:160: undefined reference to `ARMWashCycle'
collect2: ld returned 1 exit status
make: *** [core] Error 1
Anyone knows how can we solve this?
We have tried include the library path in
/etc/ld.so.conf and run "ldconfig". It returns the same result.
When we close the function call of
ARMWashCycle() in
core.c, the debug will be successful.