Skip to content

Commit

Permalink
add hw01
Browse files Browse the repository at this point in the history
  • Loading branch information
archibate committed Dec 14, 2021
1 parent 81bb872 commit f621092
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
33 changes: 1 addition & 32 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,32 +1 @@
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app
build
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.12)
project(hellocmake LANGUAGES CXX)

add_subdirectory(stbiw)

add_executable(main main.cpp)
target_link_libraries(main PUBLIC stbiw)
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
# hw01

第01讲的回家作业

# 要求

在 main.cpp 中为了导出一个美好的图像,使用了 `stb_image_write.h` 这个头文件。

在 CMakeLists.txt 中也引用了 stbiw 这个库,然而这个库还没有被定义。
你的任务就是定义 stbiw 这个库,他的内容应该包含 stbi_write_png 的实现。

最好以子模块 + 库的形式,实在搞不定的话同一个目录下 include 也可以。但是分数会低。

# 参考

stb_image_write.h 下载地址: https://github.com/nothings/stb/blob/master/stb_image_write.h

你需要一个 .cpp 文件定义了 STB_IMAGE_WRITE_IMPLEMENTATION 这个宏,才能决定让 stbi 系列函数在这里实现。

像这样:
```cmake
target_compile_definitions(stbiw PUBLIC -DSTB_IMAGE_WRITE_IMPLEMENTATION)
```
是不行的,因为如果两个 .cpp 文件都 include 了 stb_image_write.h,那么同一个函数会被定义两遍!
1 change: 1 addition & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "stb_image_write.h"
1 change: 1 addition & 0 deletions stbiw/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
message(FATAL_ERROR "请修改 stbiw/CMakeLists.txt!要求生成一个名为 stbiw 的库")

0 comments on commit f621092

Please sign in to comment.