zoukankan      html  css  js  c++  java
  • BREW AMR 编译错误 L6248E

           主要是由于使用全局变量造成的, 如果要使用全局数组,如 int a[ ] = {1,2,3 };

    请在前面加上const , 如下const static int a[ ] = {1,2,3 }; 请勿使用全局指针.

    This linker error can occur when trying to build "Position Independent" code. Consider a small example like:

    #include <stdio.h>
    char *str = "test";
    int main(void)
    {
    printf ("%s",str);
    }

    when compiled and linked with:

    armcc -c -apcs /ropi pi.c
    armlink -ropi pi.o

    the linker will report a message of the form:

    Error: L6248E: pi.o(.data) in ABSOLUTE region 'ER_RW' cannot have address/offset type
    relocation to .constdata in PI region 'ER_RO'.

    For the code above, the compiler generates a global pointer "str" to the char string "test". The global pointer "str" will need to be initialized to the address of the char string "test" in the .constdata section. However, absolute addresses cannot be used in a PI system, so the link step fails, because of the ABS32 relocations to (position independent) .constdata.

    To resolve this, you must re-write the code to avoid the explicit pointer. Two possible ways are shown below:

    1) Use a global array instead of a global pointer:

    #include <stdio.h>
    const char str[] = "test";
    int main(void)
    {
    printf ("%s",str);
    }

    2) Use a local pointer instead of a global pointer:

    #include <stdio.h>
    int main(void)
    {
    char *str = "test";
    printf ("%s",str);
    }

    Please note that if you are using a list with multiple elements, such as:

    char * list[] = {"zero", "one", "two"};

    You will get a separate link error for each element in the array. In this case, the recommended solution is:

    char list[3][5] = {"zero", "one", "two"};

    with the print instruction being (for example):

    printf("%s", list[1]);

    Note that you will need to declare a two dimensional array for the list, with the first dimension as the number of elements in the array, and the second dimension as the maximum size for an element in the array.

     
  • 相关阅读:
    【老孙随笔】关羽和吕蒙——天才的失败
    【老孙随笔】项目经理要向唐骏学习
    WebService里奇怪的参数值偏移现象?
    [原创]让您的服务器不再有被挂马的烦恼文件安全卫士
    C#里也可以用上Eval函数了:)
    使用HTTP_X_FORWARDED_FOR获取客户端IP的严重后果
    支持算术运算、逻辑运算、位运算的表达式求值
    在Lambda表达式中进行递归调用
    认识Lambda表达式
    将你的QQ唠叨或QQ签名数据加入到博客上:)
  • 原文地址:https://www.cnblogs.com/secbook/p/2655510.html
Copyright © 2011-2022 走看看