Trying to build a project with C++ source

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am trying to experiment with c++. When I build the project the c++ source file is replaced with what looks like an assembly listing.

I modified the make file (which supported 'c' and asm sources) to include c++ files. It appears to build okay but the 'project.cc' file gets replaced as above.

I run the make program from the command line. The build environment is a PowerMac G4 with CrossPack AVR.

Does anyone have an idea what is wrong here?

The make file is...


# MCU name
MCU = atmega1284p
__AVR_ATmega1284P__	= 1

# 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 = 18432000


# Fuse Programming
# ATMega1284
#	Preserve EEPROM with Flash Program, JTAG disabled
FUSE_HIGH	= D1
#	Normal Crystal Operation, /1, Full swing oscilator
FUSE_LOW	= E7

# Output format. (can be srec, ihex, binary)
FORMAT = ihex


# Target file name (without extension).
TARGET = Project


# List C source files here. (C dependencies are automatically generated.)
#SRC = $(TARGET).c 
#SRC += library/XXXX.c 


# List C++ source files here. (C dependencies are automatically generated.)
CPPSRC = $(TARGET).cc
#CPPSRC += library/XXXX.cc 


# 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
CDEFS = -DF_CPU=$(F_CPU)UL


# Place -I options here
CINCS = -Ilibrary



#---------------- 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=$(<:.c=.lst)
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += $(CSTANDARD)


#---------------- 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
CPPFLAGS = -g$(DEBUG)
CPPFLAGS += $(CDEFS) $(CINCS)
CPPFLAGS += -O$(OPT)
CPPFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CPPFLAGS += -Wall 
CPPFLAGS += -Wa,-adhlns=$(<:.c=.lst)
CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
#CPPFLAGS += $(CSTANDARD)


#---------------- 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]
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 


#---------------- Library Options ----------------
...


#---------------- 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 += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)



#---------------- Programming Options (avrdude) ----------------
...


#---------------- Debugging Options ----------------
...

#============================================================================


# Define programs and commands.
SHELL = sh
CC = avr-gcc
CCPP = avr-g++
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
NM = avr-nm
AVRDUDE = avrdude
REMOVE = rm -f
COPY = cp


# 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 = $(SRC:.c=.o) $(CPPSRC:.cc=.o) $(ASRC:.S=.o) 
#OBJ = $(SRC:.c=.o)                  $(ASRC:.S=.o) 

# Define all listing files.
#LST = $(SRC:.c=.lst) $(CPPSRC:.cc=.lst) $(ASRC:.S=.lst) 
LST = $(SRC:.c=.lst)                    $(ASRC:.S=.lst) 


# Compiler flags to generate dependency files.
GENDEPFLAGS = -MD -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. $(CPPFLAGS) $(GENDEPFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)





# Default target.
all: begin gccversion sizebefore build sizeafter end

build: elf hex eep lss sym

elf: $(TARGET).elf
hex: $(TARGET).hex
eep: $(TARGET).eep
lss: $(TARGET).lss 
sym: $(TARGET).sym



# 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) -A $(TARGET).elf
AVRMEM = avr-mem.sh $(TARGET).elf $(MCU)

sizebefore:
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
	$(AVRMEM) 2>/dev/null; echo; fi

sizeafter:
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
	$(AVRMEM) 2>/dev/null; echo; fi



# Display compiler version information.
gccversion : 
	@$(CC) --version



# Program the device.  
program: $(TARGET).hex 
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_CLOCK_RATE) $(AVRDUDE_WRITE_FLASH)

# Program the EEPROM.  
ee: $(TARGET).eep
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_CLOCK_RATE) $(AVRDUDE_WRITE_EEPROM)

# Program the Fuses
fuse: 
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FUSE_LOW) $(AVRDUDE_WRITE_FUSE_HIGH)

# 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 \
#--change-section-address .data-0x800000 \
#--change-section-address .bss-0x800000 \
#--change-section-address .noinit-0x800000 \
#--change-section-address .eeprom-0x810000 


# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
	@echo
	@echo $(MSG_FLASH) $@
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@

%.eep: %.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.
%.lss: %.elf
	@echo
	@echo $(MSG_EXTENDED_LISTING) $@
	$(OBJDUMP) -h -S $< > $@

# Create a symbol table from ELF output file.
%.sym: %.elf
	@echo
	@echo $(MSG_SYMBOL_TABLE) $@
	$(NM) -n $< > $@



