makefile removes my .cpp files - c++

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.

Related

Makefile error when building Veins project with Omnet++

I've built a number of projects with Veins on Omnet++ without issues at this stage, and I decided to implement CAM messages into a simulation. However, upon building I arrive at the following error:
12:41:23 **** Incremental Build of configuration release for project v2x ****
make MODE=release all
cd src && make make[1]: Entering directory '/home/veins/workspace.omnetpp/v2x/src'
Creating executable: ../out/clang-release/src/v2x /usr/bin/ld: cannot open output file ../out/clang-release/src/v2x: Is a directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]:
*** [Makefile:117: ../out/clang-release/src/v2x] Error 1 make[1]: Leaving directory '/home/veins/workspace.omnetpp/v2x/src'
make: *** [Makefile:2: all]
Error 2 "make MODE=release all" terminated with exit code 2.
Build might be incomplete.
12:41:24 Build Failed. 3 errors, 0 warnings. (took 549ms)
My Makefile reads:
#
# OMNeT++/OMNEST Makefile for v2x
#
# This file was generated with the command:
# opp_makemake -f --deep -KINET_PROJ=/home/veins/src/inet -KLTE_PROJ=/home/veins/src/simulte -KVEINS_INET_PROJ=/home/veins/src/veins/subprojects/veins_inet -KVEINS_PROJ=/home/veins/src/veins -DINET_IMPORT -DVEINS_IMPORT -DVEINS_INET_IMPORT -I$$\(INET_PROJ\)/src -I$$\(LTE_PROJ\)/src -I$$\(VEINS_INET_PROJ\)/src -I$$\(VEINS_PROJ\)/src -I. -L$$\(INET_PROJ\)/src -L$$\(LTE_PROJ\)/src -L$$\(VEINS_PROJ\)/src -L$$\(VEINS_INET_PROJ\)/src -lINET$$\(D\) -llte$$\(D\) -lveins$$\(D\) -lveins_inet$$\(D\)
#
# Name of target to be created (-o option)
TARGET_DIR = .
TARGET_NAME = v2x$(D)
TARGET = $(TARGET_NAME)$(EXE_SUFFIX)
TARGET_IMPLIB = $(TARGET_NAME)$(IMPLIB_SUFFIX)
TARGET_IMPDEF = $(TARGET_NAME)$(IMPDEF_SUFFIX)
TARGET_FILES = $(TARGET_DIR)/$(TARGET)
# User interface (uncomment one) (-u option)
USERIF_LIBS = $(ALL_ENV_LIBS) # that is, $(TKENV_LIBS) $(QTENV_LIBS) $(CMDENV_LIBS)
#USERIF_LIBS = $(CMDENV_LIBS)
#USERIF_LIBS = $(TKENV_LIBS)
#USERIF_LIBS = $(QTENV_LIBS)
# C++ include paths (with -I)
INCLUDE_PATH = -I$(INET_PROJ)/src -I$(LTE_PROJ)/src -I$(VEINS_INET_PROJ)/src -I$(VEINS_PROJ)/src -I.
# Additional object and library files to link with
EXTRA_OBJS =
# Additional libraries (-L, -l options)
LIBS = $(LDFLAG_LIBPATH)$(INET_PROJ)/src $(LDFLAG_LIBPATH)$(LTE_PROJ)/src $(LDFLAG_LIBPATH)$(VEINS_PROJ)/src $(LDFLAG_LIBPATH)$(VEINS_INET_PROJ)/src -lINET$(D) -llte$(D) -lveins$(D) -lveins_inet$(D)
# Output directory
PROJECT_OUTPUT_DIR = ../out
PROJECTRELATIVE_PATH = src
O = $(PROJECT_OUTPUT_DIR)/$(CONFIGNAME)/$(PROJECTRELATIVE_PATH)
# Object files for local .cc, .msg and .sm files
OBJS = \
$O/v2x/GeneralMessageSerializer.o \
$O/v2x/VeinsInetApplicationBase.o \
$O/v2x/VeinsInetManager.o \
$O/v2x/VeinsInetManagerBase.o \
$O/v2x/VeinsInetManagerForker.o \
$O/v2x/VeinsInetMobility.o \
$O/v2x/VeinsInetSampleApplication.o \
$O/v2x/VeinsInetSampleMessageSerializer.o \
$O/v2x/GeneralMessage_m.o \
$O/v2x/VeinsInetSampleMessage_m.o
# Message files
MSGFILES = \
v2x/GeneralMessage.msg \
v2x/VeinsInetSampleMessage.msg
# SM files
SMFILES =
# Other makefile variables (-K)
INET_PROJ=/home/veins/src/inet
LTE_PROJ=/home/veins/src/simulte
VEINS_INET_PROJ=/home/veins/src/veins/subprojects/veins_inet
VEINS_PROJ=/home/veins/src/veins
#------------------------------------------------------------------------------
# Pull in OMNeT++ configuration (Makefile.inc)
ifneq ("$(OMNETPP_CONFIGFILE)","")
CONFIGFILE = $(OMNETPP_CONFIGFILE)
else
CONFIGFILE = $(shell opp_configfilepath)
endif
ifeq ("$(wildcard $(CONFIGFILE))","")
$(error Config file '$(CONFIGFILE)' does not exist -- add the OMNeT++ bin directory to the path so that opp_configfilepath can be found, or set the OMNETPP_CONFIGFILE variable to point to Makefile.inc)
endif
include $(CONFIGFILE)
# Simulation kernel and user interface libraries
OMNETPP_LIBS = $(OPPMAIN_LIB) $(USERIF_LIBS) $(KERNEL_LIBS) $(SYS_LIBS)
ifneq ($(PLATFORM),win32.x86_64)
LIBS += -Wl,-rpath,$(abspath $(INET_PROJ)/src) -Wl,-rpath,$(abspath $(LTE_PROJ)/src) -Wl,-rpath,$(abspath $(VEINS_PROJ)/src) -Wl,-rpath,$(abspath $(VEINS_INET_PROJ)/src)
endif
COPTS = $(CFLAGS) $(IMPORT_DEFINES) -DINET_IMPORT -DVEINS_IMPORT -DVEINS_INET_IMPORT $(INCLUDE_PATH) -I$(OMNETPP_INCL_DIR)
MSGCOPTS = $(INCLUDE_PATH)
SMCOPTS =
# we want to recompile everything if COPTS changes,
# so we store COPTS into $COPTS_FILE (if COPTS has changed since last build)
# and make the object files depend on it
COPTS_FILE = $O/.last-copts
ifneq ("$(COPTS)","$(shell cat $(COPTS_FILE) 2>/dev/null || echo '')")
$(shell $(MKPATH) "$O")
$(file >$(COPTS_FILE),$(COPTS))
endif
#------------------------------------------------------------------------------
# User-supplied makefile fragment(s)
-include makefrag
#------------------------------------------------------------------------------
# Main target
all: $(TARGET_FILES)
$(TARGET_DIR)/% :: $O/%
#mkdir -p $(TARGET_DIR)
$(Q)$(LN) $< $#
ifeq ($(TOOLCHAIN_NAME),clang-msabi)
-$(Q)-$(LN) $(<:%.dll=%.lib) $(#:%.dll=%.lib) 2>/dev/null
endif
$O/$(TARGET): $(OBJS) $(wildcard $(EXTRA_OBJS)) Makefile $(CONFIGFILE)
#$(MKPATH) $O
#echo Creating executable: $#
$(Q)$(CXX) $(LDFLAGS) -o $O/$(TARGET) $(OBJS) $(EXTRA_OBJS) $(AS_NEEDED_OFF) $(WHOLE_ARCHIVE_ON) $(LIBS) $(WHOLE_ARCHIVE_OFF) $(OMNETPP_LIBS)
.PHONY: all clean cleanall depend msgheaders smheaders
.SUFFIXES: .cc
$O/%.o: %.cc $(COPTS_FILE) | msgheaders smheaders
#$(MKPATH) $(dir $#)
$(qecho) "$<"
$(Q)$(CXX) -c $(CXXFLAGS) $(COPTS) -o $# $<
%_m.cc %_m.h: %.msg
$(qecho) MSGC: $<
$(Q)$(MSGC) -s _m.cc -MD -MP -MF $O/$(basename $<)_m.h.d $(MSGCOPTS) $?
%_sm.cc %_sm.h: %.sm
$(qecho) SMC: $<
$(Q)$(SMC) -c++ -suffix cc $(SMCOPTS) $?
msgheaders: $(MSGFILES:.msg=_m.h)
smheaders: $(SMFILES:.sm=_sm.h)
clean:
$(qecho) Cleaning $(TARGET)
$(Q)-rm -rf $O
$(Q)-rm -f $(TARGET_FILES)
$(Q)-rm -f $(call opp_rwildcard, . , *_m.cc *_m.h *_sm.cc *_sm.h)
cleanall:
$(Q)$(CLEANALL_COMMAND)
$(Q)-rm -rf $(PROJECT_OUTPUT_DIR)
help:
#echo "$$HELP_SYNOPSYS"
#echo "$$HELP_TARGETS"
#echo "$$HELP_VARIABLES"
#echo "$$HELP_EXAMPLES"
# include all dependencies
-include $(OBJS:%=%.d) $(MSGFILES:%.msg=$O/%_m.h.d)
It's correct in saying that clang-release/src/v2x is a directory, but it has always been so (even before making the recent changes) and it hasn't produced this error.
Other than the MakeFile error, there is no other error in any of the scripts for the project.
You want to create the executable file clang-release/src/v2x but you can't because that file already exists and is a directory.
The name of the file you attempt to create is
v2x$(D)$(EXE_SUFFIX) and nowhere in your Makefile do you have Make variables D or EXE_SUFFIX defined, so they evaluate to empty strings.
Probably you want to make sure you have D and EXE_SUFFIX defined somewhere.
There is a $(CONFIGFILE) you are including, Make finds it but you did not provide the text of it, check if these variables should be defined in there but are not.

Use make to compile all cpp files in a directory into their own executable with g++ [duplicate]

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

The L6218E Error when calling VxGUI Constructor

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

Compile and link sources from different directories with make and gcc

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

Undefined Reference to (both object variables and base variables), C++ AVR

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...