mingw(gcc)编译openjpeg

20 篇文章 7 订阅

[openjpeg]1是C语言实现的开源[jpeg2000]2图像格式的编码/解码器,github上有编译好的linux/windows二进制文件,目前最新的版本是2.1(https://github.com/uclouvain/openjpeg/releases/tag/version.2.1)
但官方提供的二进制文件只提供了dll,如果想要将代码静态编译到项目中需要自己下载源代码编译。

下载

原代码下载:https://github.com/uclouvain/openjpeg/archive/version.2.1.zip

编译环境要求

作者的编译环境是win7 x64平台,编译器是MinGW5.2.0,cmake版本是3.1.0,准备好以上环境就可以开始代码编译了。
如何安装mingw和cmake,网上有很多教程讲得很详细,这里不再细说。

编译

先将源码包解压到本地硬盘
D:\os.package\cpp\openjpeg\openjpeg-version.2.1

然后创建build目录

D:\os.package\cpp\openjpeg\openjpeg-version.2.1>cd D:\os.package\cpp\openjpeg
D:\os.package\cpp\openjpeg>mkdir openjpeg-version.2.1.prj
D:\os.package\cpp\openjpeg\openjpeg-version.2.1.prj>cmake -G “Eclipse CDT4 - MinGW Makefiles” -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=j:/openjpeg-windows-gcc-x86_64 -DCMAKE_GNUtoMS=ON …\openjpeg-ver
sion.2.1
– The C compiler identification is GNU 5.2.0
– Could not determine Eclipse version, assuming at least 3.6 (Helios). Adjust C
MAKE_ECLIPSE_VERSION if this is wrong.
– Check for working C compiler: P:/MinGW/mingw64/bin/gcc.exe
– Check for working C compiler: P:/MinGW/mingw64/bin/gcc.exe – works
– Detecting C compiler ABI info
– Detecting C compiler ABI info - done
– Detecting C compile features
– Detecting C compile features - done
– Check if the system is big endian
– Searching 16 bit integer
– Looking for sys/types.h
– Looking for sys/types.h - found
– Looking for stdint.h
– Looking for stdint.h - found
– Looking for stddef.h
– Looking for stddef.h - found
– Check size of unsigned short
– Check size of unsigned short - done
– Using unsigned short
– Check if the system is big endian - little endian
– Looking for string.h
– Looking for string.h - found
– Looking for memory.h
– Looking for memory.h - found
– Looking for stdlib.h
– Looking for stdlib.h - found
– Looking for stdio.h
– Looking for stdio.h - found
– Looking for math.h
– Looking for math.h - found
– Looking for float.h
– Looking for float.h - found
– Looking for time.h
– Looking for time.h - found
– Looking for stdarg.h
– Looking for stdarg.h - found
– Looking for ctype.h
– Looking for ctype.h - found
– Looking for assert.h
– Looking for assert.h - found
– Looking for stdint.h
– Looking for stdint.h - found
– Looking for inttypes.h
– Looking for inttypes.h - found
– Looking for strings.h
– Looking for strings.h - found
– Looking for sys/stat.h
– Looking for sys/stat.h - found
– Looking for unistd.h
– Looking for unistd.h - found
– Checking for 64-bit off_t
– Checking for 64-bit off_t - present with _FILE_OFFSET_BITS=64
– Checking for fseeko/ftello
– Checking for fseeko/ftello - present
– Large File support - found
– Could NOT find ZLIB (missing: ZLIB_INCLUDE_DIR)
– Z lib not found, activate BUILD_THIRDPARTY if you want build it (necessary to
build libPNG)
– Could NOT find TIFF (missing: TIFF_LIBRARY TIFF_INCLUDE_DIR)
– TIFF lib not found, activate BUILD_THIRDPARTY if you want build it
– Could NOT find LCMS2 (missing: LCMS2_LIBRARY LCMS2_INCLUDE_DIR)
– Could NOT find LCMS (missing: LCMS_LIBRARY LCMS_INCLUDE_DIR)
– LCMS2 or LCMS lib not found, activate BUILD_THIRDPARTY if you want build it
– Configuring done
– Generating done
– Build files have been written to: D:/os.package/cpp/openjpeg/openjpeg-version
.2.1.prj

在上面的执行cmake创建makefile时,定义了几个参数,含义如下:
-G “Eclipse CDT4 - MinGW Makefiles”
生成eclipse工程文件和MinGW格式的Makefiles
-DBUILD_SHARED_LIBS=OFF
指定创建静态链接库.lib,默认是ON,生成dll

openjpeg提供的CMakeList.txt不能同时创建静态库和动态库,所以你既想要静态库,又想到动态库的时候,就得修改这个参数,编译两次。
当生成动态库的时候,还可以参加参数 -DCMAKE_GNUtoMS=ON 生成MSVC格式的导入库(import library .lib文件)。这样MSVC就可以直接使用GCC编译的动态库了。参见我之前的博客[《cmake:让mingw(gcc)生成MSVC可用的dll(.lib)》]3

-DCMAKE_BUILD_TYPE=RELEASE
就是生成RELEASE,这个参数即使不定义,默认也是生成 RELEASE版本

-DCMAKE_INSTALL_PREFIX=j:/openjpeg-windows-gcc-x86
这个参数指定在执行make install时的安装路径。如果不指定默认是安装到"C:/Program Files (x86)/OPENJPEG"。

然后执行make

D:\os.package\cpp\openjpeg\openjpeg-version.2.1.prj>make
Scanning dependencies of target openjp2
[ 2%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/bio.c.obj
[ 5%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/cio.c.obj
[ 8%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/dwt.c.obj
[ 11%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/event.c.obj
[ 14%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/image.c.obj
[ 17%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/invert.c.obj
[ 20%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/j2k.c.obj
[ 22%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/jp2.c.obj
[ 25%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/mct.c.obj
[ 28%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/mqc.c.obj
[ 31%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/openjpeg.c.obj
[ 34%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/opj_clock.c.obj
[ 37%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/pi.c.obj
[ 40%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/raw.c.obj
[ 42%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/t1.c.obj
[ 45%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/t2.c.obj
[ 48%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/tcd.c.obj
[ 51%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/tgt.c.obj
[ 54%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/function_list.c.obj
Linking C static library …\bin\libopenjp2.a
[ 54%] Built target openjp2
Scanning dependencies of target t1_generate_luts
[ 57%] Building C object src/lib/openjp2/CMakeFiles/t1_generate_luts.dir/t1_generate_luts.c.obj
Linking C executable …\bin\t1_generate_luts.exe
[ 57%] Built target t1_generate_luts
Scanning dependencies of target opj_compress
[ 60%] Building C object src/bin/jp2/CMakeFiles/opj_compress.dir/opj_compress.c.obj
[ 62%] Building C object src/bin/jp2/CMakeFiles/opj_compress.dir/convert.c.obj
[ 65%] Building C object src/bin/jp2/CMakeFiles/opj_compress.dir/index.c.obj
[ 68%] Building C object src/bin/jp2/CMakeFiles/opj_compress.dir//common/color.c.obj
[ 71%] Building C object src/bin/jp2/CMakeFiles/opj_compress.dir/
/common/opj_getopt.c.obj
Linking C executable …\bin\opj_compress.exe
[ 71%] Built target opj_compress
Scanning dependencies of target opj_decompress
[ 74%] Building C object src/bin/jp2/CMakeFiles/opj_decompress.dir/opj_decompress.c.obj
[ 77%] Building C object src/bin/jp2/CMakeFiles/opj_decompress.dir/convert.c.obj
[ 80%] Building C object src/bin/jp2/CMakeFiles/opj_decompress.dir/index.c.obj
[ 82%] Building C object src/bin/jp2/CMakeFiles/opj_decompress.dir//common/color.c.obj
[ 85%] Building C object src/bin/jp2/CMakeFiles/opj_decompress.dir/
/common/opj_getopt.c.obj
Linking C executable …\bin\opj_decompress.exe
[ 85%] Built target opj_decompress
Scanning dependencies of target opj_dump
[ 88%] Building C object src/bin/jp2/CMakeFiles/opj_dump.dir/opj_dump.c.obj
[ 91%] Building C object src/bin/jp2/CMakeFiles/opj_dump.dir/convert.c.obj
[ 94%] Building C object src/bin/jp2/CMakeFiles/opj_dump.dir/index.c.obj
[ 97%] Building C object src/bin/jp2/CMakeFiles/opj_dump.dir//common/color.c.obj
[100%] Building C object src/bin/jp2/CMakeFiles/opj_dump.dir/
/common/opj_getopt.c.obj
Linking C executable …\bin\opj_dump.exe
[100%] Built target opj_dump

安装

然后执行make install ,就会将生成的二进制文件自动复制到前面CMAKE_INSTALL_PREFIX指定的j:/openjpeg-windows-gcc-x86文件夹下,分为bin\include\lib三个子目录。

D:\os.package\cpp\openjpeg\openjpeg-version.2.1.prj>make install
[ 54%] Built target openjp2
[ 57%] Built target t1_generate_luts
[ 71%] Built target opj_compress
[ 85%] Built target opj_decompress
[100%] Built target opj_dump
Install the project…
– Install configuration: “RELEASE”
– Installing: j:/openjpeg-windows-gcc-x86_64/lib/openjpeg-2.1/OpenJPEGTargets.cmake
– Installing: j:/openjpeg-windows-gcc-x86_64/lib/openjpeg-2.1/OpenJPEGTargets-release.cmake
– Installing: j:/openjpeg-windows-gcc-x86_64/lib/openjpeg-2.1/OpenJPEGConfig.cmake
– Installing: j:/openjpeg-windows-gcc-x86_64/include/openjpeg-2.1/opj_config.h
– Installing: j:/openjpeg-windows-gcc-x86_64/lib/libopenjp2.a
– Installing: j:/openjpeg-windows-gcc-x86_64/include/openjpeg-2.1/openjpeg.h
– Installing: j:/openjpeg-windows-gcc-x86_64/include/openjpeg-2.1/opj_stdint.h
– Installing: j:/openjpeg-windows-gcc-x86_64/bin/opj_decompress.exe
– Installing: j:/openjpeg-windows-gcc-x86_64/bin/opj_compress.exe
– Installing: j:/openjpeg-windows-gcc-x86_64/bin/opj_dump.exe

因为我的操作系统是64的,所以生成的目标代码也是64位的,如果要生成32位的目标代码,需要安装32位的编译器就是(mingw32)。
可以去mingw官网下载(mingw-w64-install.exe),下载后运行在设置界面选择i686版本,就是mingw32的版本。
这里写图片描述
安装好之后,先执行下图安装路径中的mingw-w64.bat设置正确搜索路径(也可以手工把mingw32的bin路径直接设置到环境变量中,免去每次都执行mingw-w64.bat)
这里写图片描述
然后重复上面的所有步骤,就可以编译32位版本了。

jpeg 编解码系列文章

《mingw(gcc)编译libjpeg-turbo》
《libjpeg:实现jpeg内存压缩暨error_exit错误异常处理和个性化参数设置》
《libjpeg:实现jpeg内存解压缩塈转换色彩空间/压缩分辨率》
《libjpeg:读取jpeg头获取图像基本信息(jpeg_read_header)》
《nmake(vs2015)命令行编译libjpeg-turbo(x86/amd64)》

jpeg2000 编码系列文章

《mingw(gcc)编译openjpeg》
《VS2015编译openjpeg(32/64位)》
《openjpeg:解决静态链接时未定义引用错误:undefined reference to `__imp_opj_xxxxxxx‘》
《jpeg2000(j2k)图像编码解码:c++实现openjpeg内存流接口(memory stream)》
《openjpeg:jpeg2000(j2k)图像内存压缩编码》
《openjpeg:jpeg2000(j2k)图像内存解压缩(解码)》
《cmake设置msvc的运行库(runtime library)塈指定openjpeg使用静态库》


  1. http://www.openjpeg.org/ ↩︎

  2. http://www.jpeg.org/jpeg2000 ↩︎

  3. http://blog.csdn.net/10km/article/details/50525604 ↩︎

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

10km

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值