我该如何解决]部分中类型的冲突"编译错误和最佳实践使用段属性用gcc [英] How do I resolve a "section type conflict" compile error and best practices for using section attribute with gcc

查看:242
本文介绍了我该如何解决]部分中类型的冲突"编译错误和最佳实践使用段属性用gcc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Android NDKr8并扩展GCC编译器跨多个平台,包括一些嵌入式的人分享了一些库code。这code使用段来放一堆元素融入一个连续的内存空间。编译正在生成一个错误:VARIABLE_NAME导致部分类型的冲突。

我们使用宏来声明段属性:

 #定义DB_SEGMENT __attribute__((__section__(DBSegment)))

以上VARIABLE_NAME声明如下:

  dbStruct const的变量名[] = DB_SEGMENT {
    {conststringvalue0,sizeof的(conststringvalue0)},
    ...更多像这样的
};

dbStruct是

  typedef结构dbStruct
{
    为const char * const的地址;
    常量UINT16 stringsize的;
} dbStruct;

conststringvalue0声明,像这样:

 为const char conststringvalue0 [] DB_SEGMENT =一些字符串值;

这同样code在X $ C $编译c。使用其默认的编译器,只在DB_SEGMENT宏的声明中的小的修改。这是一个比我习惯了,因此任何帮助将是AP preciated更深℃。谷歌有错误一些参考,但它的解决方法是不明确的。有没有设立一个特定的连续的内存部分一个更好的策略?

在回应评论,这里是唯一的区别fromthe正确X上code编译版本:

 的#define DB_SEGMENT __attribute__((节(DBSegment,DBSection)))


解决方案

我得到了同样的问题。而我的情况是我把code和变量在相同的部分。我把不同的部分变量之后,这个问题被驳回。希望这有助于。

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")))

解决方案

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.

这篇关于我该如何解决]部分中类型的冲突"编译错误和最佳实践使用段属性用gcc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