cc/gcc 不同平台的差异

本文介绍不同操作系统下的默认编译器,并说明如何在32位系统上编译64位程序。此外,还强调了HP-UX系统中使errno线程安全所需的编译参数。最后,给出了在AIX平台上生成64位静态库的具体命令。

1. 默认编译器

    linux: gcc

    sun:   gcc

    aix:    cc

    hp:     cc


2. 32位系统编译64位程序,需要加编译参数

linux: -m64

sun:   -m64

aix:     -q64

hp:      +DD64


3. HP-UX “-D_REENTRANT” 参数

  linux下errno默认是线程安全的,多个线程之间,errno互不干扰

  HP-UX则不行,编译时必须加上"-D_REENTRANT"才会线程安全

  当然,这个参数不仅会使errno线程安全,也会自动替换其它非线程安全函数

  总之加上就对了


4. 生成静态库

    aix 平台使用 ar 命令生成64位静态库时要加参数: "-X64" ,如

     ar -X64 q hello.a hello.o

Reading state information... 1 package can be upgraded. Run 'apt list --upgradable' to see it. + apt install -y wget WARNING: apt does not have a stable CLI interface. Use with caution in scripts. Reading package lists... Building dependency tree... Reading state information... The following NEW packages will be installed: wget 0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded. Need to get 316 kB of archives. After this operation, 954 kB of additional disk space will be used. Get:1 http://rdsource.tp-link.com/ubuntu bionic-updates/main amd64 wget amd64 1.19.4-1ubuntu2.2 [316 kB] debconf: delaying package configuration, since apt-utils is not installed Fetched 316 kB in 1s (493 kB/s) Selecting previously unselected package wget. (Reading database ... 39204 files and directories currently installed.) Preparing to unpack .../wget_1.19.4-1ubuntu2.2_amd64.deb ... Unpacking wget (1.19.4-1ubuntu2.2) ... Setting up wget (1.19.4-1ubuntu2.2) ... + cd /tmp + wget -q http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-4.9/gcc-4.9-base_4.9.4-2ubuntu1_amd64.deb The command '/bin/sh -c set -eux; apt update && apt install -y wget; cd /tmp; wget -q http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-4.9/gcc-4.9-base_4.9.4-2ubuntu1_amd64.deb; wget -q http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-4.9/gcc-4.9_4.9.4-2ubuntu1_amd64.deb; wget -q http://archive.ubuntu.com/ubuntu/pool/main/g/g++-4.9/g++-4.9_4.9.4-2ubuntu1_amd64.deb; wget -q http://archive.ubuntu.com/ubuntu/pool/main/g/libgcc-4.9-dev/libgcc-4.9-dev_4.9.4-2ubuntu1_amd64.deb; wget -q http://archive.ubuntu.com/ubuntu/pool/main/g/libstdc++-4.9-dev/libstdc++-4.9-dev_4.9.4-2ubuntu1_amd64.deb; dpkg -i *.deb || true; apt install -f -y; update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20; update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 20; update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-4.9 20; ln -sf /usr/bin/gcc-nm-4.9 /usr/bin/gcc-nm; ln -sf /usr/bin/gcc-ar-4.9 /usr/bin/gcc-ar; ln -sf /usr/bin/gcc-ranlib-4.9 /usr/bin/gcc-ranlib; rm -f /tmp/*.deb; rm -rf /var/lib/apt/lists/*' returned a non-zero code: 8
最新发布
12-09
book@100ask:~/openwrt/linux-intelligent-gateway/gateway-240228$ make arm-poky-linux-gnueabi-gcc -Wall -Wextra -I/home/book/openwrt/linux-intelligent-gateway/gateway-240228 --sysroot=/home/book/openwrt/linux-intelligent-gateway/gateway-240228/sysroot -o gateway app/app_router.o app/app_buffer.o app/app_bluetooth.o app/app_runner.o app/app_device.o app/app_mqtt.o app/app_message.o app/app_task.o app/app_serial.o daemon/daemon_process.o daemon/daemon_runner.o thirdparty/log.c/log.o thirdparty/cJSON/cJSON.o main.o -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -lpaho-mqtt3c -lcrypto -lpthread -lrt /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: error: gateway uses VFP register arguments, app/app_router.o does not /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: failed to merge target specific data of file app/app_router.o /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: error: gateway uses VFP register arguments, app/app_buffer.o does not /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: failed to merge target specific data of file app/app_buffer.o /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: error: gateway uses VFP register arguments, app/app_bluetooth.o does not /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: failed to merge target specific data of file app/app_bluetooth.o /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: error: gateway uses VFP register arguments, app/app_runner.o does not /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: failed to merge target specific data of file app/app_runner.o /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: error: gateway uses VFP register arguments, app/app_device.o does not /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: failed to merge target specific data of file app/app_device.o /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: error: gateway uses VFP register arguments, app/app_mqtt.o does not /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: failed to merge target specific data of file app/app_mqtt.o /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: error: gateway uses VFP register arguments, app/app_message.o does not /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: failed to merge target specific data of file app/app_message.o /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: error: gateway uses VFP register arguments, app/app_task.o does not /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: failed to merge target specific data of file app/app_task.o /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: error: gateway uses VFP register arguments, app/app_serial.o does not /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: failed to merge target specific data of file app/app_serial.o /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: error: gateway uses VFP register arguments, daemon/daemon_process.o does not /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: failed to merge target specific data of file daemon/daemon_process.o /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: error: gateway uses VFP register arguments, daemon/daemon_runner.o does not /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: failed to merge target specific data of file daemon/daemon_runner.o /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: error: gateway uses VFP register arguments, thirdparty/log.c/log.o does not /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: failed to merge target specific data of file thirdparty/log.c/log.o /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: error: gateway uses VFP register arguments, thirdparty/cJSON/cJSON.o does not /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: failed to merge target specific data of file thirdparty/cJSON/cJSON.o /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: error: gateway uses VFP register arguments, main.o does not /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: failed to merge target specific data of file main.o collect2: error: ld returned 1 exit status Makefile:30: recipe for target 'gateway' failed make: *** [gateway] Error 1 这个报错分析一下
10-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

duanbeibei

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值