Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

64-bit version of GCC not compiling 64-bit exe

I am beginner regarding gcc command line compilation.
I need a help regarding -m64 flag.

I installed gcc compiler using MinGW.
I checked for gcc version by following,
gcc -v command, which shows Target: x86_64-w64-mingw32.
So I assume, 64-bit version of gcc is installed.

Objective: I wrote a small program to check, if the main.exe is generated for 32 or 64 bit.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#include<stdio.h>

int main(void)
{
    printf("The Size is: %lu\n", sizeof(long));
    
    return 0;   
}

I compiled using following command, gcc -o main main.c. When I execute the main.exe, it outputs, The Size is: 4.

But I expected the output to be `The Size is: 8′.

So i modified the command as gcc -m64 -o main main.c. When I executed the main.exe again, still it outputs `The Size is: 4′

How to compile for 64-bit version exe?

>Solution :

As others have said in the comments, the size of long can be 8 or 4 bytes on a 64bit system. You can try sizeof(size_t) or sizeof(void*). Even this might not be reliable on every system (but should work for Windows, Linux, macOS).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading