hw01 icon indicating copy to clipboard operation
hw01 copied to clipboard

小彭老师好, hw01

Open ZhaoChongyang96 opened this issue 3 years ago • 0 comments

作业思路

  1. 要把 stb_image_write.h 这个头文件 编译成库
  2. 因此需要一个 stbiw.cpp 文件作为一个编译单元
  3. stbiw.cpp 中要有函数的实现,按照stb_image_write.h使用说明,要先定义宏再include这个头文件
  4. stbiw 对应的 CMakeList.txt 中先把 stbiw.cpp 编译成库(add_library), 然后把头文件路径传染给link这个库的其他目标文件(target_include_directories)

stbi 头文件库这样设计的原因

这个头文件即有函数的声明又有实现,这些声明和实现分别用宏隔离开。 直接include的话,是函数声明 先定义 STB_IMAGE_WRITE_IMPLEMENTATION 宏再include, 是函数实现 优点是使用起来方便,但是每次使用都要重新编译

ZhaoChongyang96 avatar Mar 23 '22 09:03 ZhaoChongyang96