How do I resolve a “section type conflict” compile error and best practices for using section attribute with gcc

北慕城南 提交于 2019-12-10 18:04:10

问题


I am using Android NDKr8 and by extension gcc to compile some library code that is shared across multiple platforms including some embedded ones. This code uses segments to put a bunch of elements into a contiguous memory space. The compile is generating a "error: variable_name causes a section type conflict".

We use a macro to declare the segment attribute:

# define DB_SEGMENT __attribute__ ((__section__ ("DBSegment")))

The above variable_name is declared as follows:

dbStruct const variable_name[] DB_SEGMENT = {
    {conststringvalue0, sizeof(conststringvalue0)},
    …more like this
};

dbStruct is

typedef struct dbStruct
{
    const char * const  address;
    const UINT16        stringSize;
} dbStruct;

conststringvalue0 is declared like so:

const char conststringvalue0[] DB_SEGMENT = "some string value";

This same code compiles in Xcode using its default compiler with only a small modification in the declaration of the DB_SEGMENT macro. This is deeper C than I am used to so any help would be appreciated. Google has some references to the error but the fix for it is not clear. Is there a better strategy for setting up a specific contiguous memory section?

In response to a comment, here is the only difference fromthe correctly compiling version on XCode:

#define DB_SEGMENT __attribute__ ((section ("DBSegment,DBSection")))

回答1:


I got the same problem. And my situation is I put the code and variables in the same section. After I put the variable in a different section, the problem dismissed. Hope this helps.




回答2:


"# define DB_SEGMENT attribute ((section ("DBSegment")))"

I am seeing a space between # and define which is not correct.

Remove that space and try compiling.



来源:https://stackoverflow.com/questions/10436759/how-do-i-resolve-a-section-type-conflict-compile-error-and-best-practices-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!