温馨提示×

cximage在debian如何编译

小樊
38
2026-09-20 16:16:21
栏目: 智能运维

下面以 Debian / Ubuntu 环境为例,说明如何编译 CxImage(一个较老但常用的 C++ 图像处理库)。


一、准备编译环境

先在终端安装编译工具:

sudo apt update
sudo apt install -y build-essential g++ make

如果你打算用 Code::Blocks / wxWidgets / MFC(Windows),在 Debian 下一般只用 Makefile 或 CMake。


二、获取 CxImage 源码

1️⃣ 官方版本(SourceForge)

wget https://downloads.sourceforge.net/cximage/cximage599c.zip
unzip cximage599c.zip
cd cximage

目录结构大致如下:

cximage/
├── CxImage/
├── jpeg/
├── png/
├── tiff/
├── zlib/
├── Makefile
└── ...

三、使用自带 Makefile 编译(最简单)

1️⃣ 编译静态库

cd cximage
make

编译完成后会生成:

libcximage.a

2️⃣ 常见问题(Debian 下)

❌ 错误:uint / long long 未定义

修改:

typedef unsigned int uint;

或在编译时加:

make CXXFLAGS="-fpermissive"

❌ 错误:register 关键字

C++17 已移除,可改为:

make CXXFLAGS="-std=c++14"

四、手动写 Makefile(推荐方式)

如果你只要 CxImage 核心库:

CXX = g++
CXXFLAGS = -std=c++14 -I. -I./CxImage -I./jpeg -I./png -I./zlib

SRC = $(wildcard CxImage/*.cpp jpeg/*.cpp png/*.cpp zlib/*.cpp)

libcximage.a: $(SRC)
	$(CXX) $(CXXFLAGS) -c $^
	ar rcs $@ *.o

clean:
	rm -f *.o libcximage.a

编译:

make

五、在项目中如何使用

#include "CxImage.h"

int main() {
    CxImage image;
    image.Load("test.jpg", CXIMAGE_FORMAT_JPG);
    image.Save("out.png", CXIMAGE_FORMAT_PNG);
}

编译你的程序:

g++ main.cpp -I./cximage -L./cximage -lcximage -lpthread

六、用 CMake 编译(可选)

示例 CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)
project(cximage_demo)

set(SRC
    CxImage/*.cpp
    jpeg/*.cpp
    png/*.cpp
    zlib/*.cpp
)

add_library(cximage STATIC ${SRC})
target_include_directories(cximage PUBLIC .)
mkdir build && cd build
cmake ..
make

七、注意事项(Debian 用户必看)

✅ CxImage 不支持 C++17/20
✅ 建议 -std=c++14
✅ 仅适合 老项目 / 图像格式转换
✅ 新项目推荐:OpenCV / stb_image / libfreeimage


如果你告诉我:

  • Debian 版本(10 / 11 / 12)
  • 是否用于 GUI / 命令行
  • 是否只要 JPEG/PNG 支持

我可以给你一份 可直接编译的精简版本。

0 踩