# 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.
%.o : %.c
	@echo
	@echo $(MSG_COMPILING) $<
	$(CC) -c $(ALL_CFLAGS) $< -o $@ 


# Compile: create object files from C++ source files.
%.o : %.cc
	@echo
	@echo $(MSG_COMPILING) $<
	$(CCPP) -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 : %.cc
	$(CCPP) -S $(ALL_CPPFLAGS) $< -o $@


# Assemble: create object files from assembler source files.
%.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) $(OBJ)
	$(REMOVE) $(LST)
	$(REMOVE) $(SRC:.c=.s)
	$(REMOVE) $(SRC:.c=.d)
#	$(REMOVE) $(CPPSRC:.cc=.s)
#	$(REMOVE) $(CPPSRC:.cc=.d)
	$(REMOVE) .dep/*



# 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


I've removed some unrelated parts of the file and replaced them with "..."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What command does make actually produce?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This section

# Compile: create assembler files from C source files.
%.s : %.cc
   $(CCPP) -S $(ALL_CPPFLAGS) $< -o $@

tells make how to build a .s file from a .cc. If you get the $< and $@ wrong, what you're seeing might be caused here. On the other hand -o $@ seems correct....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I modified the make file (which supported 'c' and asm sources) to include c++ files.

I gotta ask why? Mfile already has support for building C++ (which should be .cpp not .cc by the way).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

which should be .cpp not .cc by the way

For the standard MFile template makefile, yes.

In general, there are several extensions used for C++ source code by convention: .C , .cpp , .cxx (or maybe .Cxx?) and even .c++ . The latter would break on certain operating systems.

Re the OPs problem, I would like to see the build output.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:
Quote:

which should be .cpp not .cc by the way

For the standard MFile template makefile, yes.

In general, there are several extensions used for C++ source code by convention: .C , .cpp , .cxx (or maybe .Cxx?) and even .c++ . The latter would break on certain operating systems.

My favorite, though I seem to be in a small minority, is .cc .
When I see .cpp , the C pre-processor puts a little sand in my gears.
Quote:
Re the OPs problem, I would like to see the build output.
Likewise.

Iluvatar is the better part of Valar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

westfw wrote:
What command does make actually produce?

    -------- begin -------- avr-gcc (GCC) 4.3.3
    Copyright (C) 2008 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions. There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    Compiling: Project.cc
    avr-g++ -c -mmcu=atmega1284p -I. -gdwarf-2 -DF_CPU=18432000UL -Ilibrary -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wa,-adhlns=Project.cc -MD -MP -MF .dep/Project.o.d Project.cc -o Project.o

    Linking: Project.elf
    avr-gcc -mmcu=atmega1284p -I. -gdwarf-2 -DF_CPU=18432000UL -Ilibrary -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=Project.o -std=gnu99 -MD -MP -MF .dep/Project.elf.d Project.o --output Project.elf -Wl,-Map=Project.map,--cref -lm

    Creating load file for Flash: Project.hex
    avr-objcopy -O ihex -R .eeprom Project.elf Project.hex

    Creating load file for EEPROM: Project.eep
    avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \
    --change-section-lma .eeprom=0 -O ihex Project.elf Project.eep
    avr-objcopy: --change-section-lma .eeprom=0x00000000 never used

    Creating Extended Listing: Project.lss
    avr-objdump -h -S Project.elf > Project.lss

    Creating Symbol Table: Project.sym
    avr-nm -n Project.elf > Project.sym

    Size after:
    Project.elf :
    section size addr
    .text 198 0
    .stab 1872 0
    .stabstr 130 0
    .debug_aranges 32 0
    .debug_pubnames 39 0
    .debug_info 142 0
    .debug_abbrev 91 0
    .debug_line 100 0
    .debug_frame 48 0
    .debug_str 160 0
    Total 2812

    -------- end --------

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:
Quote:

which should be .cpp not .cc by the way

For the standard MFile template makefile, yes.

In general, there are several extensions used for C++ source code by convention: .C , .cpp , .cxx (or maybe .Cxx?) and even .c++ . The latter would break on certain operating systems.

Re the OPs problem, I would like to see the build output.

I listed the shell output in another response. Did you mean this or the contents of one of the files.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I found the problem.

Where it creates the compiler flags is this line:

CFLAGS += -Wa,-adhlns=$(<:.c=.lst)

I didn't notice the ".c" originally. I changed it to ".cc" and now it compiles AND does not overwrite the source file.

Now on to trying to actually use it.