Help me to build FreeRTOS using g++

mleonidos wrote on Sunday, December 28, 2008:

HI. I very need your help )

I want to use c++ with FreeRTOS. I read that I can build FreeRTOS with g++ and use c++. So I downloaded FreeRTOS demo (CORTEX_LM3Sxxxx_Eclipse), and change "arm-none-eabi-gcc" to "arm-none-eabi-g++"…

There was many errors, so I have to add some typecasts and to remove data hiding…

And than he told me this:

ALIGN_STRUCT_END=__attribute\(\(aligned\(4\)\)\) -D sprintf=usprintf -D snprintf=usnprintf -D printf=uipprintf -I …/…/Common/ethernet/uIP/uip-1.0/uip -I ./webserver -ffunction-sections -fdata-sections -I …/…/Common/drivers/LuminaryMicro main.o timertest.o ./ParTest/ParTest.o rit128x96x4.o osram128x64x4.o formike128x128x16.o …/…/Common/drivers/LuminaryMicro/ustdlib.o …/…/Common/Minimal/BlockQ.o …/…/Common/Minimal/blocktim.o …/…/Common/Minimal/death.o …/…/Common/Minimal/integer.o …/…/Common/Minimal/PollQ.o …/…/Common/Minimal/semtest.o …/…/Common/Minimal/GenQTest.o …/…/Common/Minimal/QPeek.o …/…/Common/Minimal/recmutex.o …/…/Common/Minimal/IntQueue.o ./IntQueueTimer.o ./webserver/uIP_Task.o ./webserver/emac.o ./webserver/httpd.o ./webserver/httpd-cgi.o ./webserver/httpd-fs.o ./webserver/http-strings.o …/…/Common/ethernet/uIP/uip-1.0/uip/uip_arp.o …/…/Common/ethernet/uIP/uip-1.0/uip/psock.o …/…/Common/ethernet/uIP/uip-1.0/uip/timer.o …/…/Common/ethernet/uIP/uip-1.0/uip/uip.o …/…/…/Source/list.o …/…/…/Source/queue.o …/…/…/Source/tasks.o …/…/…/Source/portable/GCC/ARM_CM3/port.o …/…/…/Source/portable/MemMang/heap_2.o startup.o …/…/Common/drivers/LuminaryMicro/arm-none-eabi-gcc/libdriver.a …/…/Common/drivers/LuminaryMicro/arm-none-eabi-gcc/libgr.a -nostartfiles -Xlinker -oRTOSDemo.axf -Xlinker -M -Xlinker -Map=rtosdemo.map -Xlinker --no-gc-sections
d:/arm/bin/…/lib/gcc/arm-none-eabi/4.2.3/…/…/…/…/arm-none-eabi/bin/ld.exe: section .ARM.exidx.text._Z29vApplicationStackOverflowHookPP19tskTaskControlBlockPa [00016184 -> 0001618b] overlaps section .data [00016184 -> 000167d7]
d:/arm/bin/…/lib/gcc/arm-none-eabi/4.2.3/…/…/…/…/arm-none-eabi/bin/ld.exe: section .bss [000167d8 -> 000209c3] overlaps section .ARM.exidx.text._Z10clock_initv [000167d4 -> 000167db]
d:/arm/bin/…/lib/gcc/arm-none-eabi/4.2.3/…/…/…/…/arm-none-eabi/bin/ld.exe: section .ARM.extab.text._Z28vApplicationProcessFormInputPcl [000167dc -> 000167e7] overlaps section .bss [000167d8 -> 000209c3]
main.o: In function `vOLEDTask’:
C:\Documents and Settings\Leonidos\Desktop\FreeRTOS\Demo\CORTEX_LM3Sxxxx_Eclipse\RTOSDemo/main.c:432: undefined reference to `usprintf’
./webserver/httpd.o: In function `handle_input’:
C:\Documents and Settings\Leonidos\Desktop\FreeRTOS\Demo\CORTEX_LM3Sxxxx_Eclipse\RTOSDemo/webserver/httpd.c:256: undefined reference to `http_get’
C:\Documents and Settings\Leonidos\Desktop\FreeRTOS\Demo\CORTEX_LM3Sxxxx_Eclipse\RTOSDemo/webserver/httpd.c:256: undefined reference to `http_get’
C:\Documents and Settings\Leonidos\Desktop\FreeRTOS\Demo\CORTEX_LM3Sxxxx_Eclipse\RTOSDemo/webserver/httpd.c:266: undefined reference to `http_index_html’
C:\Documents and Settings\Leonidos\Desktop\FreeRTOS\Demo\CORTEX_LM3Sxxxx_Eclipse\RTOSDemo/webserver/httpd.c:266: undefined reference to `http_index_html’
C:\Documents and Settings\Leonidos\Desktop\FreeRTOS\Demo\CORTEX_LM3Sxxxx_Eclipse\RTOSDemo/webserver/httpd.c:287: undefined reference to `http_referer’
C:\Documents and Settings\Leonidos\Desktop\FreeRTOS\Demo\CORTEX_LM3Sxxxx_Eclipse\RTOSDemo/webserver/httpd.c:287: undefined reference to `http_referer’
./webserver/httpd.o: In function `send_headers’:
C:\Documents and Settings\Leonidos\Desktop\FreeRTOS\Demo\CORTEX_LM3Sxxxx_Eclipse\RTOSDemo/webserver/httpd.c:198: undefined reference to `http_content_type_binary’
C:\Documents and Settings\Leonidos\Desktop\FreeRTOS\Demo\CORTEX_LM3Sxxxx_Eclipse\RTOSDemo/webserver/httpd.c:198: undefined reference to `http_content_type_binary’
C:\Documents and Settings\Leonidos\Desktop\FreeRTOS\Demo\CORTEX_LM3Sxxxx_Eclipse\RTOSDemo/webserver/httpd.c:198: undefined reference to `http_content_type_binary’
C:\Documents and Settings\Leonidos\Desktop\FreeRTOS\Demo\CORTEX_LM3Sxxxx_Eclipse\RTOSDemo/webserver/httpd.c:198: undefined reference to `http_content_type_binary’
C:\Documents and Settings\Leonidos\Desktop\FreeRTOS\Demo\CORTEX_LM3Sxxxx_Eclipse\RTOSDemo/webserver/httpd.c:199: undefined reference to `http_html’
C:\Documents and Settings\Leonidos\Desktop\FreeRTOS\Demo\CORTEX_LM3Sxxxx_Eclipse\RTOSDemo/webserver/httpd.c:199: undefined reference to `http_html’
C:\Documents and Settings\Leonidos\Desktop\FreeRTOS\Demo\CORTEX_LM3Sxxxx_Eclipse\RTOSDemo/webserver/httpd.c:199: undefined reference to `http_shtml’

Please give me some advice to undestang what is going on there. )
Thanks.

mleonidos wrote on Sunday, December 28, 2008:

I’ve read that I can compile .c files as C and .cpp files as C++… but I cant write such make file… I found some, but it isn’t work…

It would be wonderful if someone give us instructions how to use C++ with FreeRTOS. Maybe some one have make file I need. I ready to donate some money to person who help me to solve my problems.

Thanks for your help.

spacewrench wrote on Monday, December 29, 2008:

I’ve been using FreeRTOS with g++ on LM3Sxxxx processors for a while now.  You shouldn’t try to compile the FreeRTOS base files with c++; it’s probably too much work, and no benefit.  My Makefiles use gcc for the FreeRTOS files and g++ for my own code.  Link with g++ and you should be good to go.  Here is my Makefile for the USB device I’ve been working on.  It is more complicated than you really need, because I use the same code & Makefiles to build binaries for LPC2K and GameBoy SP/DS machines (the USB code doesn’t work on the GameBoy, of course).

I have a clean version of FreeRTOS installed in a directory tree outside my own code, and I use VPATH to help make find the files.  (I think I may have had to copy/modify one or two FreeRTOS files to make all this work, but it’s worth the small amount of hassle for the ability to swap in a new version of FreeRTOS without having to separate out my code or figure out what changes I made.)

##
## Makefile
## 
## Made by dave m.  <xxx@yyy.com>
##
## Started on  Sat Jan 19 18:02:01 2008 dave m.
## Last update Sat Jan 19 18:02:01 2008 dave m.
##

    CPU_FAMILY        =    LM3Sx
#    CPU_FAMILY        =    LPC2k
#    CPU_FAMILY        =    GBA

        TARGET        =    USBTest

        SOURCES        =    main.cc
                        mydevice.cc
                        util.cc
                        usb.cc
                        usb-descriptors.cc
                        usb-endpoints.cc
                        usb-interface.cc
                        usb-configuration.cc
                        usb-device.cc
                        usb-string.cc
                        usb-ep0.cc
                        usb-debug.cc
                        serial_io.cc
                        list.c
                        queue.c
                        tasks.c
                        port.c
                        heap_1.c

    LOADLIBES        =    -lEMF
                        -lc
                        -lgcc

#############################################################################
#############################################################################
#############################################################################

ifeq ($(CPU_FAMILY),LM3Sx)
        CPUFLAGS    =    -mcpu=cortex-m3 -mthumb
        DEFINES        +=    -DGCC_ARMCM3
FreeRTOS_PLATFORM    =    GCC/ARM_CM3
endif
ifeq ($(CPU_FAMILY),LPC2k)
        CPUFLAGS    =    -mcpu=arm7tdmi -march=armv4t -mthumb-interwork
#        CPUFLAGS    =    -mcpu=arm7tdmi -march=armv4t -mthumb -mthumb-interwork
        DEFINES        +=    -DGCC_LPC2k
FreeRTOS_PLATFORM    =    GCC/ARM7_LPC2k
endif
ifeq ($(CPU_FAMILY),GBA)
        CPUFLAGS    =    -mcpu=arm7tdmi -march=armv4t -mthumb-interwork
#        CPUFLAGS    =    -mcpu=arm7tdmi -march=armv4t -mthumb -mthumb-interwork
        DEFINES        +=    -DGCC_GBA
FreeRTOS_PLATFORM    =    GCC/ARM7_GBA
endif

            VPATH    =    …/…/…/FreeRTOS/Source
                        …/…/…/FreeRTOS/Source/portable/MemMang
                        …/…/…/FreeRTOS/Source/portable/$(FreeRTOS_PLATFORM)

            MLDIR    =    $(shell $(CC) $(CPUFLAGS) -print-multi-directory)

        LIBDIRS        =    -L…/…/lib/$(MLDIR)

ifneq (,$(findstring -mthumb,$(filter-out -mthumb-interwork,$(CPUFLAGS))))
        DEFINES        +=    -DTHUMB
endif

        INCLUDES    +=    -I.
                        -I…/…/include
                        -I…/…/include/$(CPU_FAMILY)
                        -I…/…/Source/include
                        -I…/…/…/Luminary

        CPPFLAGS    ?=    $(DEFINES) $(INCLUDES)

        CDEBUGFLAGS    ?=    -O3 -g -Wall
                        --no-exceptions
                        -mfloat-abi=soft -mfpu=vfp
                        $(CPUFLAGS)

        CFLAGS        +=    $(CDEBUGFLAGS)
        CXXFLAGS    +=    $(CDEBUGFLAGS)
                        --no-rtti
                        -fno-threadsafe-statics

        LDFLAGS        =    -Wl,-N,-M,–demangle,–sort-common,-u,__boot__
                        -Wl,-T,…/…/etc/$(CPU_FAMILY)-ld.cmd
                        -Wl,–defsym -Wl,__cxa_pure_virtual=0
                        -nostdlib
                        -mfloat-abi=soft -mfpu=vfp
                        $(CPUFLAGS)
                        $(LIBDIRS)

        TOOLPREFIX    =    arm-elf-
            CC        =    $(TOOLPREFIX)gcc
            CXX        =    $(TOOLPREFIX)g++
            LD        =    $(TOOLPREFIX)ld
            AS        =    $(TOOLPREFIX)as
            AR        =    $(TOOLPREFIX)ar
        OBJCOPY        =    $(TOOLPREFIX)objcopy
        OBJDUMP        =    $(TOOLPREFIX)objdump

            sOBJ    =    $(SOURCES:.s=.o)
            cOBJ    =    $(sOBJ:.c=.o)
            OBJ        =    $(cOBJ:.cc=.o)

all:    $(TARGET).bin

$(TARGET):    $(OBJ)
    $(CXX) $(LDFLAGS) -o $@ $^ $(LOADLIBES) > $@.map
    $(OBJDUMP) --disassemble-all --demangle $@ > $@.lst

clean:
    $(RM) $(TARGET) $(TARGET).hex $(TARGET).bin $(TARGET).map $(TARGET).lst
        $(OBJ) *.d

%.hex:    %
    $(OBJCOPY) -S -O ihex $< $@

%.bin:    %
    $(OBJCOPY) -S -O binary $< $@