New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstract class breaks compile for mbed LPC1768 #666

Closed
EraYaN opened this Issue May 20, 2016 · 3 comments

Comments

Projects
None yet
3 participants
@EraYaN

EraYaN commented May 20, 2016

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

This comment has been minimized.

EraYaN commented May 23, 2016

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 valeros added this to the 2.9.2 milestone May 24, 2016

@valeros valeros added bug and removed help wanted labels May 24, 2016

valeros added a commit that referenced this issue Jun 2, 2016

@valeros

This comment has been minimized.

Member

valeros commented Jun 2, 2016

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

ivankravets added a commit that referenced this issue Jun 2, 2016

ivankravets added a commit that referenced this issue Jun 2, 2016

Merge branch 'develop' into feature/platformio-30
* develop:
  Version bump to 2.9.2 (issues #641, #645, #648, #652, #664, #665, #666, #671, #674)
  Fix issue with ARM mbed framework when abstract class breaks compile for LPC1768 // Resolve #666
  Fix issue with ARM mbed framework and multiple definition errors   on FRDM-KL46Z board // Resolve #641
  List embedded boards in docs
  Fix multiple definition in mbed framework when using abstract class // Issue #641, #666
  Add "stlink" as the default uploader for STM32 Discovery boards // Resolve #665
  Implement grep serial ports for Windows
  Remove unused imports
  Minor improvements
  Fix PyLint's "misplaced-comparison-constant"
  Use $PROGNAME instead static name when looking for the firmware
  Update title of the article
  Add new articles
  Link Community Forums FAQ with Docs FAQ
  Grep for "/dev/cu.*" on OS X
  Skip grep search for serial ports on Windows machines
  Improve firmware uploading to Arduino Leonardo based boards
  Add MinGW to the PATH

# Conflicts:
#	docs/index.rst
#	docs/platforms/creating_board.rst
#	docs/projectconf.rst
#	docs/userguide/platforms/cmd_install.rst
#	platformio/__init__.py
#	platformio/builder/scripts/atmelavr.py
#	platformio/builder/scripts/atmelsam.py
#	platformio/builder/scripts/frameworks/mbed.py
@EraYaN

This comment has been minimized.

EraYaN commented Jun 6, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment