This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP432P401R: I want to use c++ for my project, but am having troubles with my makefile. (GCC)

Part Number: MSP432P401R

I took the driverlib empty gcc project, and added some simple c++ code and created and destroyed an object in the main function.  I also put

#ifdef _cplusplus
extern "C"
{
#endif

//code

#ifdef _cplusplus
}
#endif

around the startup and system c files.

The code compiles, but does not link. It gives me this warning (repeatedly):

warning: /usr/lib/gcc/arm-none-eabi/5.4.1/../../../arm-none-eabi/lib/armv7e-m/fpu/libstdc++_nano.a(atexit_arm.o) uses 2-byte wchar_t yet the output is to use 4-byte wchar_t; use of wchar_t values across objects may fail

and this error:

/usr/lib/gcc/arm-none-eabi/5.4.1/../../../arm-none-eabi/lib/armv7e-m/fpu/libc_nano.a(lib_a-abort.o): In function `abort':
/build/newlib-XAuz1P/newlib-2.4.0.20160527/build_nano/arm-none-eabi/armv7e-m/fpu/newlib/libc/stdlib/../../../../../../../newlib/libc/stdlib/abort.c:63: undefined reference to `_exit'
/usr/lib/gcc/arm-none-eabi/5.4.1/../../../arm-none-eabi/lib/armv7e-m/fpu/libc_nano.a(lib_a-exit.o): In function `exit':
/build/newlib-XAuz1P/newlib-2.4.0.20160527/build_nano/arm-none-eabi/armv7e-m/fpu/newlib/libc/stdlib/../../../../../../../newlib/libc/stdlib/exit.c:70: undefined reference to `_exit'
/usr/lib/gcc/arm-none-eabi/5.4.1/../../../arm-none-eabi/lib/armv7e-m/fpu/libc_nano.a(lib_a-openr.o): In function `_open_r':
/build/newlib-XAuz1P/newlib-2.4.0.20160527/build_nano/arm-none-eabi/armv7e-m/fpu/newlib/libc/reent/../../../../../../../newlib/libc/reent/openr.c:59: undefined reference to `_open'
/usr/lib/gcc/arm-none-eabi/5.4.1/../../../arm-none-eabi/lib/armv7e-m/fpu/libc_nano.a(lib_a-sbrkr.o): In function `_sbrk_r':
/build/newlib-XAuz1P/newlib-2.4.0.20160527/build_nano/arm-none-eabi/armv7e-m/fpu/newlib/libc/reent/../../../../../../../newlib/libc/reent/sbrkr.c:58: undefined reference to `_sbrk'
/usr/lib/gcc/arm-none-eabi/5.4.1/../../../arm-none-eabi/lib/armv7e-m/fpu/libc_nano.a(lib_a-signalr.o): In function `_kill_r':
/build/newlib-XAuz1P/newlib-2.4.0.20160527/build_nano/arm-none-eabi/armv7e-m/fpu/newlib/libc/reent/../../../../../../../newlib/libc/reent/signalr.c:61: undefined reference to `_kill'
/usr/lib/gcc/arm-none-eabi/5.4.1/../../../arm-none-eabi/lib/armv7e-m/fpu/libc_nano.a(lib_a-signalr.o): In function `_getpid_r':
/build/newlib-XAuz1P/newlib-2.4.0.20160527/build_nano/arm-none-eabi/armv7e-m/fpu/newlib/libc/reent/../../../../../../../newlib/libc/reent/signalr.c:97: undefined reference to `_getpid'
/usr/lib/gcc/arm-none-eabi/5.4.1/../../../arm-none-eabi/lib/armv7e-m/fpu/libc_nano.a(lib_a-writer.o): In function `_write_r':
/build/newlib-XAuz1P/newlib-2.4.0.20160527/build_nano/arm-none-eabi/armv7e-m/fpu/newlib/libc/reent/../../../../../../../newlib/libc/reent/writer.c:58: undefined reference to `_write'
/usr/lib/gcc/arm-none-eabi/5.4.1/../../../arm-none-eabi/lib/armv7e-m/fpu/libc_nano.a(lib_a-closer.o): In function `_close_r':
/build/newlib-XAuz1P/newlib-2.4.0.20160527/build_nano/arm-none-eabi/armv7e-m/fpu/newlib/libc/reent/../../../../../../../newlib/libc/reent/closer.c:53: undefined reference to `_close'
/usr/lib/gcc/arm-none-eabi/5.4.1/../../../arm-none-eabi/lib/armv7e-m/fpu/libc_nano.a(lib_a-fstatr.o): In function `_fstat_r':
/build/newlib-XAuz1P/newlib-2.4.0.20160527/build_nano/arm-none-eabi/armv7e-m/fpu/newlib/libc/reent/../../../../../../../newlib/libc/reent/fstatr.c:62: undefined reference to `_fstat'
/usr/lib/gcc/arm-none-eabi/5.4.1/../../../arm-none-eabi/lib/armv7e-m/fpu/libc_nano.a(lib_a-isattyr.o): In function `_isatty_r':
/build/newlib-XAuz1P/newlib-2.4.0.20160527/build_nano/arm-none-eabi/armv7e-m/fpu/newlib/libc/reent/../../../../../../../newlib/libc/reent/isattyr.c:58: undefined reference to `_isatty'
/usr/lib/gcc/arm-none-eabi/5.4.1/../../../arm-none-eabi/lib/armv7e-m/fpu/libc_nano.a(lib_a-lseekr.o): In function `_lseek_r':
/build/newlib-XAuz1P/newlib-2.4.0.20160527/build_nano/arm-none-eabi/armv7e-m/fpu/newlib/libc/reent/../../../../../../../newlib/libc/reent/lseekr.c:58: undefined reference to `_lseek'
/usr/lib/gcc/arm-none-eabi/5.4.1/../../../arm-none-eabi/lib/armv7e-m/fpu/libc_nano.a(lib_a-readr.o): In function `_read_r':
/build/newlib-XAuz1P/newlib-2.4.0.20160527/build_nano/arm-none-eabi/armv7e-m/fpu/newlib/libc/reent/../../../../../../../newlib/libc/reent/readr.c:58: undefined reference to `_read'
collect2: error: ld returned 1 exit status
makefile:45: recipe for target 'cppTest.out' failed
make: *** [cppTest.out] Error 1

