I am attempting to mix C and C++ in a project. I am using a TI MSP432, which has libraries (BSD licensed) for it that are programed in C. I would like to use these libraries, but I want my code to be C++. In order to run my program I also need a couple c files provided by ti. I am having issues getting my code to compile. It may just be the flags in my make file.
SIMPLELINK_MSP432_SDK_INSTALL_DIR ?= /opt/ti/simplelink_msp432p4_sdk_1_60_00_12
XDC_INSTALL_DIR ?= /home/username/ti/xdctools_3_50_04_43_core
FREERTOS_INSTALL_DIR ?= /home/username/FreeRTOSv9.0.0
GCC_ARMCOMPILER ?= /usr/bin/arm-none-eabi-g++
GXX_ARMCOMPILER ?= /usr/bin/arm-none-eabi-g++
GCC_ARMCOMPILER_LIBS ?= /usr/lib/gcc/arm-none-eabi/5.4.1
RM = rm -f
RMDIR = rm -rf
DEVNULL = /dev/null
CC = "$(GCC_ARMCOMPILER)"
LNK = "$(GCC_ARMCOMPILER)"
OBJECTSNAMES = system_msp432p401r.obj startup_msp432p401r_gcc.obj main.obj
OBJECTS = $(addprefix $(OUTPUTDIR), $(OBJECTSNAMES))
NAME = cppTest
OUTPUTDIR ?= ./debug/
CFLAGS = "-I$(SIMPLELINK_MSP432_SDK_INSTALL_DIR)/source" "-I$(SIMPLELINK_MSP432_SDK_INSTALL_DIR)/source/third_party/CMSIS/Include" -D__MSP432P401R__ -DDeviceFamily_MSP432P401x -mcpu=cortex-m4 -march=armv7e-m -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -g -gstrict-dwarf -Wall "-I$(GCC_ARMCOMPILER_LIBS)/include/newlib-nano" "-I$(GCC_ARMCOMPILER_LIBS)/include"
LFLAGS = -Wl,-T,./msp432p401r.lds "-Wl,-Map,$(OUTPUTDIR)/$(NAME).map" "-L$(SIMPLELINK_MSP432_SDK_INSTALL_DIR)/source/ti/display/lib" -l:display.am4fg "-L$(SIMPLELINK_MSP432_SDK_INSTALL_DIR)/source/ti/drivers/lib" -l:drivers_msp432p401x.am4fg "-L$(SIMPLELINK_MSP432_SDK_INSTALL_DIR)/source/third_party/fatfs/lib" -l:fatfs.am4fg "-L$(SIMPLELINK_MSP432_SDK_INSTALL_DIR)/source/ti/devices/msp432p4xx/driverlib/gcc" -l:msp432p4xx_driverlib.a -march=armv7e-m -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -static -Wl,--gc-sections "-L$(GCC_ARMCOMPILER_LIBS)/lib/thumb/v7e-m/fpv4-sp/hard" -lgcc -lc -lm -lnosys --specs=nano.specs
all: outdir $(NAME).out
outdir:
@ mkdir -p $(OUTPUTDIR)
system_msp432p401r.obj: ./system_msp432p401r.c
@ echo Building $@
@ $(CC) $(CFLAGS) $< -c -o $(OUTPUTDIR)/$@
startup_msp432p401r_gcc.obj: ./startup_msp432p401r_gcc.c
@ echo Building $@
@ $(CC) $(CFLAGS) $< -c -o $(OUTPUTDIR)/$@
main.obj: ./main.cc
@ echo Building $@
@ $(GXX_ARMCOMPILER) -std=gnu++11 $(CFLAGS) $< -c -o $(OUTPUTDIR)/$@
$(NAME).out: $(OBJECTSNAMES)
@ echo linking...
@ $(LNK) $(OBJECTS) $(LFLAGS) -o $(OUTPUTDIR)/$(NAME).out
clean:
@ echo Cleaning...
@ $(RM) $(OBJECTS) > $(DEVNULL) 2>&1
@ $(RM) $(OUTPUTDIR)/$(NAME).out > $(DEVNULL) 2>&1
@ $(RM) $(OUTPUTDIR)/$(NAME).map > $(DEVNULL) 2>&1
@ rm -rf $(OUTPUTDIR)
Currently I am compiling everything with g++ and I put extern "C" around the two c source files inside if defs.
When I use gcc and g++ together, the C code works, and the C++ code works, but I can't link them.
Any thoughts?