Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
它用宏分离定义和实现的做法很妙。未定义
STB_IMAGE_WRITE_IMPLEMENTATION
时(如 mandel.cpp 和 rainbow.cpp),拿到的只有函数的定义。如果要生成用于编译时链接的库,写一个定义了这个宏、包含 stb_image_write.h 的 stb_image_write.cpp 文件就好,这样子这个 cpp 就能直接被编译成连接库了。(第一种做法)之所以 README.md 中“采分点提示”的做法不可行,是因为它第二个参数是
PUBLIC
,所以改成PRIVATE
就好,同时上面提到的 cpp 里的宏定义可以去掉,这样它只剩下包含指令了,而这个 cpp 的作用几乎与 stb_image_write.h 无异。(第二种做法)但它们还是有区别的,区别在于文件后缀不同。我尝试过有定义宏时直接编译,但 CMake 不能知道用什么语言编译,于是报错。
也许可以某种指令强行指定编译语言来解决这个问题,但这是我第一次用 CMake,不想弄太复杂。我想到的解决方法是把 stb_image_write.h 重命名为 stb_image_write.cpp,同时更改 mandel.cpp 和 rainbow.cpp 的
#include
内容。但这种做法需要改动 stbiw/ 之外的代码,所以这种做法没有前两种优。(第三种做法)