platformio / platformio-core

Your Gateway to Embedded Software Development Excellence :alien:
https://platformio.org
Apache License 2.0
7.95k stars 792 forks source link

Abstract class breaks compile for mbed LPC1768 #666

Closed EraYaN closed 8 years ago

EraYaN commented 8 years ago

Configuration

Operating system: Win 10 x64

PlatformIO Version (platformio --version): 2.9.1

Description of problem

When building for LPC1768 target and when your code contains abstract classes (with pure virtual members), the following error occur (PlatformIO CLI, or Visual Studio)

.pioenvs\lpc1768\libFrameworkMbed.a(retarget.o): In function `__gnu_cxx::__verbose_terminate_handler()':
retarget.cpp:(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x0): multiple definition of `__gnu_cxx::__verbose_terminate_handler()'
c:/users/erwin/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv7-m\libstdc++_s.a(vterminate.o):vterminate.cc:(.text._ZN9__gnu_cxx27__verbose_terminate_ha
ndlerEv+0x0): first defined here

Steps to Reproduce

  1. Download sample project, here: https://erayan.com/shared/Test.zip
  2. Run platformio run in Test/
    or
  3. Open .sln in vs2015 and right click project and click "Build", PC version included.

    Actual Results

[05/20/16 15:47:33] Processing lpc1768 (platform: nxplpc, targets: upload, framework: mbed, board: lpc1768)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
arm-none-eabi-g++ -o .pioenvs\lpc1768\src\ConstantAlgorithm.o -c -std=gnu++98 -fno-rtti -fdata-sections -ffunction-sections -Wno-unused-parameter -fno-exceptions -Wextra -fno-delete-null-pointer-checks -fmessage-length=0
 -mthumb -Wno-missing-field-initializers -c -fno-builtin -O2 -fomit-frame-pointer -Wall -MMD -mcpu=cortex-m3 -DTOOLCHAIN_GCC_ARM -DTOOLCHAIN_GCC -DARM_MATH_CM3 -DTARGET_LIKE_CORTEX_M3 -DTARGET_CORTEX_M -DTARGET_LIKE_MBED
 -DTARGET_LPC176X -DTARGET_NXP -DTARGET_LPC1768 -D__CORTEX_M3 -DTARGET_M3 -DTARGET_MBED_LPC1768 -D__MBED__=1 -DMBED_BUILD_TIMESTAMP=1459421819.31 -DPLATFORMIO=020901 -I.pioenvs\lpc1768\FrameworkMbedInc248832578 -I.pioenv
