GCC -M,-MM,-MMD,-MF,-MT

本文介绍了GCC编译器中与-M相关的参数,包括-M用于生成文件依赖信息,-MM忽略#include依赖,-MMD和-MD将依赖写入.d文件,-MF指定存放依赖信息的文件,-MT用于指定目标文件名。通常情况下,作者倾向于使用-MMD。结合-D参数,可以自动保存关联信息并保持目标文件的可执行属性。

GCC的命令参数有很多,下面主要介绍几个M相关的:
###-M
生成文件关联的信息。包含目标文件所依赖的所有源代码,下面是测试log:

jack@jxes-VirtualBox:~/samba_share/tmp$ vim test.c
jack@jxes-VirtualBox:~/samba_share/tmp$ gcc -M test.c
test.o: test.c /usr/include/stdc-predef.h /usr/include/stdio.h \
 /usr/include/features.h /usr/include/i386-linux-gnu/sys/cdefs.h \
 /usr/include/i386-linux-gnu/bits/wordsize.h \
 /usr/include/i386-linux-gnu/gnu/stubs.h \
 /usr/include/i386-linux-gnu/gnu/stubs-32.h \
 /usr/lib/gcc/i686-linux-gnu/5/include/stddef.h \
 /usr/include/i386-linux-gnu/bits/types.h \
 /usr/include/i386-linux-gnu/bits/typesizes.h /usr/include/libio.h \
 /usr/include/_G_config.h /usr/include/wchar.h \
 /usr/lib/gcc/i686-linux-gnu/5/include/stdarg.h \
 /usr/include/i386-linux-gnu/bits/stdio_lim.h \
 /usr/include/i386-linux-gnu/bits/sys_errlist.h

###-MM
和上面的那个一样,但是它将忽略由#include造成的依赖关系。

jack@jxes-VirtualBox:~/samba_share/tmp$ gcc -MM test.c
test.o: test.c

###-MMD
和-MM相同,但是输出将导入到.d的文件里面:

