Closed mikrocoder closed 2 years ago
Have taken a look at the vector example in the examples/
directory?
You can't just copy the vector
header file to you project, include it and expect it to work. There is a Makefile
that specifies all compiler flags, include directories and source directories necessary for the avr-libstdc++ to work.
All examples get tested by our CI (Github Action) on every commit automatically and work fine: https://github.com/modm-io/avr-libstdcpp/runs/5250992849?check_suite_focus=true
Hi,
I have now specified all the flags according to the make file in Atmel Studio. It still does not compile with the same errors.
About your objection. How else are you supposed to do it? That is the usual way. Make lib folder known, then include and apply.
You tested this only with the g++? But you write it would also work with the avr-gcc. Which it doesn't. Did you also test it with avr-gcc?
I have now specified all the flags according to the make file in Atmel Studio. It still does not compile with the same errors.
Then your build probably still misses the source files in $(LIB_DIR)/src/*.cc
, see line 18 of the Makefile
.
You tested this only with the g++? But you write it would also work with the avr-gcc. Which it doesn't. Did you also test it with avr-gcc?
[avr-]gcc
/[avr-]g++
are the exact same compiler, except that a call to g++
/avr-g++
enables C++ language support by default. You might have to pass -x c++
to avr-gcc
command to switch on C++ language support.
Which exact compiler version are you using? Which environment (operation system, ...) are you using? Where did you get your avr-gcc compiler?
Have you tried our precompiled avr-gcc v11.2.0? (Only for Linux, looks like you are using Windows.)
What additional compiler flags does you IDE(s) pass to the avr-gcc compiler?
Have you tried compiling the unmodified vector example from this Repo using the Makefile (by just calling make
in the example directory from shell)?
Looking at the error messages you posted in you first comment the problem seems easy: You are missing the operator new()
and operator delete()
implementations.
In the vector example of this repository they come from examples/common/new.cpp
.
This file is added to the sources in line 18 of the Makefile ($(COMMON_DIR)/*.cpp
), so you probably only have to copy that file (and maybe also cxxabi.cpp
and uart.cpp
) to you project, ensure the compiler compiles and links them for your error to disappear.
Hi,
can we speak in german?
I would like to thank you very much for the question.
And thanks for the replies.
So I managed to put this std++ implementation into operation in Arduino.
A few tests still need to be done. Then I would be happy to provide a short guide
Looking at the error messages you posted in you first comment the problem seems easy: You are missing the
operator new()
and operatordelete()
implementations.
I just looked at this post and it's going in the right direction. Raphael (@rleh) is correct and on the right track for this issue.
Indeed, one of the tricky things about std::vector
is that is uses dynamic menory (such as an allocator that reduces to using operators new/delete under the hood). So
If you look at the full template signature of std::vector
, you will see that the second parameter is the allocator used for memory allocation.
Things you can try...
std::array
.I have examples for most of this stuff if you'd like to dive deeper into any of these ideas...
Hello,
it was about how to get the avr-libstdcpp lib running in Atmel Studio on Windows. I was able to solve this with the help of another forum. If you are interested in this ...
You have to specify the path to the include directory in the project properties under directories.
Under Miscellaneous the usual: -std=c++20 -flto -Wno-volatile Under Symbol I enter F_CPU.
And in Solution Explorer you have to add the .cc and .cpp files.
After that you can start with the avr-libstdcpp lib.
If you want to show examples, feel free to do so. :-)
it was about how to get the avr-libstdcpp lib running in Atmel Studio on Windows
Understood. Sorry, I had not understood that point. Yes. Simply add the include path on the compiler command line with the GUI (which boils down to the GCC command line -I
include path syntax).
Not every compiler allows the specification of a path for its STL. GCC, however, odes a fine job on this for AVR and also for other toolchain targets such as ARM. So if you ever get a cool embedable STL, you can use it not only with AVR in Microchip's ATMEL Studio, but also with other targets on other environments.
I do have a related question: I notice you are mentioning the flag -std=c++20
. Have you upgraded the GCC tollchain in your ATMEL Studio? Or does a more modern version or ATMEL Studio install a toolchain beyond GCC 5.4 AVR?
If you want to show examples, feel free to do so
Hi @mikrocoder in another repository, I have some detailed benchmarks running on AVR. Some of them make rather heavy use of C++/STL.
For each benchmark, portd.3
measures the runtime on the scope.
You might enjoy the depth and scope of some of those benchmarks and their enclosing repo. In the root of theproject, there is a workspace for ATMEL Studio.
Hi,
I'll have a look at your examples. Let's see if I understand them. Anyway, thanks for that.
AS always uses its outdated avr-gcc 5.4.0. There is nothing newer. I use my own toolchain with avr-gcc 11.2.0 with binutils 2.38. From the http://packs.download.atmel.com/ are added, see below ... the standard controllers are included anyway.
In Atmel Studio you still have to add the packages in Device Manager. If you want can upload my toolchain to dropbox. Can be included in Atmel Studio and also in Arduino IDE.
Zak Kemble https://blog.zakkemble.net/avr-gcc-builds/ also offers updated toolchains in larger intervals. Only his description for Arduino does not work.
atmega328pb
atmega808
atmega809
atmega1608
atmega1609
atmega3208
atmega3209
atmega4808
atmega4809
attiny202
attiny204
attiny212
attiny214
attiny402
attiny404
attiny406
attiny412
attiny414
attiny416
attiny417
attiny804
attiny806
attiny807
attiny814
attiny816
attiny817
attiny1604
attiny1606
attiny1607
attiny1614
attiny1616
attiny1617
attiny3216
attiny3217
attiny1624
attiny1626
attiny1627
attiny3224
attiny3226
attiny3227
avr32da28
avr32da32
avr32da48
avr64da28
avr64da32
avr64da48
avr64da64
avr128da28
avr128da32
avr128da48
avr128da64
avr32db28
avr32db32
avr32db48
avr64db28
avr64db32
avr64db48
avr64db64
avr128db28
avr128db32
avr128db48
avr128db64
avr16dd14
avr16dd20
avr16dd28
avr16dd32
avr32dd14
avr32dd20
avr32dd28
avr32dd32
avr64dd14
avr64dd20
avr64dd28
avr64dd32
Translated with www.DeepL.com/Translator (free version)
I use my own toolchain with avr-gcc 11.2.0 with binutils 2.38
That is a really good idea. I am glad to hear oyu did that. I'll get back to you if needed.
We are straying just a bit off topic, but for more completeness, one more link...
You might like my build of avr-gcc
found here as a multi-file ZIP archive for windows (but you'll need a copy of libwinpthread-1.dll
).
I solved some of the missing device file problems (but not all of them). I made a bunch of notes on building here.
There are some other target GCC builds there that might interest you as well.
Hello,
there is a new problem. gcc 11.3.0 is out. In it there were changes in the math lib. Now sadly with avr-libstdcpp there is the problem of conflictings declarations and previous declarations. Could this be fixed at some point? My test environment is Windows 10 64bit, Microchip Studio 7 with my toolchains. With avr-gcc 11.2.0 everything was still ok.
Severity Code Description Project File Line
Message 'float copysignf(float, float)' previously defined here avrLibStdCpp c:\avrtoolchain\avr-gcc-11.3.0_mingw32_binutils2.38\avr\include\math.h 389
Message 'float fabsf(float)' previously defined here avrLibStdCpp c:\avrtoolchain\avr-gcc-11.3.0_mingw32_binutils2.38\avr\include\math.h 163
Error conflicting declaration of C function 'bool isfinitef(float)' avrLibStdCpp C:\avrToolchain\avrLibStdCpp\include\cmath 144
Error conflicting declaration of C function 'bool isfinitef(float)' avrLibStdCpp C:\Users\Worker\Documents\Atmel Studio\7.0\WorkSpace_AVR128DB48\avrLibStdCpp\avrLibStdCpp\math.cc 142
Error conflicting declaration of C function 'bool isinff(float)' avrLibStdCpp C:\avrToolchain\avrLibStdCpp\include\cmath 143
Error conflicting declaration of C function 'bool isinff(float)' avrLibStdCpp C:\Users\Worker\Documents\Atmel Studio\7.0\WorkSpace_AVR128DB48\avrLibStdCpp\avrLibStdCpp\math.cc 137
Error conflicting declaration of C function 'bool isnanf(float)' avrLibStdCpp C:\avrToolchain\avrLibStdCpp\include\cmath 142
Error conflicting declaration of C function 'bool isnanf(float)' avrLibStdCpp C:\Users\Worker\Documents\Atmel Studio\7.0\WorkSpace_AVR128DB48\avrLibStdCpp\avrLibStdCpp\math.cc 132
Message previous declaration 'int isfinitef(float)' avrLibStdCpp c:\avrtoolchain\avr-gcc-11.3.0_mingw32_binutils2.38\avr\include\math.h 365
Message previous declaration 'int isfinitef(float)' avrLibStdCpp c:\avrtoolchain\avr-gcc-11.3.0_mingw32_binutils2.38\avr\include\math.h 365
Message previous declaration 'int isinff(float)' avrLibStdCpp c:\avrtoolchain\avr-gcc-11.3.0_mingw32_binutils2.38\avr\include\math.h 358
Message previous declaration 'int isinff(float)' avrLibStdCpp c:\avrtoolchain\avr-gcc-11.3.0_mingw32_binutils2.38\avr\include\math.h 358
Message previous declaration 'int isnanf(float)' avrLibStdCpp c:\avrtoolchain\avr-gcc-11.3.0_mingw32_binutils2.38\avr\include\math.h 348
Message previous declaration 'int isnanf(float)' avrLibStdCpp c:\avrtoolchain\avr-gcc-11.3.0_mingw32_binutils2.38\avr\include\math.h 348
Error recipe for target 'math.o' failed avrLibStdCpp C:\Users\Worker\Documents\Atmel Studio\7.0\WorkSpace_AVR128DB48\avrLibStdCpp\avrLibStdCpp\Release\Makefile 141
Error redefinition of 'float copysignf(float, float)' avrLibStdCpp C:\Users\Worker\Documents\Atmel Studio\7.0\WorkSpace_AVR128DB48\avrLibStdCpp\avrLibStdCpp\math.cc 147
Error redefinition of 'float fabsf(float)' avrLibStdCpp C:\Users\Worker\Documents\Atmel Studio\7.0\WorkSpace_AVR128DB48\avrLibStdCpp\avrLibStdCpp\math.cc 32
gcc 11.3.0 is out
Do you have a build of avr-gcc
11.3 that you're using?
Now sadly with avr-libstdcpp there is the problem of conflictings declarations and previous declarations. Could this be fixed at some point?
This topic is something i can look into. But it might take a bit of time to straighten out the float
, double
and long
double
C/C++ functions for both 32 and 64 bit. It is something I've looked into before, but not fully completed yet.
Hi,
gcc 11.3.0 is out
Do you have a build of
avr-gcc
11.3 that you're using?Yes.
Now sadly with avr-libstdcpp there is the problem of conflictings declarations and previous declarations. Could this be fixed at some point?
This topic is something i can look into. But it might take a bit of time to straighten out the
float
,double
andlong
double
C/C++ functions for both 32 and 64 bit. It is something I've looked into before, but not fully completed yet.
Okay that would be very nice. It does not push. I have plenty of time.
Do you have a build of avr-gcc 11.3 that you're using?
Yes.
Cool. I actually mean, do you have one available that we could use for testing? I can spin one up in a few hours, but if you've got one, that's easier...
Hi,
I can provide. For Windows in .rar and .zip, each as he likes and for Linux. Whereby the Linux version is not tested. I use only the Windows version. I delete again in a few days. Link
I can provide. For Windows in .rar and .zip, each as he likes and for Linux.
Awesome builds @mikrocoder. Many thanks.
OK, so here is the deal... Lines like this are actually incorrect. This is because the proper C-language signature of such functions returns int
instead of bool
.
I have not figured out all the inconsistencies yet. And I'm not sure if compiler option or complete repair is best (as these signatures originate in <math.h>
.
So I have opened a new issue #18 to handle this. I'll try a few things there and report back when done.
Can we now close this issue @mikrocoder (assuming we follow the latest point in #18) ?
Cc: @salkinium and @rleh and @chris-durand
I've given you triage rights @ckormanyos, so that you can manage issues directly.
The first point is finished:
When using this STL library with ATMEL Studio, two thngs are needed:
-I
compiler command line option) the include path of avr-libstdcpp to the command line.The second point (<cmath>
in cimbination with a new GCC 11.3) is being handled in #18.
given you triage rights
Thank you Niklas (@salkinium).
I think I forgot to thank you for your work. Better late than never. :-)
Hi,
your lib looks very promising. Unfortunately there are big problems with it. If I use it with Arduino then the controller always resets.
If I use it in Atmel Studio 7 it always compiles with error messages. Your vector example does not compile either. It doesn't matter if I use an avr-gcc toolchain with gcc 9.3.0 or 11.2.0. Also in the Arduino IDE.
I can include vector without errors, but when I use it, it doesn't compile anymore.
Now I wanted to ask in which IDE do you program? In which environment did you test all this? According to your description it should work with avr-gcc.
2 Examples with Atmel Studio 7.
Output
Output
Translated with www.DeepL.com/Translator (free version)