Makefile.{base,include}: Fix linking for C++ code in external modules#14481
Makefile.{base,include}: Fix linking for C++ code in external modules#14481benpicco merged 5 commits intoRIOT-OS:masterfrom
Conversation
|
Note: This changes behavior slightly. If in master an application used C++ code, it will trigger the following behavior
With this PR the behavior is as follows:
In some cases this could be seen as a regression, as previously dropping C++ code in the application without Auto-magically detecting C++ code and using the feature |
|
Let's see how many apps will complain about this. If all apps build without problem, I would say we merge this into the release before feature freeze, otherwise we don't. I see this more as an enhancement BTW than a bug fix, as it adds a warning about wrong usage rather than fixing something in the code :-). |
|
Nope, lots of boards and applications failing, so sorry, postponing for next release. |
|
Please squash! |
When mixing C and C++ code, $(CXX) has to be used for linking. Prior to this commit, the build system automatically uses $(CXX) if the application contains C++ source code. However, if C++ is used in an module only, $(CC) is still used. This has not let to problems, as internal modules must be written in C. For external modules this restriction does not apply. This commit checks if the cpp feature is used. In that case, $(CXX) is used for linking over $(CC). This way external modules may use C++ code.
If external modules use C++ code and forget to require the `cpp` feature, linking will still take places using $(CC). This commit adds a check if C++ code was detected without the feature `cpp` being used, now the build is aborted with a helpful error message rather than a linker error.
This is needed so that features used can be reliably be accessed.
The vendor code uses C++ code, thus, C++ support needs to be enabled in any case.
Arduino code requires C++ support
|
This is no longer waiting on AVR gaining C++ support :-) |
Contribution description
Internal modules are not allowed to use C++ code, as some platforms (might) only support C. This restriction should however not apply to external modules. If an application uses no C++ code but uses an external module using C++ code, linking is still done using
$(CC)instead of$(CXX). This PR$(CXX)for linking if the featurecppis used, rather than searching the application for C++ sourcescppbeing used, so that a more helpful error message is presented instead of a linking failureTesting procedure
The example given in issue #14466 should now error with a helpful error message instead of a linking issue. Add
FEATURES_REQUIRED += cppshould fix the linking issue, even if no C++ source code is present in the application.Issues/PRs references
Fixes: #14466