Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
1.创建cpp,cpp中只需要include <stb_image_write.h>就可以,cpp文件用来编译动态链接库,add_library(stbiw SHARED stb_image_write.cpp)
2. 使用PUBLIC的target_include_directories,将所有链接了stbiw.so的target都从stbiw中搜索头文件,target_include_directories(stbiw PUBLIC ./)
3. 使用target_compile_definitions定义动态链接库的宏以编译stbi_write_png()这些函数,这里需要注意使用PRIVATE属性,否则会多重定义,因为前面还include了多次这个库的头文件,而函数的定义就在头文件中,所以会编译很多次。这里用PRIVATE不会将宏传递出去,只会在库编译时定义一次函数。