This is my current makefile:

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++14 $(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)

I think it is just a flag that is wrong but I am not sure. 

  • Jordan,
    I am looking to confirm that the drivers will work with C++. I will try and have a response by Tuesday, 3/20.

    Regards,
    Chris
  • I have upgraded to CCSv8.  (It feels like a large improvement over 7.)  Anyways I attempted a similar project, but attacked it differently.  I took the driverlib gcc empty project example, and deleted main.c.  I then created a new source file main.cpp.  In this I have the main function that halts the watchdog timer, and then loops forever.  The project compiles, and runs. It does complain about C99 not being a valid standard.  (I would like to change it to g++98.)  But I cannot find the correct option in the Project Settings.

    Anyways I created a class named Pin.  It has private variables short pin and short port.  Its constructor sets these variables from the constructors arguments. In main.cpp I include the Pin.h file, and the project still compiles.

    In the main function after halting the watchdog timer, but before the infinite loop, I create a Pin, and then destroy the pin.

    Pin *p = new Pin(1,1);
    delete p;

    This code fails to compile.

    When I get back to my computer I will post the errors and the project.

  • Jordan,
    Thank you for the follow up and I apologize for not meeting my commitment. I have been unable to locate any documentation regarding the linking of the driverLib libraries into C++, so I am thinking the libraries will not work with C++ but so far unable to confirm.

    Chris
  • Did you also update the compiler? ARM gcc-arm-none-eabi-7-2017-q4-major

    Dependencies
    This release was validated with the following components:

    Code Composer Studio 8.0.0
    ARM 18.1.0.LTS
    XDCTools 3.50.05.12
    GNU Code Generation Tools
    ARM gcc-arm-none-eabi-7-2017-q4-major
    IAR Code Generation Tools
    ARM 8.20.2
    Keil uVision (A subset of the SDK components support Keil IDE)
    5.23
    TexasInstruments.MSP432E4_DFP.3.2.3.pack
  • I updated everything, and it is now working!

**Attention** This is a public forum