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__
As suggested by OP, posting my comment as an answer: for this you need to pass -m64 option to compiler/linker.
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:
- Get your MinGW-w64 compiler installed somewhere.
- Create a file with the path [MinGW-w64 dir]/include/_mingw.h and the content shown below.
- 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.