Skip to content

my solution #14

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

Closed
wants to merge 1 commit into from
Closed

my solution #14

wants to merge 1 commit into from

Conversation

qiforan
Copy link

@qiforan qiforan commented Dec 14, 2021

stbiw 为 header-only library ,没有源文件,不需要实际编译,因此设置 为 interface library.
使用 target_include_directories 可以让源文件通过尖括号方式 include.

@qiforan
Copy link
Author

qiforan commented Dec 14, 2021

按照惯例,header 只声明不定义。此库却在 header 中定义了函数,所以要求多个 object 中只能有一个定义,不得不通过宏定义手动指定由哪个 object 进行定义。

Copy link
Collaborator

@archibate archibate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢你提交作业和认真的解释!不过由于最后改动了根目录的内容,我打 79 分!

所以要求多个 object 中只能有一个定义,不得不通过宏定义手动指定由哪个 object 进行定义。

所以其实可以单独弄一个空的 .cpp 文件,指定这个 object 来实现 stb 的函数。

#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <stb_image_write.h>

而这个文件可以放在 stbiw/impl.cpp 里,就可以供所有使用该函数的文件使用而不改动 main 的文件。

@qiforan qiforan closed this Dec 15, 2021
@hebangwen hebangwen mentioned this pull request Aug 19, 2022
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.

2 participants