Skip to content

Added c++ linker command to allow to include libstdc++ when linking. #276

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

Merged
merged 6 commits into from
Jul 11, 2018
Merged

Added c++ linker command to allow to include libstdc++ when linking. #276

merged 6 commits into from
Jul 11, 2018

Conversation

helmut64
Copy link
Contributor

This is needed otherwise the template C++ container support
are missing. The "compiler.c.elf.cmd" specifies the linker,
the C linker was wrong here and does not work for true C++ apps.

This change does not hurt because when no libstdc++ features are
being used there is no change.

Changed the Arduino function map() into Arduino_map(). This is needed
otherwise it clashes with the C++ template class. e.g.: #include

PS: I also added the same changes into the 32-bit Arduino ESP32 release.

This is needed otherwise the template C++ container support
are missing. The "compiler.c.elf.cmd" specifies the linker,
the C linker was wrong here and does not work for true C++ apps.

This change does not hurt because when no libstdc++ features are
being used there is no change.

Changed the Arduino function map() into Arduino_map(). This is needed
otherwise it clashes with the C++ template class. e.g.: #include <map>
@helmut64
Copy link
Contributor Author

The other map is the regular C++ libstdc++ map which is being used in all C++ books, C++ projects, etc.. C++ is now here with this for more than 20 years. It is a fault by Arduino to use this name. It is also little being used compared to the C++ map.

@helmut64
Copy link
Contributor Author

PS: I also checked the memory size of apps for the D21 SAMD platform, there is absolutely no difference with this patch.

@helmut64
Copy link
Contributor Author

I believe now it should work.

@helmut64
Copy link
Contributor Author

Why does it take several months to review and integrate my enhancement.

@helmut64
Copy link
Contributor Author

@facchinm please help to integrate the pull requests, my one is sitting here for almost 8 month now, it takes only 5 minutes to review and commit it.
Regards Helmut

@PaulStoffregen
Copy link

Changed the Arduino function map() into Arduino_map().

How does this work? Looking at the files changed tab, I see a define, but nothing else which would allow the huge number of programs people have written with map() to compile and actually work. Did I miss something?

Hopefully you can understand how a change that breaks (or likely breaks) one of Arduino's very widely used features would never be accepted?

@helmut64
Copy link
Contributor Author

helmut64 commented Jun 25, 2018

@PaulStoffregen Hi Paul, the map problem is resolved by using the complete C++ namespace name std::map for C++. The remaining issue is the wrong linker statement. It can be fixed via

< compiler.c.elf.cmd=arm-none-eabi-gcc

compiler.c.elf.cmd=arm-none-eabi-g++

With the ESP32 this is no problem, for the the D21/SAMD platform switching to the g++ for linking will resolve the STL C++ libraries when used.

Do you have merge rights?

It is just disappointing that I do a fix, for the ESP32 it took a few days to get it merged/resolved, for the SAMD nothing happens for 7 month.

Regards Helmut

@cmaglie
Copy link
Member

cmaglie commented Jun 27, 2018

I tried this with the example:

void setup() {
  int x = map(1,2,3,4,5);
}
void loop() { }

and it fails with:

/tmp/arduino_modified_sketch_608153/sketch_jun27a.ino: In function 'void setup()':
sketch_jun27a:3:24: error: 'Arduino_map' was not declared in this scope
   int x = map(1,2,3,4,5);
                        ^
/tmp/arduino_modified_sketch_608153/sketch_jun27a.ino:3:7: warning: unused variable 'x' [-Wunused-variable]
   int x = map(1,2,3,4,5);
       ^
exit status 1
'Arduino_map' was not declared in this scope

are you sure that the PR is complete?
I see that there are a bunch of tentative commits that are undone later, maybe you want to clean up the history?

@cmaglie
Copy link
Member

cmaglie commented Jun 27, 2018

Oh I see, I guess this is a leftover:

https://github.com/arduino/ArduinoCore-samd/pull/276/files#diff-9ad272c11f2032a6e0231ebda4438a04R31

so just changing gcc with g++ for linking should be enough?

@helmut64
Copy link
Contributor Author

Yes, just changing the linker to use g++
Regards Helmut

@cmaglie cmaglie merged commit 906dbd9 into arduino:master Jul 11, 2018
@cmaglie cmaglie added this to the Release 1.6.20 milestone Jul 11, 2018
@helmut64 helmut64 deleted the SAMD_CPP_FIX branch July 13, 2018 08:35
matthijskooijman added a commit to matthijskooijman/ArduinoCore-sam that referenced this pull request Sep 29, 2020
This ensures some C++-specific symbols, such as
`std::_throw_bad_function_call` and probably others, are automatically
included in the link, preventing linker errors when using some standard
c++ library bits (such as `std::function`).

This follows the same change done for SAMD:

    arduino/ArduinoCore-samd#276
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants