IntermediateRobotFunctions.cpp:
/*
* IntermediateRobotFunctions.cpp
*
* Created on: 27 Mar 2015
* Author: Edward
*/
#include "IntermediateRobotFunctions.hpp"
IntermediateRobotFunctions::IntermediateRobotFunctions() {
block = Block::Block();
robot = Robot::Robot();
basic = BasicRobotFunctions::BasicRobotFunctions();
carrying = false;
}
IntermediateRobotFunctions::IntermediateRobotFunctions(Robot R,Block B) {
block = B;
robot = R;
basic = BasicRobotFunctions::BasicRobotFunctions(R);
carrying = false;
}
IntermediateRobotFunctions::~IntermediateRobotFunctions() {}
void IntermediateRobotFunctions::PickUp(Robot R, Block B){
if(R.getCarrying()==false){
Walk(R);
basic.MoveChest();
basic.MoveArm(1);
basic.MoveArm(2);
basic.MoveChest();
R.setCarrying(true);
carrying = true;
}
else{
PutDown(R);
PickUp(R,B);
}
}
void IntermediateRobotFunctions::PutDown(Robot R){
if(R.getCarrying()==true){
basic.MoveChest();
basic.MoveArm(1);
basic.MoveArm(2);
basic.MoveChest();
R.setCarrying(false);
carrying = false;
}
}
//TODO to test
Block IntermediateRobotFunctions::newNearest(){
Block B,B1;
B1 = Block::Block();
for(int i = 0; i<360; i++){
basic.Turn(1);
if(dxl_read_word(100,32)>0){
B = Block::Block();
B.setDistance(dxl_read_word(100,27));
B.setBrightness(dxl_read_word(100,30));
B.setGrounded(true);
}
if(B.getDistance() <= B1.getDistance()){
B1 = B;
}
}
return B1;
}
Robot IntermediateRobotFunctions::updateRobotData(){
Block block;
bool carry = carrying;
block = newNearest(robot);
Robot R = Robot(block,carry);
return R;
}
//TODO to test
void IntermediateRobotFunctions::Walk(Robot R){
int steps = basic.CalculateSteps();
while(dxl_read_word(100,32)<=0)
basic.Turn(1);
for(int i =0;i<steps;i++){
basic.Step(1);
basic.Step(2);
}
}
IntermediateRobotFunctions.hpp:
/*
* IntermediateRobotFunctions.hpp
*
* Created on: 27 Mar 2015
* Author: Edward
*/
#ifndef INTERMEDIATEROBOTFUNCTIONS_HPP_
#define INTERMEDIATEROBOTFUNCTIONS_HPP_
#include "typedefinitions.h"
#include "Robot.hpp"
#include "Block.hpp"
#include "BasicRobotFunctions.hpp"
class IntermediateRobotFunctions {
public:
static Block block;
static Robot robot;
static BasicRobotFunctions basic;
static bool carrying;
//pos position;
static void PickUp(Robot R, Block B);
static void PutDown(Robot R);
static void Walk(Robot R);
static Block newNearest(Robot R);
static Block newNearest();
static Robot updateRobotData();
IntermediateRobotFunctions();
IntermediateRobotFunctions(Robot R,Block B);
virtual ~IntermediateRobotFunctions();
};
#endif /* INTERMEDIATEROBOTFUNCTIONS_HPP_ */
Makefile:
# Hey Emacs, this is a -*- makefile -*-
#----------------------------------------------------------------------------
# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.
#
# Released to the Public Domain
#
# Additional material for this makefile was written by:
# Peter Fleury
# Tim Henigan
# Colin O'Flynn
# Reiner Patommel
# Markus Pfaff
# Sander Pool
# Frederik Rouleau
# Carlos Lamas
#
#----------------------------------------------------------------------------
# On command line:
#
# make all = Make software.
#
# make clean = Clean out built project files.
#
# make coff = Convert ELF to AVR COFF.
#
# make extcoff = Convert ELF to AVR Extended COFF.
#
# make program = Download the hex file to the device, using avrdude.
# Please customize the avrdude settings below first!
#
# make debug = Start either simulavr or avarice as specified for debugging,
# with avr-gdb or avr-insight as the front end for debugging.
#
# make filename.s = Just compile filename.c into the assembler code only.
#
# make filename.i = Create a preprocessed source file for use in submitting
# bug reports to the GCC project.
#
# To rebuild project do "make clean" then "make all".
#----------------------------------------------------------------------------
# MCU name
MCU = atmega128
# Processor frequency.
# This will define a symbol, F_CPU, in all source code files equal to the
# processor frequency. You can then use this symbol in your source code to
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
# automatically to create a 32-bit value in your source code.
# Typical values are:
# F_CPU = 1000000
# F_CPU = 1843200
# F_CPU = 2000000
# F_CPU = 3686400
# F_CPU = 4000000
# F_CPU = 7372800
# F_CPU = 8000000
# F_CPU = 11059200
# F_CPU = 14745600
# F_CPU = 16000000
# F_CPU = 18432000
# F_CPU = 20000000
F_CPU = 16000000
# Output format. (can be srec, ihex, binary)
FORMAT = ihex
# Target file name (without extension).
TARGET = main
# Object files directory
# To put object files in current directory, use a dot (.), do NOT make
# this an empty or blank macro!
OBJDIR = .
# List C source files here. (C dependencies are automatically generated.)
SRC =
# List C++ source files here. (C dependencies are automatically generated.)
CPPSRC = $(TARGET).cpp AdvancedRobotFunctions.cpp IntermediateRobotFunctions.cpp BasicRobotFunctions.cpp Robot.cpp Block.cpp Structure.cpp
# List Assembler source files here.
# Make them always end in a capital .S. Files ending in a lowercase .s
# will not be considered source files but generated files (assembler
# output from the compiler), and will be deleted upon "make clean"!
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
ASRC =
# Optimization level, can be [0, 1, 2, 3, s].
# 0 = turn off optimization. s = optimize for size.
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = s
# Debugging format.
# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
# AVR Studio 4.10 requires dwarf-2.
# AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
DEBUG = dwarf-2
# List any extra directories to look for include files here.
# Each directory must be seperated by a space.
# Use forward slashes for directory separators.
# For a directory that has spaces, enclose it in quotes.
EXTRAINCDIRS =
# Compiler flag to set the C Standard level.
# c89 = "ANSI" C
# gnu89 = c89 plus GCC extensions
# c99 = ISO C99 standard (not yet fully implemented)
# gnu99 = c99 plus GCC extensions
CSTANDARD = -std=gnu99
# Place -D or -U options here for C sources
CDEFS = -DF_CPU=$(F_CPU)UL
# Place -D or -U options here for ASM sources
ADEFS = -DF_CPU=$(F_CPU)
# Place -D or -U options here for C++ sources
CPPDEFS = -DF_CPU=$(F_CPU)UL
#CPPDEFS += -D__STDC_LIMIT_MACROS
#CPPDEFS += -D__STDC_CONSTANT_MACROS
#---------------- Compiler Options C ----------------
# -g*: generate debugging information
# -O*: optimization level
# -f...: tuning, see GCC manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns...: create assembler listing
CFLAGS = -g$(DEBUG)
CFLAGS += $(CDEFS)
CFLAGS += -O$(OPT)
CFLAGS += -funsigned-char
CFLAGS += -funsigned-bitfields
CFLAGS += -fpack-struct
CFLAGS += -fshort-enums
CFLAGS += -Wall
CFLAGS += -Wstrict-prototypes
#CFLAGS += -mshort-calls
#CFLAGS += -fno-unit-at-a-time
#CFLAGS += -Wundef
#CFLAGS += -Wunreachable-code
#CFLAGS += -Wsign-compare
CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += $(CSTANDARD)
#---------------- Compiler Options C++ ----------------
# -g*: generate debugging information
# -O*: optimization level
# -f...: tuning, see GCC manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns...: create assembler listing
CPPFLAGS = -g$(DEBUG)
CPPFLAGS += $(CPPDEFS)
CPPFLAGS += -O$(OPT)
CPPFLAGS += -funsigned-char
CPPFLAGS += -funsigned-bitfields
CPPFLAGS += -fpack-struct
CPPFLAGS += -fshort-enums
CPPFLAGS += -fno-exceptions
CPPFLAGS += -Wall
CPPFLAGS += -Wundef
#CPPFLAGS += -mshort-calls
#CPPFLAGS += -fno-unit-at-a-time
#CPPFLAGS += -Wstrict-prototypes
#CPPFLAGS += -Wunreachable-code
#CPPFLAGS += -Wsign-compare
CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
CPPFLAGS += $(CSTANDARD)
#---------------- Assembler Options ----------------
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns: create listing
# -gstabs: have the assembler create line number information; note that
# for use in COFF files, additional information about filenames
# and function names needs to be present in the assembler source
# files -- see avr-libc docs [FIXME: not yet described there]
# -listing-cont-lines: Sets the maximum number of continuation lines of hex
# dump that will be displayed for a given single line of source input.
ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
#---------------- Library Options ----------------
# Minimalistic printf version
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
# Floating point printf version (requires MATH_LIB = -lm below)
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
# If this is left blank, then it will use the Standard printf version.
PRINTF_LIB =
#PRINTF_LIB = $(PRINTF_LIB_MIN)
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
# Minimalistic scanf version
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
# If this is left blank, then it will use the Standard scanf version.
SCANF_LIB =
#SCANF_LIB = $(SCANF_LIB_MIN)
#SCANF_LIB = $(SCANF_LIB_FLOAT)
MATH_LIB = -lm
# List any extra directories to look for libraries here.
# Each directory must be seperated by a space.
# Use forward slashes for directory separators.
# For a directory that has spaces, enclose it in quotes.
EXTRALIBDIRS =
#---------------- External Memory Options ----------------
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# used for variables (.data/.bss) and heap (malloc()).
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# only used for heap (malloc()).
#EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
EXTMEMOPTS =
#---------------- Linker Options ----------------
# -Wl,...: tell GCC to pass this to linker.
# -Map: create map file
# --cref: add cross reference to map file
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
LDFLAGS += $(EXTMEMOPTS)
LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
#LDFLAGS += -T linker_script.x
#---------------- Programming Options (avrdude) ----------------
# Programming hardware
# Type: avrdude -c ?
# to get a full listing.
#
AVRDUDE_PROGRAMMER = stk500v2
# com1 = serial port. Use lpt1 to connect to parallel port.
AVRDUDE_PORT = com3 # programmer connected to serial device
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
# Uncomment the following if you want avrdude's erase cycle counter.
# Note that this counter needs to be initialized first using -Yn,
# see avrdude manual.
#AVRDUDE_ERASE_COUNTER = -y
# Uncomment the following if you do /not/ wish a verification to be
# performed after programming the device.
#AVRDUDE_NO_VERIFY = -V
# Increase verbosity level. Please use this when submitting bug
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
# to submit bug reports.
#AVRDUDE_VERBOSE = -v -v
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
#---------------- Debugging Options ----------------
# For simulavr only - target MCU frequency.
DEBUG_MFREQ = $(F_CPU)
# Set the DEBUG_UI to either gdb or insight.
# DEBUG_UI = gdb
DEBUG_UI = insight
# Set the debugging back-end to either avarice, simulavr.
DEBUG_BACKEND = avarice
#DEBUG_BACKEND = simulavr
# GDB Init Filename.
GDBINIT_FILE = __avr_gdbinit
# When using avarice settings for the JTAG
JTAG_DEV = /dev/com1
# Debugging port used to communicate between GDB / avarice / simulavr.
DEBUG_PORT = 4242
# Debugging host used to communicate between GDB / avarice / simulavr, normally
# just set to localhost unless doing some sort of crazy debugging when
# avarice is running on a different computer.
DEBUG_HOST = localhost
#============================================================================
# Define programs and commands.
SHELL = sh
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
AR = avr-ar rcs
NM = avr-nm
AVRDUDE = avrdude
REMOVE = rm -f
REMOVEDIR = rm -rf
COPY = cp
WINSHELL = cmd
# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin --------
MSG_END = -------- end --------
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
MSG_COFF = Converting to AVR COFF:
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
MSG_FLASH = Creating load file for Flash:
MSG_EEPROM = Creating load file for EEPROM:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling C:
MSG_COMPILING_CPP = Compiling C++:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:
MSG_CREATING_LIBRARY = Creating library:
# Define all object files.
OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
# Define all listing files.
LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
# Compiler flags to generate dependency files.
GENDEPFLAGS = -MMD -MP -MF .dep/$(#F).d
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
# Default target.
all: begin gccversion sizebefore build sizeafter end
# Change the build target to build a HEX file or a library.
build: elf hex eep lss sym
#build: lib
elf: $(TARGET).elf
hex: $(TARGET).hex
eep: $(TARGET).eep
lss: $(TARGET).lss
sym: $(TARGET).sym
LIBNAME=lib$(TARGET).a
lib: $(LIBNAME)
# Eye candy.
# AVR Studio 3.x does not check make's exit code but relies on
# the following magic strings to be generated by the compile job.
begin:
#echo
#echo $(MSG_BEGIN)
end:
#echo $(MSG_END)
#echo
# Display size of file.
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
sizebefore:
#if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
2>/dev/null; echo; fi
sizeafter:
#if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
2>/dev/null; echo; fi
# Display compiler version information.
gccversion :
#$(CC) --version
# Program the device.
program: $(TARGET).hex $(TARGET).eep
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
# Generate avr-gdb config/init file which does the following:
# define the reset signal, load the target file, connect to target, and set
# a breakpoint at main().
gdb-config:
#$(REMOVE) $(GDBINIT_FILE)
#echo define reset >> $(GDBINIT_FILE)
#echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
#echo end >> $(GDBINIT_FILE)
#echo file $(TARGET).elf >> $(GDBINIT_FILE)
#echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
ifeq ($(DEBUG_BACKEND),simulavr)
#echo load >> $(GDBINIT_FILE)
endif
#echo break main >> $(GDBINIT_FILE)
debug: gdb-config $(TARGET).elf
ifeq ($(DEBUG_BACKEND), avarice)
#echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
#$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
#$(WINSHELL) /c pause
else
#$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
$(DEBUG_MFREQ) --port $(DEBUG_PORT)
endif
#$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT = $(OBJCOPY) --debugging
COFFCONVERT += --change-section-address .data-0x800000
COFFCONVERT += --change-section-address .bss-0x800000
COFFCONVERT += --change-section-address .noinit-0x800000
COFFCONVERT += --change-section-address .eeprom-0x810000
coff: $(TARGET).elf
#echo
#echo $(MSG_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
extcoff: $(TARGET).elf
#echo
#echo $(MSG_EXTENDED_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
#echo
#echo $(MSG_FLASH) $#
$(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock $< $#
%.eep: %.elf
#echo
#echo $(MSG_EEPROM) $#
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $# || exit 0
# Create extended listing file from ELF output file.
%.lss: %.elf
#echo
#echo $(MSG_EXTENDED_LISTING) $#
$(OBJDUMP) -h -S -z $< > $#
# Create a symbol table from ELF output file.
%.sym: %.elf
#echo
#echo $(MSG_SYMBOL_TABLE) $#
$(NM) -n $< > $#
# Create library from object files.
.SECONDARY : $(TARGET).a
.PRECIOUS : $(OBJ)
%.a: $(OBJ)
#echo
#echo $#
#echo $(MSG_CREATING_LIBRARY) $#
$(AR) $# $(OBJ)
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
#echo
#echo $(MSG_LINKING) $#
$(CC) $(ALL_CFLAGS) $^ --output $# $(LDFLAGS)
# Compile: create object files from C source files.
$(OBJDIR)/%.o : %.c
#echo
#echo $(MSG_COMPILING) $<
$(CC) -c $(ALL_CFLAGS) $< -o $#
# Compile: create object files from C++ source files.
$(OBJDIR)/%.o : %.cpp
#echo
#echo $(MSG_COMPILING_CPP) $<
$(CC) -c $(ALL_CPPFLAGS) $< -o $#
# Compile: create assembler files from C source files.
%.s : %.c
$(CC) -S $(ALL_CFLAGS) $< -o $#
# Compile: create assembler files from C++ source files.
%.s : %.cpp
$(CC) -S $(ALL_CPPFLAGS) $< -o $#
# Assemble: create object files from assembler source files.
$(OBJDIR)/%.o : %.S
#echo
#echo $(MSG_ASSEMBLING) $<
$(CC) -c $(ALL_ASFLAGS) $< -o $#
# Create preprocessed source for use in sending a bug report.
%.i : %.c
$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $#
# Target: clean project.
clean: begin clean_list end
clean_list :
#echo
#echo $(MSG_CLEANING)
$(REMOVE) $(TARGET).hex
$(REMOVE) $(TARGET).eep
$(REMOVE) $(TARGET).cof
$(REMOVE) $(TARGET).elf
$(REMOVE) $(TARGET).map
$(REMOVE) $(TARGET).sym
$(REMOVE) $(TARGET).lss
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)
$(REMOVE) $(SRC:.c=.s)
$(REMOVE) $(SRC:.c=.d)
$(REMOVE) $(SRC:.c=.i)
$(REMOVEDIR) .dep
# Create object files directory
$(shell mkdir $(OBJDIR) 2>/dev/null)
# Include the dependency files.
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion \
build elf hex eep lss sym coff extcoff \
clean clean_list program debug gdb-config
First of all I would like to apologize for the length of the code.
I've been getting errors in my Makefile stating that the "block", "robot", "basic", and "carrying" variables called in the constructors and in various methods in this source file have undefined references to their header file definitions
The errors are as follows:
IntermediateRobotFunctions.o: In function `IntermediateRobotFunctions::updateRobotData()':
C:\Users\Edward\CWork\BioloidAVR_/IntermediateRobotFunctions.cpp:74: undefined reference to `IntermediateRobotFunctions::carrying'
C:\Users\Edward\CWork\BioloidAVR_/IntermediateRobotFunctions.cpp:75: undefined reference to `IntermediateRobotFunctions::robot'
C:\Users\Edward\CWork\BioloidAVR_/IntermediateRobotFunctions.cpp:75: undefined reference to `IntermediateRobotFunctions::robot'
C:\Users\Edward\CWork\BioloidAVR_/IntermediateRobotFunctions.cpp:75: undefined reference to `IntermediateRobotFunctions::newNearest(Robot)'
where the above errors are repeated for all variables in every method of all of the following classes:
BasicRobotFunctions
IntermediateRobotFunctions
AdvancedRobotFunctions
Robot
Block
Structure
including on variables and methods received from pre-made source and header files imported from the Bioloid Embedded C API.
Again apologies for a long post possibly including a little irrelevant information but I wanted to give the complete picture; can anyone please tell me what's wrong and how I should go about fixing it?
You have this:
class IntermediateRobotFunctions {
public:
static Block block;
static Robot robot;
static BasicRobotFunctions basic;
static bool carrying;
where you have declared these variables to be static, but you have not put this:
Block IntermediateRobotFunctions::block;
Robot IntermediateRobotFunctions::robot;
BasicRobotFunctions IntermediateRobotFunctions::basic;
bool IntermediateRobotFunctions::carrying;
any place in your .cpp files, which means you have not actually defined (set aside actual memory for) those variables anywhere. That's what the compiler messages are telling you - the variables can't be found when it's trying to fix up all the various address links...
Related
This question already has answers here:
Makefile to compile multiple C programs?
(8 answers)
Closed 28 days ago.
I want to compile all the cpp files in my current directory into their own executables with one call. None of these files share anything so they don't need to be compiled into a single program. I was thinking about using a script but then I remembered about make and makefiles (haven't used it in years). Can I write a makefile to do this?
This post answers your question. It is about C programs but you can adapt it to C++.
Makefile to compile multiple C programs?
Thanks to #Robert, I have copied his Makefile from https://stackoverflow.com/a/13696012/1860805
And made changes to work with C++. Hope it works for you
############################################################################
# 'A Generic Makefile for Building Multiple main() Targets in $PWD'
# Author: Robert A. Nader (2012)
# Ramanan.T : Modified to work with C++ (2023)
# Email: naderra at some g
# Web: xiberix
############################################################################
#
# The purpose of this makefile is to compile to executable all C source
# files in CWD, where each .c file has a main() function, and each object
# links with a common LDFLAG.
#
# This makefile should suffice for simple projects that require building
# similar executable targets. For example, if your CWD build requires
# exclusively this pattern:
#
# cc -c $(CFLAGS) main_01.cpp
# cc main_01.o $(LDFLAGS) -o main_01
#
# cc -c $(CFLAGS) main_2..cpp
# cc main_02.o $(LDFLAGS) -o main_02
#
# etc, ... a common case when compiling the programs of some chapter,
# then you may be interested in using this makefile.
#
# What YOU do:
#
# Set PRG_SUFFIX_FLAG below to either 0 or 1 to enable or disable
# the generation of a .exe suffix on executables
#
# Set CFLAGS and LDFLAGS according to your needs.
#
# What this makefile does automagically:
#
# Sets SRC to a list of *.c files in PWD using wildcard.
# Sets PRGS BINS and OBJS using pattern substitution.
# Compiles each individual .c to .o object file.
# Links each individual .o to its corresponding executable.
#
###########################################################################
#
PRG_SUFFIX_FLAG := 0
#
CFLAGS_INC :=
CFLAGS := -g -Wall $(CFLAGS_INC)
CXXFLAGS = -m64 -O0 -g3 -Wall -DUNIX=1 -DMETA=1
LDFLAGS = -g3 -O0 -m64
#
## ==================- NOTHING TO CHANGE BELOW THIS LINE ===================
##
SRCS := $(wildcard *.cpp)
PRGS := $(patsubst %.cpp,%,$(SRCS))
PRG_SUFFIX=.exe
BINS := $(patsubst %,%$(PRG_SUFFIX),$(PRGS))
## OBJS are automagically compiled by make.
OBJS := $(patsubst %,%.o,$(PRGS))
##
all : $(BINS)
##
## For clarity sake we make use of:
.SECONDEXPANSION:
OBJ = $(patsubst %$(PRG_SUFFIX),%.o,$#)
ifeq ($(PRG_SUFFIX_FLAG),0)
BIN = $(patsubst %$(PRG_SUFFIX),%,$#)
else
BIN = $#
endif
## Compile the executables
%$(PRG_SUFFIX) : $(OBJS)
$(CXX) $(OBJ) $(CXXFLAGS) $(LDFLAGS) -o $(BIN)
##
## $(OBJS) should be automagically removed right after linking.
##
clean:
ifeq ($(PRG_SUFFIX_FLAG),0)
$(RM) $(PRGS) $(OBJS)
else
$(RM) $(BINS) $(OBJS)
endif
##
rebuild: clean all
##
## eof Generic_Multi_Main_PWD.makefile
I am trying to compile using Vrxcc Compiler in VeriFone sdk.
when i want to create a graphical application for Vx675 pose Payment, The compiler show this error
error : L6218E: Undefined symbol VxGUI::VxGUI() (referred from Main.o)
Main.cpp is
#include <stdio.h>
#include <svc.h>
#include <svc_gui.h>
void main()
{
VxGUI *m_GUIObj;
m_GUIObj = new VxGUI();
}
And the MakeFile is
#
################### Paths ##################
#
ACTIncludes = $(EVOACT)include
EOSIncludes = $(EOSSDK)\include
GUIIncludes = $(GUISDK)\Include
CardslotInclude=$(VCARDSLOT)\Include
DTKTOOLS=C:\eVoAps\Tools
################### App Source Paths ##################
SrcDir = .
################### Compiler/Linker/Outhdr Output Paths ##################
ObjDir = .\vobj
OutDir = .\vbin
###################for release...##################
ACTStaticLibraries = $(EVOACT)\Output\RV\Files\Static\Release
ACTSharedLibraries = $(EVOACT)\OutPut\RV\Files\Shlib1\Release
VMACLibraries = $(EVOVMAC)\Output\RV\Lib\Files\Debug
EOSLibararuies = $(EOSSDK)\lib
GUISDKLibraries= $(GUISDK)\lib
VRXSDKLobraries= $(EVOSDK)\lib
VCARDSLOTLobraries= $(VCARDSLOT)\Output\RV\Files\Static
#
######################### Options for Tools ########################
#
############# Compiler Options ############
Includes = -I$(ACTIncludes) -I$(EOSIncludes) -I$(GUIIncludes) -I$(CardslotInclude)
# for release version change the COptions to
#COptions = -DLOGSYS_FLAG -DVERIFONE
COptions = -D_VERIFONE -DVERIFONE -DEVO -p -W -D ARM -D _ARM -g -D _MAKE_VX_
VRXHDRPARAM= -s 300000 -h 4000000
#
######################### Dependencies ########################
#
AppObjects = $(ObjDir)\Main.o
#Using ACT static library.
ACTLibs = \
$(ACTStaticLibraries)\act2000.a \
$(EOSLibararuies)\CEIF.o \
$(EOSLibararuies)\svc_net.o \
$(EOSLibararuies)\elog.o \
$(GUISDKLibraries)\libvxguisdk.so
#
######################### sample Target Definition ########################
#
pseudoOut : $(OutDir)\Hello.out
$(EVOSDK)\bin\vrxhdr $(VRXHDRPARAM) -l ceif.lib=N:/ceif.lib -l net.lib=N:/net.lib -l elog.lib=N:/elog.lib $(OutDir)\Hello.out
$(OutDir)\Hello.out : $(AppObjects)
$(EVOSDK)\bin\vrxcc -map -p $(AppObjects) $(ACTLibs) -o Hello.out
move Hello.out $(OutDir)
del /F /Q $(ObjDir)\*.o
######################## Compile #########################
$(ObjDir)\Main.o : $(SrcDir)\Main.cpp
$(EVOSDK)\bin\vrxcc -c $(Includes) $(COptions) $(SrcDir)\Main.cpp -e"-" | "$(DTKTOOLS)\fmterrorARM.exe"
move Main.o $(ObjDir)\Main.o
please help me to resolve this problem.
Have fixed the problem above?
If not, please pay attention that, when you use the libvxgui, you must use C++ syntax and generate a .vso file instead of .out bin file.
insert the -vsoapp option in the CC and Link options and the output must be .vso file.
COptions = -g -b -p -vsoapp -map -armcc,"--diag_suppress 1300\,611\,9,--apcs=/fpic --export_all_vtbl" -DLOGSYS_FLAG -DLOGSYS_NEW_API_STYLE
LOptions = -g -p -vsoapp -b -k -map
$(VRXSDK)/bin/vrxcc $(LOptions) $(AppObjects) $(Libs) -o $#
$(VRXSDK)/bin/vrxhdr -s $(STACK_SIZE) -h $(HEAP_SIZE) -lnet.lib=N:/net.lib -lceif.lib=N:/ceif.lib -lssl.lib=N:/ssl.lib -lelog.lib=N:/elog.lib $(OutDir)/$(OutFile)
$(ObjDir)/%.o: $(SrcFiles)/%.c
$(VRXSDK)/bin/vrxcc -c $(COptions) $(Includes) $< -o $#
$(ObjDir)/%.o: $(SrcFiles)/%.cpp
$(VRXSDK)/bin/vrxcc -c $(COptions) $(Includes) $< -o $#
I have used VxGUI and including with QT Objects with success.
If you have more problems, let me know. I can send a working project to you.
Best regards,
Leandro
I`m having a Project with some subdirectories. I want to compile them with one makefile per Directory and link all Output files into one executable. Can anyone explain me, which commands I should use (-c or -g or extra call)?
makefile in my root-directory:
LIBS =
# The test will be called in this file. There is no need to change this.
#SRCS = main_test.c
SRCS = min.c max.c
###############################################################################
# #
# Normally it is not needed to edited below this. #
# #
###############################################################################
#SRCS = main_test.c Automated.c Basic.c Console.c CUCurses.c CUError.c Cunit_intl.c \
# MyMem.c TestDB.c TestRun.c Util.c wxWidget.c main_test.c \
# $(TST_SRCS)
# define the C object files
#
# This uses Suffix Replacement within a macro:
# $(name:string1=string2)
# For each word in 'name' replace 'string1' with 'string2'
OBJ = $(SRCS:%.c=%.o)
# define the C compiler to use
CC = gcc
# define any compile-time flags
ODIR = out
#compile and link
#CFLAGS = -O0 -g -Wall -fmessage-length=0 -fprofile-arcs -ftest-coverage
#compile without link
CFLAGS = -O0 -c -Wall -fmessage-length=0 -fprofile-arcs -ftest-coverage
#TODO Linkerflags
LFLAGS = --coverage
#VPATH=test
#VPATH=source
# define the executable file,
TARGET = CUnit
export COVERAGE = $(TST_SRCS)
export STUBS = $(STUB_SRCS)
all:
$(MAKE) -C stub
$(MAKE) -C source
#echo --- build finished ---
#echo.
#echo TODO
#echo --- start linking ---
#echo.
and makefile of subdirectory
# define any directories containing header files other than /usr/include
# TODO
# define any libraries to link into executable:
# if I want to link in libraries (libx.so or libx.a) I use the -llibname
# option, something like (this will link in libmylib.so and libm.so:
LIBS =
# TODO define the C source files
SRCS = $(COVERAGE)
# define the C object files
#
# This uses Suffix Replacement within a macro:
# $(name:string1=string2)
# For each word in 'name' replace 'string1' with 'string2'
OBJ = $(SRCS:%.c=%.o)
# define the C compiler to use
CC = gcc
# define any compile-time flags
ODIR = ../out
#compile without link
CFLAGS = -O0 -c -fmessage-length=0 -fprofile-arcs -ftest-coverage
#TODO Linkerflags
LFLAGS = --coverage
# define the executable file,
all: $(TARGET) $(OBJ)
$(CC) $(OBJ) $(CFLAGS) -o $(TARGET) $(LFLAGS) $(OBJ)
#echo +++ build of source finished +++
clean:
$(RM) *.o *~ $(MAIN)
# DO NOT DELETE THIS LINE -- make depend needs it
I it is easier for the linker, if all Output file are in the same Directory. Works this with ODIR?
With the compiler option -c -g I can compile each submake and link the object files together.
CFLAGS = -O0 -Wall -c -g -fmessage-length=0 -fprofile-arcs -ftest-coverage
this is the only line I changed on the make file, which is adding the "*.cpp" to the line:
SRC = $(wildcard *.c *.cpp)
and this is the clean target of the makefile:
# Target: clean project.
clean: begin clean_list end
clean_list :
#echo
#echo $(MSG_CLEANING)
$(REMOVE) $(OBJDIR)/$(TARGET).hex
$(REMOVE) $(OBJDIR)/$(TARGET).eep
$(REMOVE) $(OBJDIR)/$(TARGET).cof
$(REMOVE) $(OBJDIR)/$(TARGET).elf
$(REMOVE) $(OBJDIR)/$(TARGET).map
$(REMOVE) $(OBJDIR)/$(TARGET).sym
$(REMOVE) $(OBJDIR)/$(TARGET).lss
$(REMOVE) $(OBJ)
$(REMOVE) $(LST)
$(REMOVE) $(OBJDIR)/$(SRC:.c=.s)
$(REMOVE) $(OBJDIR)/$(SRC:.c=.d)
$(REMOVE) $(OBJDIR)/.dep/*
And when I run the makefile, it removes all my .cpp file. What did I do wrong?
Thanks in advance.
Jo
Here is the definition of OBJ and LST:
# Define all object files.
OBJ = $(addprefix $(OBJDIR)/,$(SRC:.c=.o)) $(addprefix $(OBJDIR)/,$(ASRC:.S=.o))
# Define all listing files.
LST = $(addprefix $(OBJDIR)/,$(SRC:.c=.lst)) $(addprefix $(OBJDIR)/,$(ASRC:.S=.lst))
This is the complete make file:
# Hey Emacs, this is a -*- makefile -*-
#----------------------------------------------------------------------------
# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.
#
# Released to the Public Domain
#
# Additional material for this makefile was written by:
# Peter Fleury
# Tim Henigan
# Colin O'Flynn
# Reiner Patommel
# Markus Pfaff
# Sander Pool
# Frederik Rouleau
#
#----------------------------------------------------------------------------
# On command line:
#
# make all = Make software.
#
# make clean = Clean out built project files.
#
# make coff = Convert ELF to AVR COFF.
#
# make extcoff = Convert ELF to AVR Extended COFF.
#
# make program = Download the hex file to the device, using avrdude.
# Please customize the avrdude settings below first!
#
# make debug = Start either simulavr or avarice as specified for debugging,
# with avr-gdb or avr-insight as the front end for debugging.
#
# make filename.s = Just compile filename.c into the assembler code only.
#
# make filename.i = Create a preprocessed source file for use in submitting
# bug reports to the GCC project.
#
# To rebuild project do "make clean" then "make all".
#----------------------------------------------------------------------------
#include conf.mk
# MCU name
MCU = atmega328p
# Processor frequency.
# This will define a symbol, F_CPU, in all source code files equal to the
# processor frequency. You can then use this symbol in your source code to
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
# automatically to create a 32-bit value in your source code.
F_CPU = 8000000
AVRDUDE_PROGRAMMER = stk500v1
# com1 = serial port. Use lpt1 to connect to parallel port.
AVRDUDE_PORT = /dev/cu.wchusbserial1420 # programmer connected to serial device
# Output format. (can be srec, ihex, binary)
FORMAT = ihex
# Target file name (without extension).
TARGET = main
# List C source files here. (C dependencies are automatically generated.)
SRC = $(wildcard *.c *.cpp)
OBJDIR = Builds
# List Assembler source files here.
# Make them always end in a capital .S. Files ending in a lowercase .s
# will not be considered source files but generated files (assembler
# output from the compiler), and will be deleted upon "make clean"!
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
ASRC =
# Optimization level, can be [0, 1, 2, 3, s].
# 0 = turn off optimization. s = optimize for size.
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = s
# Debugging format.
# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
# AVR Studio 4.10 requires dwarf-2.
# AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
DEBUG = stabs
# List any extra directories to look for include files here.
# Each directory must be seperated by a space.
# Use forward slashes for directory separators.
# For a directory that has spaces, enclose it in quotes.
EXTRAINCDIRS =
# Compiler flag to set the C Standard level.
# c89 = "ANSI" C
# gnu89 = c89 plus GCC extensions
# c99 = ISO C99 standard (not yet fully implemented)
# gnu99 = c99 plus GCC extensions
CSTANDARD = -std=c++11
# Place -D or -U options here
CDEFS = -DF_CPU=$(F_CPU)UL
# Place -I options here
CINCS =
#---------------- Compiler Options ----------------
# -g*: generate debugging information
# -O*: optimization level
# -f...: tuning, see GCC manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns...: create assembler listing
CFLAGS = -g$(DEBUG)
CFLAGS += $(CDEFS) $(CINCS)
CFLAGS += -O$(OPT)
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CFLAGS += -Wall -Wstrict-prototypes
CFLAGS += -Wa,-adhlns=$(addprefix $(OBJDIR)/,$(<:.c=.lst))
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += $(CSTANDARD)
CFLAGS += -gstabs
CFLAGS += -gstrict-dwarf
#---------------- Assembler Options ----------------
# -Wa,...: tell GCC to pass this to the assembler.
# -ahlms: create listing
# -gstabs: have the assembler create line number information; note that
# for use in COFF files, additional information about filenames
# and function names needs to be present in the assembler source
# files -- see avr-libc docs [FIXME: not yet described there]
# -listing-cont-lines: Sets the maximum number of continuation lines of hex
# dump that will be displayed for a given single line of source input.
ASFLAGS = -Wa,-adhlns=$(addprefix $(OBJDIR)/,$(<:.S=.lst)),-gstabs,--listing-cont-lines=100
#---------------- Library Options ----------------
# Minimalistic printf version
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
# Floating point printf version (requires MATH_LIB = -lm below)
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
# If this is left blank, then it will use the Standard printf version.
PRINTF_LIB =
#PRINTF_LIB = $(PRINTF_LIB_MIN)
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
# Minimalistic scanf version
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
# If this is left blank, then it will use the Standard scanf version.
SCANF_LIB =
#SCANF_LIB = $(SCANF_LIB_MIN)
#SCANF_LIB = $(SCANF_LIB_FLOAT)
MATH_LIB = -lm
#---------------- External Memory Options ----------------
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# used for variables (.data/.bss) and heap (malloc()).
#EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# only used for heap (malloc()).
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
EXTMEMOPTS =
#---------------- Linker Options ----------------
# -Wl,...: tell GCC to pass this to linker.
# -Map: create map file
# --cref: add cross reference to map file
LDFLAGS = -Wl,-Map=$(OBJDIR)/$(TARGET).map,--cref
LDFLAGS += $(EXTMEMOPTS)
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
#---------------- Programming Options (avrdude) ----------------
# Programming hardware: alf avr910 avrisp bascom bsd
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
#
# Type: avrdude -c ?
# to get a full listing.
#
AVRDUDE_WRITE_FLASH = -U flash:w:$(OBJDIR)/$(TARGET).hex
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
# Uncomment the following if you want avrdude's erase cycle counter.
# Note that this counter needs to be initialized first using -Yn,
# see avrdude manual.
#AVRDUDE_ERASE_COUNTER = -y
# Uncomment the following if you do /not/ wish a verification to be
# performed after programming the device.
#AVRDUDE_NO_VERIFY = -V
# Increase verbosity level. Please use this when submitting bug
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
# to submit bug reports.
#AVRDUDE_VERBOSE = -v -v
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
# --------------------------- EDITED BY WIJOYO UTOMO ---------------------------
# This is to modify the baud rate to 19200 when using my Arduino Nano v-3.0 as my ISP programmer
AVRDUDE_FLAGS += -C 19200
#---------------- Debugging Options ----------------
# For simulavr only - target MCU frequency.
DEBUG_MFREQ = $(F_CPU)
# Set the DEBUG_UI to either gdb or insight.
# DEBUG_UI = gdb
DEBUG_UI = insight
# Set the debugging back-end to either avarice, simulavr.
DEBUG_BACKEND = avarice
#DEBUG_BACKEND = simulavr
# GDB Init Filename.
GDBINIT_FILE = __avr_gdbinit
# When using avarice settings for the JTAG
JTAG_DEV = /dev/com1
# Debugging port used to communicate between GDB / avarice / simulavr.
DEBUG_PORT = 4242
# Debugging host used to communicate between GDB / avarice / simulavr, normally
# just set to localhost unless doing some sort of crazy debugging when
# avarice is running on a different computer.
DEBUG_HOST = localhost
#============================================================================
# Define programs and commands.
SHELL = sh
CC = /usr/local/CrossPack-AVR/bin/avr-g++
OBJCOPY = /usr/local/CrossPack-AVR/bin/avr-objcopy
OBJDUMP = /usr/local/CrossPack-AVR/bin/avr-objdump
SIZE = /usr/local/CrossPack-AVR/bin/avr-size
NM = /usr/local/CrossPack-AVR/bin/avr-nm
AVRDUDE = /usr/local/CrossPack-AVR/bin/avrdude
REMOVE = rm -f
COPY = cp
WINSHELL = cmd
# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin --------
MSG_END = -------- end --------
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
MSG_COFF = Converting to AVR COFF:
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
MSG_FLASH = Creating load file for Flash:
MSG_EEPROM = Creating load file for EEPROM:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:
# Define all object files.
OBJ = $(addprefix $(OBJDIR)/,$(SRC:.c=.o)) $(addprefix $(OBJDIR)/,$(ASRC:.S=.o))
# Define all listing files.
LST = $(addprefix $(OBJDIR)/,$(SRC:.c=.lst)) $(addprefix $(OBJDIR)/,$(ASRC:.S=.lst))
# Compiler flags to generate dependency files.
GENDEPFLAGS = -MD -MP -MF $(OBJDIR)/.dep/$(#F).d
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
# Default target.
all: begin gccversion sizebefore clean build program sizeafter end
build: $(OBJDIR) elf hex eep lss sym
elf: $(OBJDIR)/$(TARGET).elf
hex: $(OBJDIR)/$(TARGET).hex
eep: $(OBJDIR)/$(TARGET).eep
lss: $(OBJDIR)/$(TARGET).lss
sym: $(OBJDIR)/$(TARGET).sym
$(OBJDIR):
#mkdir -p $#
# Eye candy.
# AVR Studio 3.x does not check make's exit code but relies on
# the following magic strings to be generated by the compile job.
begin:
#echo
#echo $(MSG_BEGIN)
end:
#echo $(MSG_END)
#echo
# Display size of file.
HEXSIZE = $(SIZE) --target=$(FORMAT) $(OBJDIR)/$(TARGET).hex
ELFSIZE = $(SIZE) --format=avr $(OBJDIR)/$(TARGET).elf
sizebefore:
#if test -f $(OBJDIR)/$(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
2>/dev/null; echo; fi
sizeafter:
#if test -f $(OBJDIR)/$(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
2>/dev/null; echo; fi
# Display compiler version information.
gccversion :
#$(CC) --version
# Program the device.
program: $(OBJDIR)/$(TARGET).hex $(OBJDIR)/$(TARGET).eep
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
# Generate avr-gdb config/init file which does the following:
# define the reset signal, load the target file, connect to target, and set
# a breakpoint at main().
gdb-config:
#$(REMOVE) $(GDBINIT_FILE)
#echo define reset >> $(GDBINIT_FILE)
#echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
#echo end >> $(GDBINIT_FILE)
#echo file $(OBJDIR)/$(TARGET).elf >> $(GDBINIT_FILE)
#echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
ifeq ($(DEBUG_BACKEND),simulavr)
#echo load >> $(GDBINIT_FILE)
endif
#echo break main >> $(GDBINIT_FILE)
debug: gdb-config $(OBJDIR)/$(TARGET).elf
ifeq ($(DEBUG_BACKEND), avarice)
#echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
#$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
$(OBJDIR)/$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
#$(WINSHELL) /c pause
else
#$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
$(DEBUG_MFREQ) --port $(DEBUG_PORT)
endif
#$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000
coff: $(OBJDIR)/$(TARGET).elf
#echo
#echo $(MSG_COFF) $(OBJDIR)/$(TARGET).cof
$(COFFCONVERT) -O coff-avr $< $(OBJDIR)/$(TARGET).cof
extcoff: $(OBJDIR)/$(TARGET).elf
#echo
#echo $(MSG_EXTENDED_COFF) $(OBJDIR)/$(TARGET).cof
$(COFFCONVERT) -O coff-ext-avr $< $(OBJDIR)/$(TARGET).cof
# Create final output files (.hex, .eep) from ELF output file.
$(OBJDIR)/%.hex: $(OBJDIR)/%.elf
#echo
#echo $(MSG_FLASH) $#
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $#
$(OBJDIR)/%.eep: $(OBJDIR)/%.elf
#echo
#echo $(MSG_EEPROM) $#
-$(OBJCOPY) -j .eeprom --set-section-flags .eeprom=alloc,load \
--change-section-lma .eeprom=0 -O $(FORMAT) $< $#
# Create extended listing file from ELF output file.
$(OBJDIR)/%.lss: $(OBJDIR)/%.elf
#echo
#echo $(MSG_EXTENDED_LISTING) $#
$(OBJDUMP) -h -S $< > $#
# Create a symbol table from ELF output file.
$(OBJDIR)/%.sym: $(OBJDIR)/%.elf
#echo
#echo $(MSG_SYMBOL_TABLE) $#
$(NM) -n $< > $#
# Link: create ELF output file from object files.
.SECONDARY : $(OBJDIR)/$(TARGET).elf
.PRECIOUS : $(OBJ)
$(OBJDIR)/%.elf: $(OBJ)
#echo
#echo $(MSG_LINKING) $#
$(CC) $(ALL_CFLAGS) $^ --output $# $(LDFLAGS)
# Compile: create object files from C source files.
$(OBJDIR)/%.o : %.c
#echo
#echo $(MSG_COMPILING) $<
$(CC) -c $(ALL_CFLAGS) $(abspath $<) -o $#
# Compile: create assembler files from C source files.
$(OBJDIR)/%.s : %.c
$(CC) -S $(ALL_CFLAGS) $< -o $#
# Assemble: create object files from assembler source files.
$(OBJDIR)/%.o : %.S
#echo
#echo $(MSG_ASSEMBLING) $<
$(CC) -c $(ALL_ASFLAGS) $< -o $#
# Create preprocessed source for use in sending a bug report.
$(OBJDIR)/%.i : %.c
$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $#
# Target: clean project.
clean: begin clean_list end
clean_list :
#echo
#echo $(MSG_CLEANING)
$(REMOVE) $(OBJDIR)/$(TARGET).hex
$(REMOVE) $(OBJDIR)/$(TARGET).eep
$(REMOVE) $(OBJDIR)/$(TARGET).cof
$(REMOVE) $(OBJDIR)/$(TARGET).elf
$(REMOVE) $(OBJDIR)/$(TARGET).map
$(REMOVE) $(OBJDIR)/$(TARGET).sym
$(REMOVE) $(OBJDIR)/$(TARGET).lss
$(REMOVE) $(OBJ)
$(REMOVE) $(LST)
$(REMOVE) $(OBJDIR)/$(SRC:.c=.s)
$(REMOVE) $(OBJDIR)/$(SRC:.c=.d)
$(REMOVE) $(OBJDIR)/.dep/*
# Include the dependency files.
-include $(shell mkdir $(OBJDIR)/.dep 2>/dev/null) $(wildcard $(OBJDIR)/.dep/*)
# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion \
build elf hex eep lss sym coff extcoff \
clean clean_list program debug gdb-config
Since I can't post image, I will explain my directory structure. There is a Builds sub directory that holds the .hex .eep .o .elf .lst of the build (when successful). My source files and header files are not in the Builds sub directory, but in the project directory which contains the Builds directory.
Alan Stokes is correct, except it doesn't matter what value OBJDIR has, because your clean rule is badly written. Consider this line in the clean rule:
$(REMOVE) $(OBJDIR)/$(SRC:.c=.s)
It's a common mistake to think that just by prefixing a variable with another variable, every word in the second will be prefixed by the first, but that's just not true. That's what addprefix is for (or patsubst if you prefer). The above line expands to this (assuming REMOVE is rm -f, OBJDIR is obj, and SRC is foo.c bar.c biz.c baz.c):
rm -f obj/foo.s bar.s biz.s baz.s
You can immediately see this is not what you wanted.
Now consider what happens when you add all the .cpp files, so SRC is now foo.c bar.c biz.c baz.c one.cpp two.cpp three.cpp. The substitution $(SRC:.c=.s) will replace the .c suffixes, BUT it will not touch any words that don't match the pattern. So, the command you run becomes:
rm -f obj/foo.s bar.s biz.s baz.s one.cpp two.cpp three.cpp
So you have two problems: the first is you should be using addprefix (or patsubst) to prefix all the words with the directory, and the second is you should be using the basename function to remove the suffix for all the words. There are multiple ways to do it but something like this will work:
$(REMOVE) $(patsubst %,$(OBJDIR)/%.s,$(basename $(SRC)))
And of course, you have to do the same with your rule for .d files. I strongly recommend you try it first with make -n before you let it rip for real.
I'm trying to write some C++ code for a Atmel SAM3S1 microcontroller. I'm Using the ASF Library with the FreeRTOS library included. I wrote a simple and small C++ wrapper (3 .cpp files) so I can easily inherit it in my device classes.
The Atmel SAM (datasheet) has 64KB Flash and 16KB RAM which I think is more then enough. although when I start compiling I get the message:
section `.text' will not fit in region `rom'
/usr/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: region `rom' overflowed by 13120 bytes
I use arm-none-eabi-g++ to compile and link everything.
When I clear the declared Class in Main.cpp the sizes are just fine so I think that is has something to do with C++. Can somebody explain to me what I'm doing wrong here?
Test.elf :
section size addr
.text 0x102c 0x400000
.ARM.exidx 0x8 0x40102c
.relocate 0x844 0x20000000
.bss 0x154 0x20000844
.stack 0x2000 0x20000998
.ARM.attributes 0x29 0x0
.comment 0x70 0x0
.debug_info 0x57d1 0x0
.debug_abbrev 0x1058 0x0
.debug_aranges 0x430 0x0
.debug_ranges 0xb00 0x0
.debug_macro 0xf50a 0x0
.debug_line 0x5024 0x0
.debug_str 0x46ec7 0x0
.debug_frame 0xe04 0x0
.debug_loc 0x31f1 0x0
Total 0x6a5a8
text data bss dec hex filename
0x1034 0x844 0x2154 14796 39cc Test.elf
These are my CPP files:
Main.cpp
#include <asf.h>
#include <MMA8652.h>
extern "C" {
extern void vApplicationStackOverflowHook(xTaskHandle *pxTask,
signed char *pcTaskName) {
}
}
int main(void) {
const taskConfig_t AccelTaskConfig = { "AccelRx", 3, 100 };
MMA8652 Accelero(AccelTaskConfig);
return(0);
}
Task.h
//#ifndef TASK_H
//#define TASK_H
#include <inttypes.h>
typedef struct {
char *taskName;
uint8_t priority;
uint16_t stackSize;
} taskConfig_t;
class Task {
private:
public:
Task(char *taskName, uint8_t priority, uint16_t stackSize);
~Task();
friend void run_helper(void *arg) {
return static_cast<Task*>(arg)->run();
}
virtual void run(void) const = 0;
protected:
};
//#endif
Task.cpp
#include <Task.h>
#include <asf.h>
void run_helper(void *arg);
Task::Task( char *taskName,
uint8_t priority,
uint16_t stackSize ) {
// check for minimal stacksize
if(stackSize < configMINIMAL_STACK_SIZE) {
stackSize = configMINIMAL_STACK_SIZE;
}
// check priority val
if(priority > configMAX_PRIORITIES) {
priority = configMAX_PRIORITIES;
}
// create a new FreeRTOS task with func ptr to run() member
xTaskCreate( &run_helper, (const signed char *) taskName,
stackSize, (Task*)this, priority, NULL);
}
MMA8652.h
#ifndef MMA8652_H
#define MMA8652_H
#include <Task.h>
class MMA8652: public Task {
private:
public:
void run(void) const;
MMA8652(const taskConfig_t &tConfig);
~MMA8652(void);
};
#endif // MMA8652_H
MMA8652.cpp
#include <asf.h>
#include <MMA8652.h>
MMA8652::MMA8652(const taskConfig_t &tConfig) :
Task(tConfig.taskName, tConfig.priority, tConfig.stackSize) {
}
void MMA8652::run(void) const {
pio_set_pin_high(TESTLED_GPIO);
vTaskDelay(1000);
pio_set_pin_low(TESTLED_GPIO);
vTaskDelay(1000);
}
linker_script.ld
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
SEARCH_DIR(.)
/* Memory Spaces Definitions */
MEMORY
{
rom (rx) : ORIGIN = 0x00400000, LENGTH = 0x00010000 /* Flash, 64K */
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00004000 /* sram, 16K */
}
/* The stack size used by the application. NOTE: you need to adjust */
__stack_size__ = DEFINED(__stack_size__) ? __stack_size__ : 0x2000;
__ram_end__ = ORIGIN(ram) + LENGTH(ram) - 4;
/* Section Definitions */
SECTIONS
{
.text :
{
. = ALIGN(4);
_sfixed = .;
KEEP(*(.vectors .vectors.*))
*(.text .text.* .gnu.linkonce.t.*)
*(.glue_7t) *(.glue_7)
*(.rodata .rodata* .gnu.linkonce.r.*)
*(.ARM.extab* .gnu.linkonce.armextab.*)
/* Support C constructors, and C destructors in both user code
and the C library. This also provides support for C++ code. */
. = ALIGN(4);
KEEP(*(.init))
. = ALIGN(4);
__preinit_array_start = .;
KEEP (*(.preinit_array))
__preinit_array_end = .;
. = ALIGN(4);
__init_array_start = .;
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))
__init_array_end = .;
. = ALIGN(0x4);
KEEP (*crtbegin.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*crtend.o(.ctors))
. = ALIGN(4);
KEEP(*(.fini))
. = ALIGN(4);
__fini_array_start = .;
KEEP (*(.fini_array))
KEEP (*(SORT(.fini_array.*)))
__fini_array_end = .;
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*crtend.o(.dtors))
. = ALIGN(4);
_efixed = .; /* End of text section */
} > rom
/* .ARM.exidx is sorted, so has to go in its own output section. */
PROVIDE_HIDDEN (__exidx_start = .);
.ARM.exidx :
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > rom
PROVIDE_HIDDEN (__exidx_end = .);
. = ALIGN(4);
_etext = .;
.relocate : AT (_etext)
{
. = ALIGN(4);
_srelocate = .;
*(.ramfunc .ramfunc.*);
*(.data .data.*);
. = ALIGN(4);
_erelocate = .;
} > ram
/* .bss section which is used for uninitialized data */
.bss (NOLOAD) :
{
. = ALIGN(4);
_sbss = . ;
_szero = .;
*(.bss .bss.*)
*(COMMON)
. = ALIGN(4);
_ebss = . ;
_ezero = .;
} > ram
/* stack section */
.stack (NOLOAD):
{
. = ALIGN(8);
_sstack = .;
. = . + __stack_size__;
. = ALIGN(8);
_estack = .;
} > ram
. = ALIGN(4);
_end = . ;
}
config.mk
# Path to top level ASF directory relative to this project directory.
PRJ_PATH = ASF
# Target CPU architecture: cortex-m3, cortex-m4
ARCH = cortex-m3
# Target part: none, sam3n4 or sam4l4aa
PART = sam3s1ab
# Application target name. Given with suffix .a for library and .elf for a
# standalone application.
TARGET_FLASH = $(PRJ_NAME).elf
TARGET_SRAM = $(PRJ_NAME).elf
# List of C source files.
CSRCS = \
Main.cpp \
lib/Task.cpp \
devices/MMA8652.cpp \
sam/boards/Board/init.c \
common/services/clock/sam3s/sysclk.c \
common/utils/interrupt/interrupt_sam_nvic.c \
common/utils/stdio/read.c \
common/utils/stdio/write.c \
sam/drivers/pio/pio.c \
sam/drivers/pio/pio_handler.c \
sam/drivers/pmc/pmc.c \
sam/drivers/pmc/sleep.c \
sam/utils/cmsis/sam3s/source/templates/exceptions.c \
sam/utils/cmsis/sam3s/source/templates/gcc/startup_sam3s.c \
sam/utils/cmsis/sam3s/source/templates/system_sam3s.c \
sam/utils/syscalls/gcc/syscalls.c \
thirdparty/freertos/freertos-7.0.0/source/croutine.c \
thirdparty/freertos/freertos-7.0.0/source/list.c \
thirdparty/freertos/freertos-7.0.0/source/portable/gcc/sam/port.c \
thirdparty/freertos/freertos-7.0.0/source/portable/memmang/heap_3.c \
thirdparty/freertos/freertos-7.0.0/source/queue.c \
thirdparty/freertos/freertos-7.0.0/source/tasks.c \
thirdparty/freertos/freertos-7.0.0/source/timers.c
# List of assembler source files.
ASSRCS =
# List of include paths.
INC_PATH = \
../lib/include \
../devices/include \
../config \
../ \
common/services/clock \
common/boards \
common/services/gpio \
common/services/ioport \
common/utils \
sam/drivers/pio \
sam/drivers/pmc \
sam/utils \
sam/utils/cmsis/sam3s/include \
sam/utils/cmsis/sam3s/source/templates \
sam/utils/header_files \
sam/utils/preprocessor \
thirdparty/CMSIS/Include \
thirdparty/CMSIS/Lib/GCC \
thirdparty/freertos/freertos-7.0.0/source/include \
thirdparty/freertos/freertos-7.0.0/source/portable/gcc/sam \
# Additional search paths for libraries.
LIB_PATH = \
thirdparty/CMSIS/Lib/GCC
# List of libraries to use during linking.
LIBS =
# Path relative to top level directory pointing to a linker script.
LINKER_SCRIPT_FLASH = sam/utils/linker_scripts/sam3s/sam3s1/gcc/flash.ld
LINKER_SCRIPT_SRAM = sam/utils/linker_scripts/sam3s/sam3s1/gcc/sram.ld
# Project type parameter: all, sram or flash
PROJECT_TYPE = flash
# Additional options for debugging. By default the common Makefile.in will
# add -g3.
DBGFLAGS =
# Application optimization used during compilation and linking:
# -O0, -O1, -O2, -O3 or -Os
OPTIMIZATION = -O3
# Extra flags to use when archiving.
ARFLAGS =
# Extra flags to use when assembling.
ASFLAGS =
# Extra flags to use when compiling.
CFLAGS =
# Extra flags to use when preprocessing.
#
# Preprocessor symbol definitions
# To add a definition use the format "-D name[=definition]".
# To cancel a definition use the format "-U name".
#
# The most relevant symbols to define for the preprocessor are:
# BOARD Target board in use, see boards/board.h for a list.
# EXT_BOARD Optional extension board in use, see boards/board.h for a list.
CPPFLAGS = \
-D __FREERTOS__ \
-D __SAM3S1B__ \
-D BOARD=BOARD \
-D printf=iprintf \
-D scanf=iscanf
# Extra flags to use when linking
LDFLAGS = \
# Pre- and post-build commands
PREBUILD_CMD =
POSTBUILD_CMD =
Makefile.sam.in
include config.mk
# Tool to use to generate documentation from the source code
DOCGEN ?= doxygen
# Look for source files relative to the top-level source directory
VPATH := $(PRJ_PATH)
# Output target file
project_type := $(PROJECT_TYPE)
# Output target file
ifeq ($(project_type),flash)
target := $(TARGET_FLASH)
linker_script := $(PRJ_PATH)/$(LINKER_SCRIPT_FLASH)
debug_script := $(PRJ_PATH)/$(DEBUG_SCRIPT_FLASH)
else
target := $(TARGET_SRAM)
linker_script := $(PRJ_PATH)/$(LINKER_SCRIPT_SRAM)
debug_script := $(PRJ_PATH)/$(DEBUG_SCRIPT_SRAM)
endif
# Output project name (target name minus suffix)
project := $(basename $(target))
# Output target file (typically ELF or static library)
ifeq ($(suffix $(target)),.a)
target_type := lib
else
ifeq ($(suffix $(target)),.elf)
target_type := elf
else
$(error "Target type $(target_type) is not supported")
endif
endif
# Allow override of operating system detection. The user can add OS=Linux or
# OS=Windows on the command line to explicit set the host OS.
#
# This allows to work around broken uname utility on certain systems.
ifdef OS
ifeq ($(strip $(OS)), Linux)
os_type := Linux
endif
ifeq ($(strip $(OS)), Windows)
os_type := windows32_64
endif
endif
os_type ?= $(strip $(shell uname))
ifeq ($(os_type),windows32)
os := Windows
else
ifeq ($(os_type),windows64)
os := Windows
else
ifeq ($(os_type),windows32_64)
os ?= Windows
else
ifeq ($(os_type),)
os := Windows
else
# Default to Linux style operating system. Both Cygwin and mingw are fully
# compatible (for this Makefile) with Linux.
os := Linux
endif
endif
endif
endif
# Output documentation directory and configuration file.
docdir := ../doxygen/html
doccfg := ../doxygen/doxyfile.doxygen
CROSS ?= arm-none-eabi-
AR := $(CROSS)ar
AS := $(CROSS)as
CC := $(CROSS)gcc
CPP := $(CROSS)gcc -E
CXX := $(CROSS)g++
LD := $(CROSS)g++
NM := $(CROSS)nm
OBJCOPY := $(CROSS)objcopy
OBJDUMP := $(CROSS)objdump
SIZE := $(CROSS)size
GDB := $(CROSS)gdb
RM := rm
ifeq ($(os),Windows)
RMDIR := rmdir /S /Q
else
RMDIR := rmdir -p --ignore-fail-on-non-empty
endif
# On Windows, we need to override the shell to force the use of cmd.exe
ifeq ($(os),Windows)
SHELL := cmd
endif
# Strings for beautifying output
MSG_CLEAN_FILES = "RM *.o *.d"
MSG_CLEAN_DIRS = "RMDIR $(strip $(clean-dirs))"
MSG_CLEAN_DOC = "RMDIR $(docdir)"
MSG_MKDIR = "MKDIR $(dir $#)"
MSG_INFO = "INFO "
MSG_PREBUILD = "PREBUILD $(PREBUILD_CMD)"
MSG_POSTBUILD = "POSTBUILD $(POSTBUILD_CMD)"
MSG_ARCHIVING = "AR $#"
MSG_ASSEMBLING = "AS $#"
MSG_BINARY_IMAGE = "OBJCOPY $#"
MSG_COMPILING = "CC $#"
MSG_COMPILING_CXX = "CXX $#"
MSG_EXTENDED_LISTING = "OBJDUMP $#"
MSG_IHEX_IMAGE = "OBJCOPY $#"
MSG_LINKING = "LN $#"
MSG_PREPROCESSING = "CPP $#"
MSG_SIZE = "SIZE $#"
MSG_SYMBOL_TABLE = "NM $#"
MSG_GENERATING_DOC = "DOXYGEN $(docdir)"
# Don't use make's built-in rules and variables
MAKEFLAGS += -rR
# Don't print 'Entering directory ...'
MAKEFLAGS += --no-print-directory
# Function for reversing the order of a list
reverse = $(if $(1),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) $(firstword $(1))
# Hide command output by default, but allow the user to override this
# by adding V=1 on the command line.
#
# This is inspired by the Kbuild system used by the Linux kernel.
ifdef V
ifeq ("$(origin V)", "command line")
VERBOSE = $(V)
endif
endif
ifndef VERBOSE
VERBOSE = 0
endif
ifeq ($(VERBOSE), 1)
Q =
else
Q = #
endif
arflags-gnu-y := $(ARFLAGS)
asflags-gnu-y := $(ASFLAGS)
cflags-gnu-y := $(CFLAGS)
cxxflags-gnu-y := $(CXXFLAGS)
cppflags-gnu-y := $(CPPFLAGS)
cpuflags-gnu-y :=
dbgflags-gnu-y := $(DBGFLAGS)
libflags-gnu-y := $(foreach LIB,$(LIBS),-l$(LIB))
ldflags-gnu-y := $(LDFLAGS)
flashflags-gnu-y :=
clean-files :=
clean-dirs :=
clean-files += $(wildcard $(target) $(project).map)
clean-files += $(wildcard $(project).hex $(project).bin)
clean-files += $(wildcard $(project).lss $(project).sym)
clean-files += $(wildcard $(build))
# Use pipes instead of temporary files for communication between processes
cflags-gnu-y += -pipe
asflags-gnu-y += -pipe
ldflags-gnu-y += -pipe
# Archiver flags.
arflags-gnu-y += rcs
# Always enable warnings. And be very careful about implicit
# declarations.
cflags-gnu-y += -Wall -Wstrict-prototypes -Wmissing-prototypes
cflags-gnu-y += -Werror-implicit-function-declaration
cxxflags-gnu-y += -Wall
# IAR doesn't allow arithmetic on void pointers, so warn about that.
cflags-gnu-y += -Wpointer-arith
cxxflags-gnu-y += -Wpointer-arith
# Preprocessor flags.
cppflags-gnu-y += $(foreach INC,$(addprefix $(PRJ_PATH)/,$(INC_PATH)),-I$(INC))
asflags-gnu-y += $(foreach INC,$(addprefix $(PRJ_PATH)/,$(INC_PATH)),'-Wa,-I$(INC)')
# CPU specific flags.
cpuflags-gnu-y += -mcpu=$(ARCH) -mthumb -D=__$(PART)__
# Dependency file flags.
depflags = -MD -MP -MQ $#
# Debug specific flags.
ifdef BUILD_DEBUG_LEVEL
dbgflags-gnu-y += -g$(BUILD_DEBUG_LEVEL)
else
dbgflags-gnu-y += -g3
endif
# Optimization specific flags.
ifdef BUILD_OPTIMIZATION
optflags-gnu-y = -O$(BUILD_OPTIMIZATION)
else
optflags-gnu-y = $(OPTIMIZATION)
endif
# Always preprocess assembler files.
asflags-gnu-y += -x assembler-with-cpp
# Compile C files using the GNU99 standard.
cflags-gnu-y += -std=gnu99
# Compile C++ files using the GNU++98 standard.
cxxflags-gnu-y += -std=gnu++98
# Don't use strict aliasing (very common in embedded applications).
cflags-gnu-y += -fno-strict-aliasing
cxxflags-gnu-y += -fno-strict-aliasing
# Separate each function and data into its own separate section to allow
# garbage collection of unused sections.
cflags-gnu-y += -ffunction-sections -fdata-sections
cxxflags-gnu-y += -ffunction-sections -fdata-sections
# Various cflags.
cflags-gnu-y += -Wchar-subscripts -Wcomment -Wformat=2 -Wimplicit-int
cflags-gnu-y += -Wmain -Wparentheses
cflags-gnu-y += -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs -Wunused
cflags-gnu-y += -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef
cflags-gnu-y += -Wshadow -Wbad-function-cast -Wwrite-strings
cflags-gnu-y += -Wsign-compare -Waggregate-return
cflags-gnu-y += -Wmissing-declarations
cflags-gnu-y += -Wformat -Wmissing-format-attribute -Wno-deprecated-declarations
cflags-gnu-y += -Wpacked -Wredundant-decls -Wnested-externs -Winline -Wlong-long
cflags-gnu-y += -Wunreachable-code
cflags-gnu-y += -Wcast-align
cflags-gnu-y += --param max-inline-insns-single=500
# Garbage collect unreferred sections when linking.
ldflags-gnu-y += -Wl,--gc-sections
# Use the linker script if provided by the project.
ifneq ($(strip $(linker_script)),)
ldflags-gnu-y += -Wl,-T $(linker_script)
endif
# Output a link map file and a cross reference table
ldflags-gnu-y += -Wl,-Map=$(project).map,--cref
# Add library search paths relative to the top level directory.
ldflags-gnu-y += $(foreach _LIB_PATH,$(addprefix $(PRJ_PATH)/,$(LIB_PATH)),-L$(_LIB_PATH))
a_flags = $(cpuflags-gnu-y) $(depflags) $(cppflags-gnu-y) $(asflags-gnu-y) -D__ASSEMBLY__
c_flags = $(cpuflags-gnu-y) $(dbgflags-gnu-y) $(depflags) $(optflags-gnu-y) $(cppflags-gnu-y) $(cflags-gnu-y)
cxx_flags= $(cpuflags-gnu-y) $(dbgflags-gnu-y) $(depflags) $(optflags-gnu-y) $(cppflags-gnu-y) $(cxxflags-gnu-y)
l_flags = -Wl,--entry=Reset_Handler -Wl,--cref $(cpuflags-gnu-y) $(optflags-gnu-y) $(ldflags-gnu-y)
ar_flags = $(arflags-gnu-y)
# Source files list and part informations must already be included before
# running this makefile
# If a custom build directory is specified, use it -- force trailing / in directory name.
ifdef BUILD_DIR
build-dir := $(dir $(BUILD_DIR))$(if $(notdir $(BUILD_DIR)),$(notdir $(BUILD_DIR))/)
else
build-dir =
endif
# Create object files list from source files list.
obj-y := $(addprefix $(build-dir), $(addsuffix .o,$(basename $(CSRCS) $(ASSRCS))))
# Create dependency files list from source files list.
dep-files := $(wildcard $(foreach f,$(obj-y),$(basename $(f)).d))
clean-files += $(wildcard $(obj-y))
clean-files += $(dep-files)
clean-dirs += $(call reverse,$(sort $(wildcard $(dir $(obj-y)))))
# Default target.
.PHONY: all
ifeq ($(project_type),all)
all:
$(MAKE) all PROJECT_TYPE=flash
$(MAKE) all PROJECT_TYPE=sram
else
ifeq ($(target_type),lib)
all: $(target) $(project).lss $(project).sym
else
ifeq ($(target_type),elf)
all: prebuild $(target) $(project).lss $(project).sym $(project).hex $(project).bin postbuild
endif
endif
endif
prebuild:
ifneq ($(strip $(PREBUILD_CMD)),)
#echo $(MSG_PREBUILD)
$(Q)$(PREBUILD_CMD)
endif
postbuild:
ifneq ($(strip $(POSTBUILD_CMD)),)
#echo $(MSG_POSTBUILD)
$(Q)$(POSTBUILD_CMD)
endif
# Clean up the project.
.PHONY: clean
clean:
#$(if $(strip $(clean-files)),echo $(MSG_CLEAN_FILES))
$(if $(strip $(clean-files)),$(Q)$(RM) $(clean-files),)
#$(if $(strip $(clean-dirs)),echo $(MSG_CLEAN_DIRS))
# Remove created directories, and make sure we only remove existing
# directories, since recursive rmdir might help us a bit on the way.
ifeq ($(os),Windows)
$(Q)$(if $(strip $(clean-dirs)), \
$(RMDIR) $(strip $(subst /,\,$(clean-dirs))))
else
$(Q)$(if $(strip $(clean-dirs)), \
for directory in $(strip $(clean-dirs)); do \
if [ -d "$$directory" ]; then \
$(RMDIR) $$directory; \
fi \
done \
)
endif
# Rebuild the project.
.PHONY: rebuild
rebuild: clean all
# Debug the project in flash.
.PHONY: debug_flash
debug_flash: all
$(GDB) -x "$(PRJ_PATH)/$(DEBUG_SCRIPT_FLASH)" -ex "reset" -readnow -se $(TARGET_FLASH)
# Debug the project in sram.
.PHONY: debug_sram
debug_sram: all
$(GDB) -x "$(PRJ_PATH)/$(DEBUG_SCRIPT_SRAM)" -ex "reset" -readnow -se $(TARGET_SRAM)
.PHONY: objfiles
objfiles: $(obj-y)
# Create object files from C source files.
$(build-dir)%.o: %.c $(MAKEFILE_PATH) config.mk
$(Q)test -d $(dir $#) || echo $(MSG_MKDIR)
ifeq ($(os),Windows)
$(Q)test -d $(patsubst %/,%,$(dir $#)) || mkdir $(subst /,\,$(dir $#))
else
$(Q)test -d $(dir $#) || mkdir -p $(dir $#)
endif
#echo $(MSG_COMPILING)
$(Q)$(CC) $(c_flags) -c $< -o $#
# Create object files from C++ source files.
$(build-dir)%.o: %.cpp $(MAKEFILE_PATH) config.mk
$(Q)test -d $(dir $#) || echo $(MSG_MKDIR)
ifeq ($(os),Windows)
$(Q)test -d $(patsubst %/,%,$(dir $#)) || mkdir $(subst /,\,$(dir $#))
else
$(Q)test -d $(dir $#) || mkdir -p $(dir $#)
endif
#echo $(MSG_COMPILING_CXX)
$(Q)$(CXX) $(cxx_flags) -c $< -o $#
# Preprocess and assemble: create object files from assembler source files.
$(build-dir)%.o: %.S $(MAKEFILE_PATH) config.mk
$(Q)test -d $(dir $#) || echo $(MSG_MKDIR)
ifeq ($(os),Windows)
$(Q)test -d $(patsubst %/,%,$(dir $#)) || mkdir $(subst /,\,$(dir $#))
else
$(Q)test -d $(dir $#) || mkdir -p $(dir $#)
endif
#echo $(MSG_ASSEMBLING)
$(Q)$(CC) $(a_flags) -c $< -o $#
# Include all dependency files to add depedency to all header files in use.
include $(dep-files)
ifeq ($(target_type),lib)
# Archive object files into an archive
$(target): $(MAKEFILE_PATH) config.mk $(obj-y)
#echo $(MSG_ARCHIVING)
$(Q)$(AR) $(ar_flags) $# $(obj-y)
#echo $(MSG_SIZE)
$(Q)$(SIZE) -Bxt $#
else
ifeq ($(target_type),elf)
# Link the object files into an ELF file. Also make sure the target is rebuilt
# if the common Makefile.sam.in or project config.mk is changed.
$(target): $(linker_script) $(MAKEFILE_PATH) config.mk $(obj-y)
#echo $(MSG_LINKING)
$(Q)$(LD) $(l_flags) $(obj-y) $(libflags-gnu-y) -o $#
#echo $(MSG_SIZE)
$(Q)$(SIZE) -Ax $#
$(Q)$(SIZE) -Bx $#
endif
endif
# Create extended function listing from target output file.
%.lss: $(target)
#echo $(MSG_EXTENDED_LISTING)
$(Q)$(OBJDUMP) -h -S $< > $#
# Create symbol table from target output file.
%.sym: $(target)
#echo $(MSG_SYMBOL_TABLE)
$(Q)$(NM) -n $< > $#
# Create Intel HEX image from ELF output file.
%.hex: $(target)
#echo $(MSG_IHEX_IMAGE)
$(Q)$(OBJCOPY) -O ihex $(flashflags-gnu-y) $< $#
# Create binary image from ELF output file.
%.bin: $(target)
#echo $(MSG_BINARY_IMAGE)
$(Q)$(OBJCOPY) -O binary $< $#
# Provide information about the detected host operating system.
.SECONDARY: info-os
info-os:
#echo $(MSG_INFO)$(os) build host detected
# Build Doxygen generated documentation.
.PHONY: doc
doc:
#echo $(MSG_GENERATING_DOC)
$(Q)cd $(dir $(doccfg)) && $(DOCGEN) $(notdir $(doccfg))
# Clean Doxygen generated documentation.
.PHONY: cleandoc
cleandoc:
#$(if $(wildcard $(docdir)),echo $(MSG_CLEAN_DOC))
$(Q)$(if $(wildcard $(docdir)),$(RM) --recursive $(docdir))
# Rebuild the Doxygen generated documentation.
.PHONY: rebuilddoc
rebuilddoc: cleandoc doc
According to my calculations, your .text segment is around 4k.
Many linker applications for embedded systems, have a command or configuration file. The configuration file tells the starting addresses of segments and size.
You will need to find the configuration file and verify that the ROM section is at the correct address and has the correct capacity.
Try with -Os instead of -O3 in OPTIMIZATION flag inside config.mk; you may also use -flto -Os both when compiling and when linking (for link-time optimizations)
I finally fixed it! i've added the fno-rtti and fno-exceptions and overloaded the new, delete and destructor operator. http://www.embedded.com/design/mcus-processors-and-socs/4007134/Building-Bare-Metal-ARM-Systems-with-GNU-Part-4.
Unfortunately i cant overload the static_cast operator used in Task.h->action_helper() . Does anyone know how to solve this?
In general:
fno-exceptions is a good way to start, if you don't use it.
RTTI can also be switched off, but I think it's worth to keep. It's a really powerful feature with minimal cost.
overloading new/delete is not necessary. If you never use it and disable exceptions, it can be optimized by LTO. You have to worry about it only if you allocate dynamically.
overloading static_cast? It's "static" because it's compile time. No reason to overload it, I'm not sure if it's possible at all.
try changing debug info generation settings (-g flags in gcc)
optimize for size if possible. It makes debugging really hard.
Don't forget that all of your ASF sources are C, so setting up the C toolchain is also necessary.