In C, is it possible to change exported function name to different one?

前端 未结 3 1278
故里飘歌
故里飘歌 2020-12-17 16:34

all.

I want to link a library which calls malloc() function. However, my target environment is different one and malloc() is supplied as in

3条回答
  •  臣服心动
    2020-12-17 17:07

    I think the alias attribute might solve your problem:

    alias ("target")
        The alias attribute causes the declaration to be emitted as an alias for another symbol, which must be specified. For instance,
    
                  void __f () { /* Do something. */; }
                  void f () __attribute__ ((weak, alias ("__f")));
    
    
        defines `f' to be a weak alias for `__f'. In C++, the mangled name for the target must be used. It is an error if `__f' is not defined in the same translation unit.
    
        Not all target machines support this attribute.
    

    http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html

提交回复
热议问题