s\lpc1768\FrameworkMbedInc-213564679 -I.pioenvs\lpc1768\FrameworkMbedInc-250686161 -I.pioenvs\lpc1768\FrameworkMbedInc549023428 -I.pioenvs\lpc1768\FrameworkMbedInc-642763518 -I.pioenvs\lpc1768\FrameworkMbedInc818999332 -
I.pioenvs\lpc1768\FrameworkMbedInc1648309630 -I.pioenvs\lpc1768\FrameworkMbedInc-550770547 src\ConstantAlgorithm.cpp
arm-none-eabi-g++ -o .pioenvs\lpc1768\src\IAlgorithm.o -c -std=gnu++98 -fno-rtti -fdata-sections -ffunction-sections -Wno-unused-parameter -fno-exceptions -Wextra -fno-delete-null-pointer-checks -fmessage-length=0 -mthum
b -Wno-missing-field-initializers -c -fno-builtin -O2 -fomit-frame-pointer -Wall -MMD -mcpu=cortex-m3 -DTOOLCHAIN_GCC_ARM -DTOOLCHAIN_GCC -DARM_MATH_CM3 -DTARGET_LIKE_CORTEX_M3 -DTARGET_CORTEX_M -DTARGET_LIKE_MBED -DTARG
ET_LPC176X -DTARGET_NXP -DTARGET_LPC1768 -D__CORTEX_M3 -DTARGET_M3 -DTARGET_MBED_LPC1768 -D__MBED__=1 -DMBED_BUILD_TIMESTAMP=1459421819.31 -DPLATFORMIO=020901 -I.pioenvs\lpc1768\FrameworkMbedInc248832578 -I.pioenvs\lpc17
68\FrameworkMbedInc-213564679 -I.pioenvs\lpc1768\FrameworkMbedInc-250686161 -I.pioenvs\lpc1768\FrameworkMbedInc549023428 -I.pioenvs\lpc1768\FrameworkMbedInc-642763518 -I.pioenvs\lpc1768\FrameworkMbedInc818999332 -I.pioen
vs\lpc1768\FrameworkMbedInc1648309630 -I.pioenvs\lpc1768\FrameworkMbedInc-550770547 src\IAlgorithm.cpp
arm-none-eabi-g++ -o .pioenvs\lpc1768\src\main.o -c -std=gnu++98 -fno-rtti -fdata-sections -ffunction-sections -Wno-unused-parameter -fno-exceptions -Wextra -fno-delete-null-pointer-checks -fmessage-length=0 -mthumb -Wno
-missing-field-initializers -c -fno-builtin -O2 -fomit-frame-pointer -Wall -MMD -mcpu=cortex-m3 -DTOOLCHAIN_GCC_ARM -DTOOLCHAIN_GCC -DARM_MATH_CM3 -DTARGET_LIKE_CORTEX_M3 -DTARGET_CORTEX_M -DTARGET_LIKE_MBED -DTARGET_LPC
176X -DTARGET_NXP -DTARGET_LPC1768 -D__CORTEX_M3 -DTARGET_M3 -DTARGET_MBED_LPC1768 -D__MBED__=1 -DMBED_BUILD_TIMESTAMP=1459421819.31 -DPLATFORMIO=020901 -I.pioenvs\lpc1768\FrameworkMbedInc248832578 -I.pioenvs\lpc1768\Fra
meworkMbedInc-213564679 -I.pioenvs\lpc1768\FrameworkMbedInc-250686161 -I.pioenvs\lpc1768\FrameworkMbedInc549023428 -I.pioenvs\lpc1768\FrameworkMbedInc-642763518 -I.pioenvs\lpc1768\FrameworkMbedInc818999332 -I.pioenvs\lpc
1768\FrameworkMbedInc1648309630 -I.pioenvs\lpc1768\FrameworkMbedInc-550770547 src\main.cpp
arm-none-eabi-ar rcs .pioenvs\lpc1768\libFrameworkMbed.a C:\Users\Test\.platformio\packages\framework-mbed\variant\LPC1768\mbed\TARGET_LPC1768\TOOLCHAIN_GCC_ARM\startup_LPC17xx.o C:\Users\Test\.platformio\packages\fram
ework-mbed\variant\LPC1768\mbed\TARGET_LPC1768\TOOLCHAIN_GCC_ARM\cmsis_nvic.o C:\Users\Test\.platformio\packages\framework-mbed\variant\LPC1768\mbed\TARGET_LPC1768\TOOLCHAIN_GCC_ARM\system_LPC17xx.o C:\Users\Test\.plat
formio\packages\framework-mbed\variant\LPC1768\mbed\TARGET_LPC1768\TOOLCHAIN_GCC_ARM\retarget.o C:\Users\Test\.platformio\packages\framework-mbed\variant\LPC1768\mbed\TARGET_LPC1768\TOOLCHAIN_GCC_ARM\board.o
src\main.cpp: In function 'int main()':
src\main.cpp:9:8: warning: unused variable 'testCurrent' [-Wunused-variable]
float testCurrent = alg->GetCurrent(); //should be 4.5
^
src\main.cpp:10:8: warning: unused variable 'testDuty' [-Wunused-variable]
float testDuty = alg->GetDuty(); //should be 0.5
^
arm-none-eabi-g++ -o .pioenvs\lpc1768\firmware.elf -Wl,--gc-sections -Wl,--wrap,main -mcpu=cortex-m3 -mthumb --specs=nano.specs "-u _printf_float" "-u _scanf_float" -Wl,-T"C:\Users\Test\.platformio\packages\framework-mb
ed\variant\LPC1768\mbed\TARGET_LPC1768\TOOLCHAIN_GCC_ARM\LPC1768.ld" .pioenvs\lpc1768\src\ConstantAlgorithm.o .pioenvs\lpc1768\src\IAlgorithm.o .pioenvs\lpc1768\src\main.o -LC:\Users\Test\.platformio\packages\ldscripts
-LC:\Users\Test\.platformio\packages\framework-mbed\variant\LPC1768\mbed\TARGET_LPC1768\TOOLCHAIN_GCC_ARM -L.pioenvs\lpc1768 -Wl,--start-group -lstdc++ -lsupc++ -lnosys -lmbed -lc -lgcc .pioenvs\lpc1768\libFrameworkMbed
.a -lc -lgcc -lm -Wl,--end-group
.pioenvs\lpc1768\libFrameworkMbed.a(retarget.o): In function `__gnu_cxx::__verbose_terminate_handler()':
retarget.cpp:(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x0): multiple definition of `__gnu_cxx::__verbose_terminate_handler()'
c:/users/erwin/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv7-m\libstdc++_s.a(vterminate.o):vterminate.cc:(.text._ZN9__gnu_cxx27__verbose_terminate_ha
ndlerEv+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
scons: *** [.pioenvs\lpc1768\firmware.elf] Error 1
=============================================================================================== [ ERROR ] Took 1.09 seconds ===============================================================================================

Expected Results

A properly compiled bin.

The mbed online compiler has no issues: http://i.imgur.com/0Tu2vWM.png MSVC has no problems compiling this for x64.

If problems with PlatformIO Build System:

The content of platformio.ini:

[env:lpc1768]
platform = nxplpc
framework = mbed
board = lpc1768
targets = upload

Source file to reproduce issue: (Headers and other files are here: https://erayan.com/shared/Test.zip)

#include "IAlgorithm.h"
#include "ConstantAlgorithm.h"

IAlgorithm *alg;

int main() {
    alg = new ConstantAlgorithm(4.5, 0.5);
    //float testCurrent = alg->GetCurrent(); //should be 4.5
    //float testDuty = alg->GetDuty(); //should be 0.5  
}

Some people suggested it had to do with specs files, but that goes way over my head.

EraYaN commented 8 years ago

If I remove all = 0 parts from the functions in IAlgorithm.h so it looks like this:

#pragma once
#ifndef IALGORITHM_H
#define IALGORITHM_H
class IAlgorithm {
public: 
    virtual ~IAlgorithm() {};
    virtual void Tick(float MeasuredPower) {};
    virtual float GetDuty(void) {};
    virtual float GetCurrent(void) {};
    virtual void ResetTo(float ResetCurrent, float ResetDuty) {};
};
#endif

It all links fine. Although to be able to use abstract classes would be a nice thing. All other compilers (for x86 that is) work fine.

valeros commented 8 years ago

Hi @EraYaN ! Please re-test your project with the latest PlatformIO from the develop branch. Thanks!

EraYaN commented 8 years ago

Thank you for the fix. I updated using pip to 2.9.4. Because it is easier and I saw the version bump. (And I'm lazy ;))

The project compiles fine now. I haven't had the chance to actually try the generated code (no hardware). Will do so Wednesday.