Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xiao-ming-hub 完成了作孽! #109

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

xiao-ming-hub
Copy link

  它用宏分离定义和实现的做法很妙。未定义 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 Error: Cannot determine link language for target "stbiw".
CMake Error: CMake can not determine linker language for target: stbiw

也许可以某种指令强行指定编译语言来解决这个问题,但这是我第一次用 CMake,不想弄太复杂。我想到的解决方法是把 stb_image_write.h 重命名为 stb_image_write.cpp,同时更改 mandel.cpp 和 rainbow.cpp 的#include 内容。但这种做法需要改动 stbiw/ 之外的代码,所以这种做法没有前两种优。(第三种做法)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant