Compile C++ as 64Bit with CLion

杀马特。学长 韩版系。学妹 提交于 2019-12-11 10:29:27

问题


I have a c++ application that runs a memory-consuming algorithm.

It crushes with error : terminate called after throwing an instance of 'std::bad_alloc' after the allocated memory reaches about 2GB.

I want to compile it as 64Bit so it could allocate more memory from my 64Bit/8GB Ram machine.

How it can be done?

Im working with CLion, building with CMake and using mingw version: mingw-w64\i686-4.8.3-posix-dwarf-rt_v3-rev2 btw - the wingw is installed under C:\Program Files (x86)\mingw-w64 is this related to the issue?

I've been looking here: Detecting 64bit compile in C and (not suprisingly) I can see that my application does not have the __x86_64__


回答1:


As suggested by OP, posting my comment as an answer: for this you need to pass -m64 option to compiler/linker.




回答2:


You have to tell CLion to use MinGW-w64 to build your CMake project.

You dont have to change your CMake project configuration. It would be counterproductive limiting your CMake project by a fixed machine architecture, if you can instead easily tell your compiler which architecture to build for or use an appropriate compiler (MinGW-w64).

This post shows you how to do that:

https://dev.my-gate.net/2014/09/15/how-to-use-mingw-w64-with-clion/

Excerpt from this post:

Here are the few steps to make it work:

  1. Get your MinGW-w64 compiler installed somewhere.
  2. Create a file with the path [MinGW-w64 dir]/include/_mingw.h and the content shown below.
  3. Point CLion to your [MinGW-w64 dir] and watch how CLion recognizes your MinGW setup.

After building your executable, you can check its architecture with the unix command file, which should be available to you since you are using mingw.



来源:https://stackoverflow.com/questions/33923609/compile-c-as-64bit-with-clion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!