gcc linking order

g++ -o 1 1.cpp -lpng16 # correct
g++ 1.cpp -lpng16 -o 1 # correct
g++ -lpng16 1.cpp -o 1 # wrong
g++ -o 1 -lpng16 1.cpp # wrong

GNU make's manual. 10.3 Variables Used by Implicit Rules

  • CC - Program for compiling C programs; default ‘cc’.
  • CFLAGS - Extra flags to give to the C compiler.
  • CXX - Program for compiling C++ programs; default ‘g++’.
  • CXXFLAGS - Extra flags to give to the C++ compiler.
  • CPP - Program for running the C preprocessor.
  • CPPFLAGS - Extra flags to give to the C preprocessor and programs that use it (the C and Fortran compilers).
  • LDFLAGS - Extra flags to give to compilers when they are supposed to invoke the linker, ‘ld’. [实测好像是cc,不是ld]
  • LDLIBS - Library flags or names given to compilers when they are supposed to invoke the linker.
  • 没有LD. 所有还是得会会$@, $<, $^之流。

myprog: myprog.o file1.o file2.o
    $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)

  • $< The name of the first prerequisite.
  • $^ The names of all the prerequisites.
  • $+ is like ‘$^’, but prerequisites listed more than once are duplicated in the order they were listed in the makefile. This is primarily useful for use in linking commands where it is meaningful to repeat library file names in a particular order.
posted @   Fun_with_Words  阅读(20)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
历史上的今天:
2022-01-08 A Child's History of England.105
2022-01-08 ambulance
2022-01-08 A Child's History of England.104
2022-01-08 蜂鸟E203开源RISC-V开发板
2022-01-08 ambassador
2022-01-08 amateur
2022-01-08 Basic Computer Games









 和4张牌。

点击右上角即可分享
微信分享提示