Skip to content

my solution - #14

Closed
qiforan wants to merge 1 commit into
parallel101:mainfrom
qiforan:main
Closed

qiforan wants to merge 1 commit into
parallel101:mainfrom
qiforan:main

Conversation

@qiforan

@qiforan qiforan commented Dec 14, 2021

Copy link
Copy Markdown

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

@qiforan

qiforan commented Dec 14, 2021

Copy link
Copy Markdown
Author

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

@archibate archibate left a comment

Copy link
Copy Markdown
Collaborator

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