conan+cmake 使用libpng库开发

构建环境

conan+cmake 使用libpng库开发_第1张图片

  • 随时可以在底部看到
    在这里插入图片描述

conan的配置文件



 [requires]
libpng/1.6.37@bincrafters/stable

[generators]
cmake

[options]
*:shared=True

[imports]
bin, *.dll -> ./bin
lib, *.dylib* -> ./bin

cmake 的配置文件

cmake_minimum_required(VERSION 3.0.0)
project(cdsConan VERSION 0.1.0)

include(CTest)
enable_testing()

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(cdsConan main.cpp)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

注意事项

  1. 下载动态库,并且将动态库导入文件中.
[options]
*:shared=True

[imports]
bin, *.dll -> ./bin
lib, *.dylib* -> ./bin

  1. cmake链接conan工程
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
  1. deubg
    1. 修改为debug模式
    2. 修改all为需要调试的文件

conan+cmake 使用libpng库开发_第2张图片

测试代码

conan+cmake 使用libpng库开发_第3张图片

#include 
#include 
#include 
#include 
#include 
#include 

#include 

using namespace std;

int main(int argc, const char **argv)
{


    png_image image; /* The control structure used by libpng */

    memset(&image, 0, (sizeof image));
    image.version = PNG_IMAGE_VERSION;

    printf("dsfsdfsfsfdsf============");
    printf("dsfsdfsfsfdsf============");
    printf("dsfsdfsfsfdsf============");
    char* name = "xxx.png";
    if (png_image_begin_read_from_file(&image, name) != 0) {
        png_bytep buffer;
         image.format = PNG_FORMAT_RGBA;
          buffer = (png_bytep)malloc(PNG_IMAGE_SIZE(image));

          if (buffer != NULL &&
            png_image_finish_read(&image, NULL/*background*/, buffer,
                0/*row_stride*/, NULL/*colormap*/) != 0) {
                    if (png_image_write_to_file(&image, "./cds.png", 0/*convert_to_8bit*/,
                        buffer, 0/*row_stride*/, NULL/*colormap*/) != 0)
                    {
                    /* The image has been written successfully. */
                    printf("dsfsdfsfsfdsf============");
                    printf("dsfsdfsfsfdsf============");
                    printf("dsfsdfsfsfdsf============");
                    printf("dsfsdfsfsfdsf============");
                    exit(0);
                    }
            } else {
                if (buffer == NULL)
               png_image_free(&image);
            else
               free(buffer);
            }
    }

    fprintf(stderr, "pngtopng: error: %s\n", image.message);
    system("pause");
    return 0;
}

你可能感兴趣的:(#,C,C++,tools)