使用CMake构建32位CGAL:即使指定了32位,也会生成64位二进制文件

Building 32-bit CGAL with CMake: makes 64-bit binaries even though 32-bit specified?

本文关键字:32位 二进制文件 64位 CGAL 构建 CMake 使用      更新时间:2023-10-16

我使用的是Windows 7。我已经在我的系统上安装了32位CGAL 4.6.2和Boost。我还成功地构建了Boost,并测试了它的工作原理(简单的regex程序(。

现在,我正按照本教程的指示,尝试使用CMake构建CGAL。我在该教程中添加的唯一一件事是,我在所有标志中引入了-m32标志;静态链接器、动态链接器、exe链接器、c和c++编译器。配置然后生成很好,我得到了CMake输出:

== Setting paths ==
Build CGAL from release in directory CGAL-4.6.2-x86
Packagenames: CGAL-4.6.2-x86
== Setting paths (DONE) ==
== Generate version files ==
CGAL_MAJOR_VERSION=4
CGAL_MINOR_VERSION=6
CGAL_BUGFIX_VERSION=2
CGAL_SONAME_VERSION=11
CGAL_SOVERSION     =11.0.0
CGAL_REFERENCE_CACHE_DIR=
Building shared libraries
Targetting MinGW Makefiles
Using E:/Program Files (x86)/CodeBlocks/MinGW/bin/x86_64-w64-mingw32-g++.exe compiler.
USING CMake version: 2.8.8
System: Windows
USING GCC_VERSION = '5.1.0'
Using gcc version 4 or later. Adding -frounding-math
== Generate version files (DONE) ==
== Set up flags ==
Build type: Release
USING CXXFLAGS = ' -frounding-math -m32 -O3 -DNDEBUG -m32'
USING LDFLAGS = '-m32 -m32'
== Set up flags (DONE) ==
== Detect external libraries ==
External libraries supported: GMP;MPFR;ZLIB;OpenGL;LEDA;MPFI;RS;RS3;OpenNL;Eigen3;BLAS;LAPACK;QGLViewer;ESBTL;Coin3D;NTL;IPE
Preconfiguring library: GMP ...
GMP has been preconfigured:
  UseGMP-file:      
  GMP include:      e:/Users/Bombax/Cpp/Libraries/CGAL-4.6.2-x86/auxiliary/gmp/include
  GMP libraries:    e:/Users/Bombax/Cpp/Libraries/CGAL-4.6.2-x86/auxiliary/gmp/lib/libgmp-10.dll
  GMP definitions:  
USING GMP_VERSION = '5.0.1'
Preconfiguring library: MPFR ...
MPFR has been preconfigured:
  UseMPFR-file:      
  MPFR include:      e:/Users/Bombax/Cpp/Libraries/CGAL-4.6.2-x86/auxiliary/gmp/include
  MPFR libraries:    e:/Users/Bombax/Cpp/Libraries/CGAL-4.6.2-x86/auxiliary/gmp/lib/libmpfr-4.dll
  MPFR definitions:  
USING MPFR_VERSION = '3.0.0'
Boost version: 1.59.0
Found the following Boost libraries:
  thread
  system
Boost include:     e:/Users/Bombax/Cpp/Libraries/boost_1_59_0-x86
Boost libraries:   optimized;e:/Users/Bombax/Cpp/Libraries/boost_1_59_0-x86/stage/lib/libboost_thread-mgw51-mt-1_59.a;debug;e:/Users/Bombax/Cpp/Libraries/boost_1_59_0-x86/stage/lib/libboost_thread-mgw51-mt-d-1_59.a;optimized;e:/Users/Bombax/Cpp/Libraries/boost_1_59_0-x86/stage/lib/libboost_system-mgw51-mt-1_59.a;debug;e:/Users/Bombax/Cpp/Libraries/boost_1_59_0-x86/stage/lib/libboost_system-mgw51-mt-d-1_59.a
Boost definitions: 
USING BOOST_VERSION = '1.59.0'
== Detect external libraries (DONE) ==
== Write compiler_config.h ==
== Write compiler_config.h (DONE) ==
== Generating build files ==
Configuring libCGAL
Requested component: MPFR
Requested component: GMP
libCGAL is configured
Sources for CGAL component library 'CGAL_Core' detected
Configuring libCGAL_Core
Requested component: MPFR
Requested component: GMP
libCGAL_Core is configured
Sources for CGAL component library 'CGAL_ImageIO' detected
Sources for CGAL component library 'CGAL_Qt3' detected
Sources for CGAL component library 'CGAL_Qt4' detected
Sources for CGAL component libraries 'CGAL_Core;CGAL_ImageIO;CGAL_Qt3;CGAL_Qt4' detected
== Generating build files (DONE) ==
Configuring done
Generating done

CMake为我生成了一个CodeBlocks项目,但我从未使用它成功构建过,因为无论我如何移动和重命名mingw32-make.exe,它似乎都无法找到make.exe。无论如何,在过去,我可以手动构建CGAL,我只需将mingw32-make.exe复制到我的CGAL文件夹中,然后从命令行在该文件夹中运行:

mingw32-make.exe -s -f Makefile all

但后来我得到了这个输出!

Scanning dependencies of target CGAL
[ 25%] Building CXX object src/CGAL/CMakeFiles/CGAL.dir/all_files.cpp.obj
[ 50%] Building RC object src/CGAL/CMakeFiles/CGAL.dir/CGAL_verinfo.rc.obj
Linking CXX shared library ....binlibCGAL.dll
E:/PROGRA~3/CODEBL~1/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../
86_64-w64-mingw32/bin/ld.exe: i386:x86-64 architecture of input file `CMakeFile
CGAL.dir/objects.a(CGAL_verinfo.rc.obj)' is incompatible with i386 output
collect2.exe: error: ld returned 1 exit status
srcCGALCMakeFilesCGAL.dirbuild.make:107: recipe for target 'bin/libCGAL.dll
 failed
mingw32-make.exe[2]: *** [bin/libCGAL.dll] Error 1
CMakeFilesMakefile2:185: recipe for target 'src/CGAL/CMakeFiles/CGAL.dir/all'
ailed
mingw32-make.exe[1]: *** [src/CGAL/CMakeFiles/CGAL.dir/all] Error 2
Makefile:112: recipe for target 'all' failed
mingw32-make.exe: *** [all] Error 2

我认为我做的一切都是正确的,所以CMake生成的是32位二进制文件,而不是64位二进制文件。但错误表明生成的二进制文件是64位的?我如何解决这个问题,我需要CMake中的另一个选项还是。。。?

我找到了解决方案。显然,windres.exe也在64位模式下运行,所以在使用CMake进行配置之前,我需要添加一些标志。具体来说,对于CMAKE_RC_FLAGS,我需要为我的Windows7系统添加--output-format=coff --target=pe-i386