由于程序迁移,需要在64bit开发机上编译32bit的程序。
在64位的机器上编译32位还是62位程序,主要是要编译器和链接器上加上参数据:-m32 (编译32位) -m64(编译64)
在自己的makefile中添加"CFLAGS=-m32"
"CXXFLAGS=-m32" "LDFLAGS=-m32"
即可
因为项目中用到了boost库,编译32bit boost 命令如下:
./bjam toolset=gcc --prefix=**** --layout=versioned --build-type=complete --with-system address-model=32 install对于采用autotools 开源库的编译:./configure --help可看到如下信息:--host=HOST cross-compile to build programs to run on HOST [BUILD]
Some influential environment variables:
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
nonstandard directory <lib dir>
LIBS libraries to pass to the linker, e.g. -l<library>
CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
you have headers in a nonstandard directory <include dir>
CXX C++ compiler command
CXXFLAGS C++ compiler flags
CXXCPP C++ preprocessor因此:./configure --prefix=**** --host=i686-linux-gnu "CFLAGS=-m32" "CXXFLAGS=-m32" "LDFLAGS=-m32"make && make install