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

Hw01 frsama #100

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Hw01 frsama #100

wants to merge 2 commits into from

Conversation

frsama
Copy link

@frsama frsama commented Jul 14, 2022

不太会用git,不知道这样可以吗?

frsama added 2 commits July 14, 2022 22:47
创建.cpp文件
先宏定义STB_IMAGE_WRITE_IMPLEMENTATION,
再include头文件stb_image_write.h
这样做是因为stb_image_write将API和源码整合在了一个.h文件里,于是.h文件就同时包含了API声明和API定义。
这么做的原因可能是出于方便管理,一个.h文件总比一个.h文件加一个.cpp文件或.so文件更方便一些。

但是整合在一起后,我们又不希望每个include该头文件的其它文件每次都重新定义一遍API,所以就加了一个宏变量去限制它,
只有定义了该宏变量的文件,才会对API进行定义,其它文件只有API的声明部分。
通过此方法,最终实现了API声明和定义整合在一起,同时限制了重复定义的问题。
使用add_library是用来生成stbiw静态库的。
使用target_include_directories指定了stbiw库关联了当前目录(即/stbiw),且使用了public关键字,这将会传递给所有与stbiw库关联的文件,这些被关联的文件也会到/stbiw目录中去寻找可能需要的头文件。
@archibate
Copy link
Collaborator

archibate commented Jul 15, 2022 via email

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