Skip to content

Finish Homework 1 #103

New issue

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

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

Already on GitHub? # to your account

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

Finish Homework 1 #103

wants to merge 3 commits into from

Conversation

hebangwen
Copy link

感谢小彭老师的课程,这是我完成的作业1。

我发现了下面这几个问题:

  • 为什么使用add_definitions 通过了?因为add_definitions 给当前目录下和所有添加的子目录都添加一个DEFINITION ,而不会给包含它的上级目录添加,相当于是默认的PRIVATE
  • 为什使用target_compile_definitions(stbiw PUBLIC -DSTB_IMAGE_WRITE_IMPLEMENTATION=1) 不通过?因为mandel.hrainbow.h 都include了stbiw库,所以如果在CMakeLists.txt中设置宏,会导致这个宏被定义了两次,发生冲突。如果在某个源文件中定义这个宏,由于头文件使用#ifdef INCLUDE_STB_IMAGE_WRITE_H 来标志函数实现的源码只被包含一次,所以不会发生冲突。应该在CMakeLists.txt文件中将宏设置为PRIVATE ,这样这个宏就不会传递到包含它的项目中,从而避免了重定义。
  • 能否只使用头文件来进行编译,而不要再额外增加一个cpp文件?可行,因为头文件在预处理阶段就被复制到了引用它的源文件中,也就是它不会存在于编译阶段,也就不能拿来编译。其它的头文件库,例如type_safe中用的就是INTERFACE 关键字。由于STB_IMAGE里用的是#ifdef而不是#ifndef,不能只修改CMakeLists.txt而不修改某一个cpp源文件,因此pull/14只能去修改main.cpp,不符合要求。

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

Successfully merging this pull request may close these issues.

1 participant