强制使用CMake的32位编译的正确方法 [英] The proper way of forcing a 32-bit compile using CMake

查看:5184
本文介绍了强制使用CMake的32位编译的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,有很多类似的问题,但我确实发现,谷歌的CMake查询总是产生类似但不是相同的场景,冲突的CMake命令等!



我需要强制我的项目构建32位二进制文​​件,因为我必须链接一个库,只有可用的32位。我诊断这是基于错误消息,如:

  / usr / bin / ld:i386架构的输入文件` 32bit-lib *'与i386不兼容:x86-64输出

因此,请使用:

  set(CMAKE_CXX_FLAGS-m32)

这改变了事情 - 我现在得到几个错误,如:

  / usr / bin / ld:i386输入文件架构`* project-output-lib *'与i386不兼容:x86-64 output 

仍然会得到与外部库相同的错误。 I 这是因为 -m32 使gcc生成32位二进制文​​件,但ld仍在尝试64位输出?进一步谷歌这个问题没有任何成功,所以如果任何人可以验证我是对的,并给正确的方式这样做,我会非常感谢!



非常感谢!

解决方案

如果你想编译和链接32位使用cmake使用这个创建库和二进制: / p>

创建库:

  add_library(mylib SHARED my_source.c)
set_target_properties(mylib PROPERTIES COMPILE_FLAGS-m32LINK_FLAGS-m32)

  add_executable(mybin sources.c)
set_target_properties(mybin PROPERTIES COMPILE_FLAGS-m32LINK_FLAGS-m32)

希望这有帮助,


Sorry that there are many similar questions, but I do find that Googling for CMake queries always yields similar-but-not-the-same scenarios, conflicting CMake commands and so on!

I need to force my project to build 32-bit binaries because I have to link with a library which is only available as 32-bit. I diagnosed this based on error messages such as:

/usr/bin/ld: i386 architecture of input file `*external-32bit-lib*' is incompatible with i386:x86-64 output

From what I gather, I should therefore use:

set (CMAKE_CXX_FLAGS "-m32")

This does change things - I now get several errors like:

/usr/bin/ld: i386 architecture of input file `*project-output-lib*' is incompatible with i386:x86-64 output

AND still get the same errors for the external library too. I think this is because the -m32 made gcc generate 32-bit binaries, but ld is still trying for 64-bit output? Further Googling for this problem didn't give any success, so if anyone could verify that I am right and give the correct way of doing this, I would be very grateful!

Many thanks!

解决方案

If you want to compile and link for 32 bit using cmake use this for creating libraries and binaries:

Creating libraries:

add_library(mylib SHARED my_source.c)
set_target_properties(mylib PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")

creating executables:

add_executable(mybin sources.c)
set_target_properties(mybin PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")

Hope this helps,

这篇关于强制使用CMake的32位编译的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