jack@jxes-VirtualBox:~/samba_share/tmp$ gcc -MMD test.c -o test
jack@jxes-VirtualBox:~/samba_share/tmp$ ll
total 24
drwxrwxr-x 2 jack jack 4096 7月  17 10:42 ./
drwxr-xr-x 6 jack jack 4096 7月  17 10:38 ../
-rwxrwxr-x 1 jack jack 7344 7月  17 10:42 test*
-rw-rw-r-- 1 jack jack   87 7月  17 10:39 test.c
-rw-rw-r-- 1 jack jack   13 7月  17 10:42 test.d //test.d为导出文件
jack@jxes-VirtualBox:~/samba_share/t
make[2]: Entering directory ‘/home/bba/work/BBA1_5/MBB_Platform/apps/public/openssl-1.1.1f’ /usr/bin/perl apps/progs.pl apps/openssl > apps/progs.h mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/asn1pars.d.tmp -MT apps/asn1pars.o -c -o apps/asn1pars.o apps/asn1pars.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/ca.d.tmp -MT apps/ca.o -c -o apps/ca.o apps/ca.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/ciphers.d.tmp -MT apps/ciphers.o -c -o apps/ciphers.o apps/ciphers.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/cms.d.tmp -MT apps/cms.o -c -o apps/cms.o apps/cms.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/crl.d.tmp -MT apps/crl.o -c -o apps/crl.o apps/crl.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/crl2p7.d.tmp -MT apps/crl2p7.o -c -o apps/crl2p7.o apps/crl2p7.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/dgst.d.tmp -MT apps/dgst.o -c -o apps/dgst.o apps/dgst.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/dhparam.d.tmp -MT apps/dhparam.o -c -o apps/dhparam.o apps/dhparam.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/dsa.d.tmp -MT apps/dsa.o -c -o apps/dsa.o apps/dsa.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/dsaparam.d.tmp -MT apps/dsaparam.o -c -o apps/dsaparam.o apps/dsaparam.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/ec.d.tmp -MT apps/ec.o -c -o apps/ec.o apps/ec.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/ecparam.d.tmp -MT apps/ecparam.o -c -o apps/ecparam.o apps/ecparam.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/enc.d.tmp -MT apps/enc.o -c -o apps/enc.o apps/enc.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/engine.d.tmp -MT apps/engine.o -c -o apps/engine.o apps/engine.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/errstr.d.tmp -MT apps/errstr.o -c -o apps/errstr.o apps/errstr.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/gendsa.d.tmp -MT apps/gendsa.o -c -o apps/gendsa.o apps/gendsa.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/genpkey.d.tmp -MT apps/genpkey.o -c -o apps/genpkey.o apps/genpkey.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/genrsa.d.tmp -MT apps/genrsa.o -c -o apps/genrsa.o apps/genrsa.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/nseq.d.tmp -MT apps/nseq.o -c -o apps/nseq.o apps/nseq.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/ocsp.d.tmp -MT apps/ocsp.o -c -o apps/ocsp.o apps/ocsp.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/openssl.d.tmp -MT apps/openssl.o -c -o apps/openssl.o apps/openssl.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/passwd.d.tmp -MT apps/passwd.o -c -o apps/passwd.o apps/passwd.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/pkcs12.d.tmp -MT apps/pkcs12.o -c -o apps/pkcs12.o apps/pkcs12.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/pkcs7.d.tmp -MT apps/pkcs7.o -c -o apps/pkcs7.o apps/pkcs7.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/pkcs8.d.tmp -MT apps/pkcs8.o -c -o apps/pkcs8.o apps/pkcs8.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/pkey.d.tmp -MT apps/pkey.o -c -o apps/pkey.o apps/pkey.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/pkeyparam.d.tmp -MT apps/pkeyparam.o -c -o apps/pkeyparam.o apps/pkeyparam.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/pkeyutl.d.tmp -MT apps/pkeyutl.o -c -o apps/pkeyutl.o apps/pkeyutl.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/prime.d.tmp -MT apps/prime.o -c -o apps/prime.o apps/prime.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/rand.d.tmp -MT apps/rand.o -c -o apps/rand.o apps/rand.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/rehash.d.tmp -MT apps/rehash.o -c -o apps/rehash.o apps/rehash.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/req.d.tmp -MT apps/req.o -c -o apps/req.o apps/req.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/rsa.d.tmp -MT apps/rsa.o -c -o apps/rsa.o apps/rsa.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/rsautl.d.tmp -MT apps/rsautl.o -c -o apps/rsautl.o apps/rsautl.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/s_client.d.tmp -MT apps/s_client.o -c -o apps/s_client.o apps/s_client.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/s_server.d.tmp -MT apps/s_server.o -c -o apps/s_server.o apps/s_server.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/s_time.d.tmp -MT apps/s_time.o -c -o apps/s_time.o apps/s_time.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/sess_id.d.tmp -MT apps/sess_id.o -c -o apps/sess_id.o apps/sess_id.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/smime.d.tmp -MT apps/smime.o -c -o apps/smime.o apps/smime.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/speed.d.tmp -MT apps/speed.o -c -o apps/speed.o apps/speed.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/spkac.d.tmp -MT apps/spkac.o -c -o apps/spkac.o apps/spkac.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/srp.d.tmp -MT apps/srp.o -c -o apps/srp.o apps/srp.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/storeutl.d.tmp -MT apps/storeutl.o -c -o apps/storeutl.o apps/storeutl.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/ts.d.tmp -MT apps/ts.o -c -o apps/ts.o apps/ts.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/verify.d.tmp -MT apps/verify.o -c -o apps/verify.o apps/verify.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/version.d.tmp -MT apps/version.o -c -o apps/version.o apps/version.c mipsel-linux-gcc -I. -Iinclude -Iapps -pthread -Wall -Os -DGNU -DNDEBUG -MMD -MF apps/x509.d.tmp -MT apps/x509.o -c -o apps/x509.o apps/x509.c rm -f apps/openssl ${LDCMD:-mipsel-linux-gcc} -pthread -Wall -Os -DGNU -L. -o apps/openssl apps/asn1pars.o apps/ca.o apps/ciphers.o apps/cms.o apps/crl.o apps/crl2p7.o apps/dgst.o apps/dhparam.o apps/dsa.o apps/dsaparam.o apps/ec.o apps/ecparam.o apps/enc.o apps/engine.o apps/errstr.o apps/gendsa.o apps/genpkey.o apps/genrsa.o apps/nseq.o apps/ocsp.o apps/openssl.o apps/passwd.o apps/pkcs12.o apps/pkcs7.o apps/pkcs8.o apps/pkey.o apps/pkeyparam.o apps/pkeyutl.o apps/prime.o apps/rand.o apps/rehash.o apps/req.o apps/rsa.o apps/rsautl.o apps/s_client.o apps/s_server.o apps/s_time.o apps/sess_id.o apps/smime.o apps/speed.o apps/spkac.o apps/srp.o apps/storeutl.o apps/ts.o apps/verify.o apps/version.o apps/x509.o apps/libapps.a -lssl -lcrypto -ldl -pthread ./libcrypto.so: warning: gethostbyname is obsolescent, use getnameinfo() instead. ./libcrypto.so: undefined reference to getcontext' ./libcrypto.so: undefined reference to setcontext’ ./libcrypto.so: undefined reference to `makecontext’ collect2: ld returned 1 exit status Makefile:6187: recipe for target ‘apps/openssl’ failed make[2]: *** [apps/openssl] Error 1 make[2]: Leaving directory ‘/home/bba/work/BBA1_5/MBB_Platform/apps/public/openssl-1.1.1f’ Makefile:183: recipe for target ‘build_programs’ failed make[1]: *** [build_programs] Error 2 make[1]: Leaving directory ‘/home/bba/work/BBA1_5/MBB_Platform/apps/public/openssl-1.1.1f’ make/apps/pubapps/openssl.mk:3: recipe for target ‘openssl’ failed make: *** [openssl] Error 2
09-23
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

JXES智能生态系统

如文章对你有用,请作者喝个咖啡

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

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

打赏作者

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

抵扣说明:

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

余额充值