64位机器上 编译32位程序

来源:互联网 发布:阿里云 更改域名 编辑:程序博客网 时间:2024/05/17 22:21

由于程序迁移,需要在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


原创粉丝点击