【gcc】gcc常见问题

gcc关闭warning

加 -w 关闭warings的显示

原始命令:
gcc -fsanitize=address -m32 main.c decrypt.c inflate.c -o main -lz
新命令:
gcc -fsanitize=address -m32 main.c decrypt.c inflate.c -o main -lz -w

gcc编译出32位程序

加 -m32
新命令:
gcc -m32 main.c decrypt.c inflate.c -o main -lz -w

gcc -fsanitize选项

参考https://blog.csdn.net/weixin_46222091/article/details/104375875

  • -fsanitize=address
    开启AddressSanitizer,一个快速的内存错误检查工具。内存访问的指令用于检测越界和使用后释放的bug。此外可以通过设置ASAN_OPTIONS环境变量来影响运行时的行为。当ASAN_OPTIONS环境变量设置为help=1时(如:ASAN_OPTIONS=help=1),所有可用的选项将在将在程序启用时显示。更多关于ASAN_OPTIONS环境变量有哪些预设值,参考wiki。ASAN_OPTIONS环境变量不能结合-fsanitize=thread使用。

【Ubuntu解决】fatal error: bits/libc-header-start.h: No such file or directory

fatal error: bits/libc-header-start.h: No such file or directory
#include <bits/libc-header-start.h>
compilation terminated.

sudo apt-get update
sudo apt install gcc-multilib

【Ubuntu解决】/usr/bin/ld: cannot find -lz

/usr/bin/ld: cannot find -lz

collect2: error: ld returned 1 exit status

Makefile:2: recipe for target ‘all’ failed

make: *** [all] Error 1

sudo apt-get install zlib1g-dev

【Ubuntu解决】 skipping incompatible //usr/lib/x86_64-linux-gnu/libz.so when searching for -lz 和/usr/bin/ld: cannot find -lz

/usr/bin/ld: skipping incompatible //usr/lib/x86_64-linux-gnu/libz.so
when searching for -lz

/usr/bin/ld: skipping incompatible //usr/lib/x86_64-linux-gnu/libz.a
when searching for -lz

/usr/bin/ld: cannot find -lz

collect2: error: ld returned 1 exit status

Makefile:2: recipe for target ‘all’ failed

make: *** [all] Error 1

sudo apt install gcc-multilib
sudo apt-get install lib32z1-dev

【Win解决】/mingw32/bin/ld.exe: cannot find -lz

d:/academic/mingw/program/bin/…/lib/gcc/mingw32/6.3.0/…/…/…/…/mingw32/bin/ld.exe: cannot find -lz

d:/academic/mingw/program/bin/…/lib/gcc/mingw32/6.3.0/…/…/…/…/mingw32/bin/ld.exe: cannot find -lasan

collect2.exe: error: ld returned 1 exit status

Makefile:2: recipe for target ‘all’ failed

make: *** [all] Error 1

使用其他版本的mingw:
https://sourceforge.net/projects/mingw-w64/files/
选择x86_64和sjlj
在这里插入图片描述

【Win解决】/bin/ld.exe: cannot find -lasan

命令:gcc -fsanitize=address -m32 main.c decrypt.c inflate.c -o main -lz -w

gcc -fsanitize=address -m32 main.c decrypt.c inflate.c -o main -lz -w
D:/Academic/MinGW/installer/x86_64-8.1.0-release-win32-sjlj-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lasan
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:2: all] Error 1

参考
https://stackoverflow.com/questions/55018627/cannot-find-lasan-using-address-sanitizer-in-qt-creator-in-windows-mingw
在这里插入图片描述

ASAN, TSAN and USAN are great technologies which are available in GCC.
Unfortunately they are not completely usable on Windows. A proper
review and tests are needed before anything.

因为使用了-fsanitize=address,而GCC does not support Asan on Windows,所以可以去掉-fsanitize=address

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值