ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

make 随笔

2022-02-27 21:02:40  阅读:201  来源: 互联网

标签:gcc redhat -- make param test 随笔


# --with--cc-opt flag导致./configure时找不到对应库文件?
checking for --with-ld-opt="-Wl,-z,relro  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E" ... found


checking for --with-ld-opt="-Wl,-z,relro  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E" ... not found


'--with-cc-opt=-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong 
-grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables
 -fstack-clash-protection -fcf-protection 
 
 
 '--with-cc-opt=-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong 
 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables 
 -fstack-clash-protection -fcf-protection 
 -floop-unroll-and-jam  -ftree-loop-distribution  --param early-inlining-insns=160 --param inline-heuristics-hint-percent=800 --param inline-min-speedup=50
 --param inline-unit-growth=256  --param max-average-unrolled-insns=500 --param max-completely-peel-times=32 --param max-completely-peeled-insns=800
 --param max-inline-insns-auto=128 --param max-inline-insns-small=128 --param max-unroll-times=16 --param max-unrolled-insns=16'

gcc

  1. 预处理
    gcc -E x.cpp >test.ii将include代码导进来
  2. 编译
    gcc -S test.ii 生成汇编代码
  3. 汇编
    gcc -c test.s 生成.o (二进制文件)
  4. 链接
    g++ test.o -o test
  5. 运行 (运行时才会加载动态链接库)
    ./test

makefile

# first_make
# $^ 依赖 不重复
# $@ 目标
# @ 不显示命令执行过程 -失败不停止
# LD_LIBRARY_PATH=../xthread 运行的时候去哪里找链接库
TARGET=first_make
LIBS=-lpthread
#有的.o文件与要编译的文件不同目录,所以定义CXXFLAGS
CXXFLAGS=-I../test_gcc  
OBJS=first_make.cpp xdate.cpp
$(TARGET):$(OBJS)
	@#-@rm test
	@echo "begin build $(TARGET)"
	$(CXX) $^ -o $@ $(LIBS)
	@echo "a$(TARGET) build success"

clean:
	$(RM) $(OBJS) $(TARGET)
#尾部标对应的清理
.PHONY: clean *clean

-----------------
make clean
make

begin build first_make
gcc first_make.cpp xdate.cpp -o first_mak -lpthread
first_make build success

ldd xx.so

静态库 ar -crv libmylib.a mylib.o

  • 跟普通的链接一样,-o 会把库的代码复制过来
  • 动态库链接时只会把动态库当中函数地址复制过来,具体的二进制代码不会复制过来,所以链接动态库,整个文件大小会小一点

动态库

  • g++ -shared -fPIC mylib.cpp libmylib.so
  • g+= test.cpp -lmylib -L/root/cpp
  • LD_LIBRARY_PATH=./
  • export LD_LIBRARY_PATH
  • ./testjin't

标签:gcc,redhat,--,make,param,test,随笔
来源: https://www.cnblogs.com/hhds/p/15943350.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有