当前位置:   article > 正文

鸿蒙程序编译_鸿蒙target

鸿蒙target

文章目录

示例

源码

  • 源码 add.c
    int add(int a, int b)
    {
       return a+b;
    }
    
    • 1
    • 2
    • 3
    • 4
  • 源码 main.c
    #include <stdio.h>
    
    extern int add(int a, int b);
    int main(int argc, char *argv[])
    {
          printf("test %d", add(1, 2));
          return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

编译

  • 编译成 *.o 文件
    clang++.exe --target=aarch64-linux-ohos \
      --gcc-toolchain=D:/Huawei/SDK/native/2.0.1.93/llvm \
      --sysroot=D:/Huawei/SDK/native/2.0.1.93/sysroot  \
      -Dhello_EXPORTS  -g -fdata-sections -ffunction-sections \
      -funwind-tables -fstack-protector-strong -no-canonical-prefixes \
      -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security  \
       -O0 -fno-limit-debug-info  -fPIC   -o add.o -c add.c
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
  • 编译成动态库
     clang.exe --target=aarch64-linux-ohos \
         --gcc-toolchain=D:/Huawei/SDK/native/2.0.1.93/llvm \
         --sysroot=D:/Huawei/SDK/native/2.0.1.93/sysroot \
         add.o -shared -fPIC \
         --rtlib=compiler-rt -fuse-ld=lld -Wl,--build-id=sha1 \
         -Wl,--warn-shared-textrel -Wl,--fatal-warnings -lunwind \
         -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack \
         -o libtest.so
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
  • 编译程序
    clang --target=aarch64-linux-ohos \
         --gcc-toolchain=D:/Huawei/SDK/native/2.0.1.93/llvm \
         --sysroot=D:/Huawei/SDK/native/2.0.1.93/sysroot \
         --rtlib=compiler-rt -fuse-ld=lld -Wl,--build-id=sha1 \
         -Wl,--warn-shared-textrel \
         -Wl,--fatal-warnings -lunwind -Wl,--no-undefined \
         -Qunused-arguments -Wl,-z,noexecstack \
         -L./ -ltest main.c -o main
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/252051
推荐阅读
相关标签
  

闽ICP备14008679号