conan+cmake 使用libpng库开发

构建环境

在这里插入图片描述

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

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为需要调试的文件

在这里插入图片描述

测试代码

在这里插入图片描述

#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <png.h>
#include <zlib.h>

#include <string>

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;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

早睡的叶子

你的鼓励就是我的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值