-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[cmsis_gcc.h] nested extern declaration #617
Comments
Uses the latest version of these files. |
Hi @salkinium, thanks for pointing this out. These warnings are caused by the reworked C startup code (compiler agnostic). I'll check what's behind and how we can change it. As long as you are using the former startup routines (compiler specific) you are fine with defining Cheers, |
Yeah, redefining |
Hi @salkinium, I checked with our GCC experts and the code should just be fine. Do you have any concerns if we simply suppress that warning in that location? I.e. by adding Cheers, |
No, suppressing the warning locally is fine for me. |
May I ask you for what reason you enabled that warning? There seems nothing wrong with using this kind of extern declaration. Hence I am now struggling between adding the pragmas to suppress the warning locally versus keeping the code clean. As I don't see any problems with that code I tend to conclude: That warning should not be used. |
cc @dergraaf Why was Is there a complete list of compile flags to use to compile your code? |
I've solved it this way. I think this is best since Thanks for you help! |
Hi @JonatanAntoni , I got the similar error while including the "arm_math.h" in *.cpp file, the gcc error is:
The flag By the way, when I changed the cmsis_gcc.h, moving extern void _start(void) __NO_RETURN;
typedef struct {
uint32_t const* src;
uint32_t* dest;
uint32_t wlen;
} __copy_table_t;
typedef struct {
uint32_t* dest;
uint32_t wlen;
} __zero_table_t;
extern const __copy_table_t __copy_table_start__;
extern const __copy_table_t __copy_table_end__;
extern const __zero_table_t __zero_table_start__;
extern const __zero_table_t __zero_table_end__; out of the function |
Hi @zejiangfish, I guess this happens because the symbols in question (e.g. We could of course move the type defines and extern declarations into global scope. I added them to local scope in order not to clutter the global scope. Cheers, |
Hi @JonatanAntoni , Thank you very much for analyze, is there plan for this error? Or some suggestions? thanks. |
Facing the same problem here, moving the type defines out of the function clears the compiler error.
|
Hi @noxuz, Thanks for getting in touch. I had clarified with our Compiler experts back in June last year that these nested declarations should just be fine. Why is this causing errors for you? Cheers, |
@JonatanAntoni Thank you for the follow-up. I was trying to compile a project using directly the CMSIS library from this repo, although I was not using that particular function, the compiler did popped the same error from the top of this post. I'm currently working with NXP mcu's, and I ended up using the CMSIS-like header that its provided from within the IDE for it. You can take a look at it in this Link. |
See ARM-software#617 for previous discussions.
I got the same error as @zejiangfish, and I managed to get a patch with only the struct declarations moved: EMCLab-Sinica@f37a114. extern symbol declarations are kept local. That should reduce the risk of symbol conflicts. |
which version of GCC are you using? As stated above, the nested declarations should be just fine from C standard point of view. Cheers, |
I'm using GCC 10.1. I guess GCC does not like it as I'm compiling C++ code. I remember CMSIS worked fine with one of my another project with only C code. |
Apologies - it turns out the problem is from dependency management of our projects. The "declared using local type" error appears only with CMSIS 5.6.0. CMSIS 5.7.0 works fine with C++ source files (our code base uses C++ 11, if that is relevant). As a side note, the key change in CMSIS between 5.6.0 and 5.7.0 appears to be 3b2a0ee#diff-b9d8110b101a50848c56c0c9c90fc936. As |
Hello, today I meet this error too. I use Segger Embedded Studio with GCC compiler (standarts: c++17, c17). But patching package files supplied by the IDE developer is bad form. Therefore, I cover all the including of this file with guards. |
Hi @CheMax-Tag, The Do you have specific requirements why you'd want to include internal stuff of CMSIS directly from user application? Cheers, |
Hi @JonatanAntoni , I include this file to access assembly wrappers, such as __SEV(); __WFE(); __BKPT() and other. Since the file in which I make the connection is used for different MCUs, I wanted to make a universal solution. Therefore, I connected a "universal" file. For the test, I tried to include "core_cm4.h", but got another error: Regards, |
I had a similar experience. Anyway, it is good practice for each header file to include the |
I agree, if done properly the Thanks, |
@JonatanAntoni , Ok. I try do it. |
In my case I am including But the project I am using was configured to Clang 12 and I was getting following error:
Should Clang use a different header? Interestingly this ,global define fixes it even for Clang. |
Hi @dzid26, I can only speculate because using vanilla Clang is currently not in scope. The "problem" might be the declaration of extern variables with non-external types. Strictly speaking no extern module would ever be able to define a variable with that function-local type. In this specific case the extern variables are linker defined trough the used linker script. The type's memory layout is respected without actually using the type delaration from the c module, of course. The compiler cannot know this. By moving the type declaration to global scope the warning disappears. A global type could be used from an external module to define the variable. If it is actually used doesn't matter, here. The reason for having the type declaration local to the function is to prevent cluttering global scope. In fact, this type should not be required/used in any other place. Can you try to modify the code as proposed by the error message, please? I.e.
so the code should become something like typedef struct copy_table_t {
uint32_t const* src;
uint32_t* dest;
uint32_t wlen;
} __copy_table_t; Does this solve the issue for you? If yes, would you mind to raise this change as a pull-request?` Thanks, |
In .cpp file, if i include like this: extern "C" {
#include "arm_math.h"
} them errors disappear. |
Thanks for your suggestions. Finally it worked.
|
Hi, I encounter same issue. The main reason If I include cmsis_compiler.h directly it's to access cortex_m macros/types/inlines for sources common to different cores (m0, m0+, m3, m4...). But I also think that encapsulating #include files with extern "C" statement like in core_cm?.h files is definitely not a good idea and may have unexpected effects for C++ development. We are at the age where Linux kernel is migrating to C++ ! Olivier |
When compiling with
-Wnested-externs
, these warnings appear:I'm currently working around this by
#define __PROGRAM_START 1
, but that's pretty brute force.The text was updated successfully, but these errors were encountered: