VS2015编译openjpeg(32/64位)

版权声明:本文为博主原创文章,转载请注明源地址。 https://blog.csdn.net/10km/article/details/50581246

上一篇博客《mingw(gcc)编译openjpeg》讲了如何用gcc编译openjpeg,但我目前只会在64位平台下生成64位目标代码,如果需要在64位平台生成32位目标代码怎么办?我还没有找到不修改CMakeList.txt的情况下在Windows 64位平台用gcc生成32位代码的办法(待研究),因为我的调试环境还是喜欢用VS2015所以我决定还是用VS2015再把openjpeg编译一遍,而且可以编译32和64位代码,方法比较笨,但总算有效,以后再研究更好的办法。 下面分别说明在win7 x64平台下编译32位和64位代码的过程

下载

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

编译环境

作者使用的操作系统平台是win7 x64, 编译器是目前最新的vs2015,cmake版本是3.1.0,准备好以上环境就可以开始代码编译了。

先将源码包解压到本地硬盘 D:\os.package\cpp\openjpeg\openjpeg-version.2.1 创建build目录openjpeg-version.2.1.prj:

D:\os.package\cpp\openjpeg>rmdir openjpeg-version.2.1.prj /s/q D:\os.package\cpp\openjpeg>mkdir openjpeg-version.2.1.prj D:\os.package\cpp\openjpeg>cd openjpeg-version.2.1.prj D:\os.package\cpp\openjpeg\openjpeg-version.2.1.prj>

win 7 x64下编译32位openjpeg

安装好VS2015后在命令行下执行set显示环境变量,会有如下图红圈所示的VS140COMNTOOLS变量

然后在命令行执行

D:\os.package\cpp\openjpeg\openjpeg-version.2.1.prj>”%VS140COMNTOOLS%vsvars32.bat” 来设置VC的命令行编译环境。

然后执行cmake来生成makefile文件

D:\os.package\cpp\openjpeg\openjpeg-version.2.1.prj>cmake -G “NMake Makefiles” - DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=j:/openjpeg-windows-vc-x86 -DCMAKE _BUILD_TYPE=RELEASE ..\openjpeg-version.2.1 – The C compiler identification is MSVC 19.0.23026.0 – Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe – Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe – works – Detecting C compiler ABI info – Detecting C compiler ABI info - 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 - not found – Looking for sys/stat.h – Looking for sys/stat.h - found – Looking for unistd.h – Looking for unistd.h - not found – Checking for 64-bit off_t – Checking for 64-bit off_t - not present – Checking for fseeko/ftello – Checking for fseeko/ftello - not found – Large File support - not found – Could NOT find ZLIB (missing: ZLIB_LIBRARY 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 “NMake Makefiles” 生成NMake 格式的Makefiles ,nmake是msvc的命令行编译工具 -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)》

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

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

然后执行nmake

D:\os.package\cpp\openjpeg\openjpeg-version.2.1.prj>nmake

Microsoft (R) 程序维护实用工具 14.00.23026.0 版 版权所有 (C) Microsoft Corporation。 保留所有权利。

Scanning dependencies of target openjp2 [ 2%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/bio.c.obj bio.c [ 5%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/cio.c.obj cio.c [ 8%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/dwt.c.obj dwt.c [ 11%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/event.c.obj event.c [ 14%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/image.c.obj image.c [ 17%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/invert.c.obj invert.c [ 20%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/j2k.c.obj j2k.c [ 22%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/jp2.c.obj jp2.c D:\os.package\cpp\openjpeg\openjpeg-version.2.1\src\lib\openjp2\jp2.c(872): warn ing C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失 [ 25%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/mct.c.obj mct.c [ 28%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/mqc.c.obj mqc.c [ 31%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/openjpeg.c.obj openjpeg.c [ 34%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/opj_clock.c.obj opj_clock.c [ 37%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/pi.c.obj pi.c [ 40%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/raw.c.obj raw.c [ 42%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/t1.c.obj t1.c [ 45%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/t2.c.obj t2.c [ 48%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/tcd.c.obj tcd.c [ 51%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/tgt.c.obj tgt.c [ 54%] Building C object src/lib/openjp2/CMakeFiles/openjp2.dir/function_list.c.obj function_list.c Linking C static library ……\bin\openjp2.lib [ 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 t1_generate_luts.c 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 opj_compress.c [ 62%] Building C object src/bin/jp2/CMakeFiles/opj_compress.dir/convert.c.obj convert.c [ 65%] Building C object src/bin/jp2/CMakeFiles/opj_compress.dir/index.c.obj index.c [ 68%] Building C object src/bin/jp2/CMakeFiles/opj_compress.dir/__/common/color.c.obj color.c [ 71%] Building C object src/bin/jp2/CMakeFiles/opj_compress.dir/__/common/opj_getopt.c.obj opj_getopt.c 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 opj_decompress.c [ 77%] Building C object src/bin/jp2/CMakeFiles/opj_decompress.dir/convert.c.obj convert.c [ 80%] Building C object src/bin/jp2/CMakeFiles/opj_decompress.dir/index.c.obj index.c [ 82%] Building C object src/bin/jp2/CMakeFiles/opj_decompress.dir/__/common/color.c.obj color.c [ 85%] Building C object src/bin/jp2/CMakeFiles/opj_decompress.dir/__/common/opj _getopt.c.obj opj_getopt.c 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 opj_dump.c [ 91%] Building C object src/bin/jp2/CMakeFiles/opj_dump.dir/convert.c.obj convert.c [ 94%] Building C object src/bin/jp2/CMakeFiles/opj_dump.dir/index.c.obj index.c [ 97%] Building C object src/bin/jp2/CMakeFiles/opj_dump.dir/__/common/color.c.obj color.c [100%] Building C object src/bin/jp2/CMakeFiles/opj_dump.dir/__/common/opj_getopt.c.obj opj_getopt.c Linking C executable ……\bin\opj_dump.exe [100%] Built target opj_dump

然后执行nmake install

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

D:\os.package\cpp\openjpeg\openjpeg-version.2.1.prj>nmake install Microsoft (R) 程序维护实用工具 14.00.23026.0 版 版权所有 (C) Microsoft Corporation。 保留所有权利。 [ 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-vc-x86/lib/openjpeg-2.1/OpenJPEGTargets.cmake – Installing: j:/openjpeg-windows-vc-x86/lib/openjpeg-2.1/OpenJPEGTargets-release.cmake – Installing: j:/openjpeg-windows-vc-x86/lib/openjpeg-2.1/OpenJPEGConfig.cmake – Installing: j:/openjpeg-windows-vc-x86/bin/msvcp140.dll – Installing: j:/openjpeg-windows-vc-x86/include/openjpeg-2.1/opj_config.h – Installing: j:/openjpeg-windows-vc-x86/lib/openjp2.lib – Installing: j:/openjpeg-windows-vc-x86/include/openjpeg-2.1/openjpeg.h – Installing: j:/openjpeg-windows-vc-x86/include/openjpeg-2.1/opj_stdint.h – Installing: j:/openjpeg-windows-vc-x86/bin/opj_decompress.exe – Installing: j:/openjpeg-windows-vc-x86/bin/opj_compress.exe – Installing: j:/openjpeg-windows-vc-x86/bin/opj_dump.exe

win 7 x64下编译64位openjpeg

上面的步骤执行下来,nmake生成的默认就是x86(32位)目标代码,因为对cmake nmake了解不够,现在还不知道如何在这个过程中指定生成64代码,所以生成64位代码我用了另外一个过程。

不要忘记了,在编译之前一定也要像上面的步骤一样,先执行”%VS140COMNTOOLS%vsvars32.bat”来设置VC的命令行编译环境哦

清理掉上面过程的文件,重新创建build文件夹(openjpeg-version.2.1.prj)

D:\os.package\cpp\openjpeg\openjpeg-version.2.1.prj>cd .. D:\os.package\cpp\openjpeg>rmdir openjpeg-version.2.1.prj /s/q D:\os.package\cpp\openjpeg>mkdir openjpeg-version.2.1.prj D:\os.package\cpp\openjpeg>cd openjpeg-version.2.1.prj D:\os.package\cpp\openjpeg\openjpeg-version.2.1.prj>

执行cmake生成VS2015 Win64格式的sln工程文件OPENJPEG.sln

D:\os.package\cpp\openjpeg\openjpeg-version.2.1.prj>cmake -G “Visual Studio 14 2 015 Win64” -DBUILD_SHARED_LIBS=OFF ..\openjpeg-version.2.1 – The C compiler identification is MSVC 19.0.23026.0 – Check for working C compiler using: Visual Studio 14 2015 Win64 – Check for working C compiler using: Visual Studio 14 2015 Win64 – works – Detecting C compiler ABI info – Detecting C compiler ABI info - 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 - not found – Looking for sys/stat.h – Looking for sys/stat.h - found – Looking for unistd.h – Looking for unistd.h - not found – Checking for 64-bit off_t – Checking for 64-bit off_t - not present – Checking for fseeko/ftello – Checking for fseeko/ftello - not found – Large File support - not found – Could NOT find ZLIB (missing: ZLIB_LIBRARY 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 D:\os.package\cpp\openjpeg\openjpeg-version.2.1.prj>

命令行调用VS2015开发环境devenv编译上面生成的工程文件OPENJPEG.sln,指定编译解决方案”Release|x64”

D:\os.package\cpp\openjpeg\openjpeg-version.2.1.prj>devenv OPENJPEG.sln /build ” Release|x64” Microsoft Visual Studio 2015 14.0.23107.0 版。 版权所有 (C) Microsoft Corp。保留所有权利。 1>—— 已启动生成: 项目: ZERO_CHECK, 配置: Release x64 —— 1> Checking Build System 1> CMake does not need to re-run because D:/os.package/cpp/openjpeg/openjpeg-version.2.1.prj/CMakeFiles/generate.stamp is up-to-date. 1> CMake does not need to re-run because D:/os.package/cpp/openjpeg/openjpeg-version.2.1.prj/src/lib/CMakeFiles/generate.stamp is up-to-date. 1> CMake does not need to re-run because D:/os.package/cpp/openjpeg/openjpeg-version.2.1.prj/src/lib/openjp2/CMakeFiles/generate.stamp is up-to-date. 1> CMake does not need to re-run because D:/os.package/cpp/openjpeg/openjpeg-version.2.1.prj/thirdparty/CMakeFiles/generate.stamp is up-to-date. 1> CMake does not need to re-run because D:/os.package/cpp/openjpeg/openjpeg-version.2.1.prj/src/bin/CMakeFiles/generate.stamp is up-to-date. 1> CMake does not need to re-run because D:/os.package/cpp/openjpeg/openjpeg-version.2.1.prj/src/bin/common/CMakeFiles/generate.stamp is up-to-date. 1> CMake does not need to re-run because D:/os.package/cpp/openjpeg/openjpeg-ve rsion.2.1.prj/src/bin/jp2/CMakeFiles/generate.stamp is up-to-date. 1> CMake does not need to re-run because D:/os.package/cpp/openjpeg/openjpeg-version.2.1.prj/src/bin/wx/CMakeFiles/generate.stamp is up-to-date. 1> CMake does not need to re-run because D:/os.package/cpp/openjpeg/openjpeg-version.2.1.prj/wrapping/CMakeFiles/generate.stamp is up-to-date. 2>—— 已启动生成: 项目: openjp2, 配置: Release x64 —— 3>—— 已启动生成: 项目: t1_generate_luts, 配置: Release x64 —— 2> Building Custom Rule D:/os.package/cpp/openjpeg/openjpeg-version.2.1/src/lib /openjp2/CMakeLists.txt 2> CMake does not need to re-run because D:\os.package\cpp\openjpeg\openjpeg-ve rsion.2.1.prj\src\lib\openjp2\CMakeFiles\generate.stamp is up-to-date. 2> bio.c 2> cio.c 2> dwt.c 2> event.c 2> image.c 3> Building Custom Rule D:/os.package/cpp/openjpeg/openjpeg-version.2.1/src/lib /openjp2/CMakeLists.txt 2> invert.c 3> CMake does not need to re-run because D:\os.package\cpp\openjpeg\openjpeg-ve rsion.2.1.prj\src\lib\openjp2\CMakeFiles\generate.stamp is up-to-date. 2> j2k.c 2> jp2.c 3> t1_generate_luts.c 2>D:\os.package\cpp\openjpeg\openjpeg-version.2.1\src\lib\openjp2\jp2.c(872): wa rning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unico de 格式以防止数据丢失 2> mct.c 2> mqc.c 2> openjpeg.c 3> t1_generate_luts.vcxproj -> D:\os.package\cpp\openjpeg\openjpeg-version.2.1. prj\bin\Release\t1_generate_luts.exe 2> opj_clock.c 2> pi.c 2> raw.c 2> t1.c 2> t2.c 2> tcd.c 2> tgt.c 2> function_list.c 2> 正在生成代码… 2> openjp2.vcxproj -> D:\os.package\cpp\openjpeg\openjpeg-version.2.1.prj\bin\R elease\openjp2.lib 4>—— 已启动生成: 项目: opj_compress, 配置: Release x64 —— 5>—— 已启动生成: 项目: opj_decompress, 配置: Release x64 —— 6>—— 已启动生成: 项目: opj_dump, 配置: Release x64 —— 5> Building Custom Rule D:/os.package/cpp/openjpeg/openjpeg-version.2.1/src/bin /jp2/CMakeLists.txt 4> Building Custom Rule D:/os.package/cpp/openjpeg/openjpeg-version.2.1/src/bin /jp2/CMakeLists.txt 5> CMake does not need to re-run because D:\os.package\cpp\openjpeg\openjpeg-ve rsion.2.1.prj\src\bin\jp2\CMakeFiles\generate.stamp is up-to-date. 4> CMake does not need to re-run because D:\os.package\cpp\openjpeg\openjpeg-ve rsion.2.1.prj\src\bin\jp2\CMakeFiles\generate.stamp is up-to-date. 5> opj_decompress.c 4> opj_compress.c 6> Building Custom Rule D:/os.package/cpp/openjpeg/openjpeg-version.2.1/src/bin /jp2/CMakeLists.txt 6> CMake does not need to re-run because D:\os.package\cpp\openjpeg\openjpeg-ve rsion.2.1.prj\src\bin\jp2\CMakeFiles\generate.stamp is up-to-date. 5> convert.c 5> index.c 4> convert.c 6> opj_dump.c 5> color.c 4> index.c 5> opj_getopt.c 4> color.c 5> 正在生成代码… 4> opj_getopt.c 4> 正在生成代码… 6> convert.c 6> index.c 6> color.c 6> opj_getopt.c 6> 正在生成代码… 5> opj_decompress.vcxproj -> D:\os.package\cpp\openjpeg\openjpeg-version.2.1.pr j\bin\Release\opj_decompress.exe 4> opj_compress.vcxproj -> D:\os.package\cpp\openjpeg\openjpeg-version.2.1.prj\ bin\Release\opj_compress.exe 6> opj_dump.vcxproj -> D:\os.package\cpp\openjpeg\openjpeg-version.2.1.prj\bin\ Release\opj_dump.exe 7>—— 已启动生成: 项目: ALL_BUILD, 配置: Release x64 —— 7> Building Custom Rule D:/os.package/cpp/openjpeg/openjpeg-version.2.1/CMakeLi sts.txt 7> CMake does not need to re-run because D:\os.package\cpp\openjpeg\openjpeg-ve rsion.2.1.prj\CMakeFiles\generate.stamp is up-to-date. 8>—— 已跳过生成: 项目: INSTALL, 配置: Release x64 —— 8>没有为此解决方案配置选中要生成的项目 9>—— 已跳过生成: 项目: PACKAGE, 配置: Release x64 —— 9>没有为此解决方案配置选中要生成的项目 ========== 生成: 成功 7 个,失败 0 个,最新 0 个,跳过 2 个 ========== D:\os.package\cpp\openjpeg\openjpeg-version.2.1.prj>

编译结束,所有的目标文件都在openjpeg-version.2.1.prj/bin/Release下。使用devenv编译sln工程没有install过程,你得手工把目标文件复制到你需要的位置。

在调用cmake生成OPEN.sln时如果 BUILD_SHARED_LIBS设为ON,就会生成openjp2.dll和导入库(import library)openjp2.lib

说话,我觉得编译32位和64位目标代码要用不同的办法,还是挺麻烦的,对于cmake交叉编译,目前还没有完全搞明白,如果哪位朋友有办法,不吝赐教啊。

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券

年度创作总结 领取年终奖励