hw01 icon indicating copy to clipboard operation
hw01 copied to clipboard

高性能并行编程与优化 - 第01讲回家作业

Results 99 hw01 issues
Sort by recently updated
recently updated
newest added

Step 1. create the stb_image_write.cpp Step 2. modify the CmakeList.txt in stbi Step 3. build and run !

try fix hw01 first time

遇到重定义问题,知道是头文件重复引入的问题。应该只引入一次即可,但是cmake没有这个编译参数,又不能更改main函数,只能在子模块里改,cpp文件内放入一个宏和include头文件,main函数调用不同头文件,头文件有pragma once,所以只会引入一次lib库文件。mandel和rainbow合并成一个文件就可以避免出现这种情况, ![Tabby_DyRrT2uytn](https://user-images.githubusercontent.com/38826071/166469414-d4f516e0-e244-430c-afce-a0dbed59a4f2.png) 开始困扰我的地方在于我一直以为是只能改cmakelists.txt,但是cmake里面没有课件上写的target_add_definitions函数,最后也是看答案了(😔,结果发现就差一步,太难受了。

感谢彭老师提供的平台,学习了cmake和git~

Add this code below in .gitignore may be helpful for MacOS & VSCode User for pulling their requests, and make the repo clearer. ```git # vscode .vscode # mac .DS_Store...

Complete hw01,Thx Peng!

## 作业思路 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,...

* Q:为什么设计成需要在仅一个文件中定义宏并include对应头文件的形式哦 * A: * 当定义了对应的宏后,.h文件中将包含函数声明和对应的实现,否则将仅包含声明部分。 * 因此,在零个文件中定义将导致缺少函数的实现,而在一个以上的文件中定义将存在重复的函数实现。 * 官方仓库的[README](https://github.com/nothings/stb#how-do-i-use-these-libraries)中指出,因当在一个不常编辑的 c/cpp 文件中展开实现部分,应该是为了避免文件修改后重新编译 stb 库部分消耗更多时间。