c语言编译 64位,cmake – 编译32位和64位

正如我在评论中所说,这是我们如何做到这一点的一个例子.

if( CMAKE_SIZEOF_VOID_P EQUAL 8 )

MESSAGE( "64 bits compiler detected" )

SET( EX_PLATFORM 64 )

SET( EX_PLATFORM_NAME "x64" )

else( CMAKE_SIZEOF_VOID_P EQUAL 8 )

MESSAGE( "32 bits compiler detected" )

SET( EX_PLATFORM 32 )

SET( EX_PLATFORM_NAME "x86" )

endif( CMAKE_SIZEOF_VOID_P EQUAL 8 )

...

IF( EX_PLATFORM EQUAL 64 )

MESSAGE( "Outputting to lib64 and bin64" )

# ---------- Setup output Directories -------------------------

SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY

${YourSoftwarePath}/lib64

CACHE PATH

"Single Directory for all Libraries"

)

# --------- Setup the Executable output Directory -------------

SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY

${YourSoftwarePath}/bin64

CACHE PATH

"Single Directory for all Executables."

)

# --------- Setup the Executable output Directory -------------

SET (CMAKE_ARCHIVE_OUTPUT_DIRECTORY

${YourSoftwarePath}/lib64

CACHE PATH

"Single Directory for all static libraries."

)

ELSE( EX_PLATFORM EQUAL 64 )

# ---------- Setup output Directories -------------------------

SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY

${YourSoftwarePath}/lib

CACHE PATH

"Single Directory for all Libraries"

)

# --------- Setup the Executable output Directory -------------

SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY

${YourSoftwarePath}/bin

CACHE PATH

"Single Directory for all Executables."

)

# --------- Setup the Executable output Directory -------------

SET (CMAKE_ARCHIVE_OUTPUT_DIRECTORY

${YourSoftwarePath}/lib

CACHE PATH

"Single Directory for all static libraries."

)

ENDIF( EX_PLATFORM EQUAL 64 )

...

add_library(YourSoftware SHARED

${INCLUDES}

${SRC}

)

它对我们来说效果很好,即使在我们的生产过程中也是如此.

它允许top为我们的配置做好准备:32位和64位.之后我们必须在两个平台上构建.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值