PDA

View Full Version : How to know if 32 or 64 linux.



nomadscarecrow
19th June 2010, 00:37
Is there a flag or something to know if the application is the 32 or 64 bit version, building on Linux?

I found a lot of flags about the OS and Window system, but none about this.

Thanks.

SixDegrees
19th June 2010, 00:50
Various 'uname' flags will tell you if the machine is 64 or 32 bit. You can also parse /proc/cpuinfo. You can check a particular executable with the 'file' utility.

ChrisW67
19th June 2010, 01:59
SixDegrees' suggestions will tell you if the operating system is running 32- or 64-bit (uname), CPU is 64-bit capable (cpuinfo) but not what mode it is currently in, or whether an arbitrary executable is 32- or 64-bit (file).

If you want to know if your running executable is 32- or 64-bit then surely you can build the application so that it knows?

SixDegrees
19th June 2010, 10:21
SixDegrees' suggestions will tell you if the operating system is running 32- or 64-bit (uname), CPU is 64-bit capable (cpuinfo) but not what mode it is currently in, or whether an arbitrary executable is 32- or 64-bit (file).

If you want to know if your running executable is 32- or 64-bit then surely you can build the application so that it knows?

Actually, the 'file' utility will reveal whether any given executable is 64 or 32 bit.

ChrisW67
20th June 2010, 05:06
Actually, the 'file' utility will reveal whether any given executable is 64 or 32 bit.
How does that differ from what I wrote?

nomadscarecrow
21st June 2010, 15:42
Thanks for the replies ... but my problem is different ... let me explain

With Q_WS_X11 defined I know if I'm running on a x11 environment, and make specific code for this scenario if I need. Q_OS_LINUX let me check the OS, and there are another defines to check other OS's and environments.

My problem: I need something like this flags to check if I'm running 64 or 32 bit of my software version? Or, I must start to write my own define's?

Thanks :)

perden
21st June 2010, 16:24
The mkspec which you are compiling for is defined as a scope when qmake gets run. So for one possible solution, you could check for that scope in your .pro file, and make any special defines for yourself. For example, when I need to add a platform specific library I add the following to my .pro file.

linux-g++-32:LIBS += -Llib/ -lmyliblin32
linux-g++-64:LIBS += -Llib/ -lmyliblin64
win32-g++:LIBS += mylibwin32.lib

The benefit of this is that it's cross platform; you don't have to rely on a platform-specific utility to give you info about the same platform. The down side is there are a lot of possible mkspecs that you'd have to handle if you plan on distributing your source.

Ideally, there'd be something already defined for you, but I haven't found anything like that yet.

nomadscarecrow
21st June 2010, 16:48
The mkspec which you are compiling for is defined as a scope when qmake gets run. So for one possible solution, you could check for that scope in your .pro file, and make any special defines for yourself. For example, when I need to add a platform specific library I add the following to my .pro file.

linux-g++-32:LIBS += -Llib/ -lmyliblin32
linux-g++-64:LIBS += -Llib/ -lmyliblin64
win32-g++:LIBS += mylibwin32.lib

The benefit of this is that it's cross platform; you don't have to rely on a platform-specific utility to give you info about the same platform. The down side is there are a lot of possible mkspecs that you'd have to handle if you plan on distributing your source.

Ideally, there'd be something already defined for you, but I haven't found anything like that yet.

Yes ... I was thinking to play with qmake and .pro file to a conditional "include" of files with the defines...

The main idea of this is the update functionality that I'm including on my software. If 32bit, download and apply 32 patch, else ... 64 bit, the 64patch. That is the reason because to know if the application is 32 or 64 bit. A elegant way is with flags, just like I mentioned ... but ... the magic will came from the qmake and .pro files

thanks.

ChrisW67
21st June 2010, 23:27
Assuming you are are using GCC on Linux then these predefined macros may be useful:


__i386__ You're compiling for a 32-bit Intel
__x86_64__ You're compiling for a 64-bit Intel
__ppc__ You're compiling for a 32-bit PowerPC
__ppc64__ You're compiling for a 64-bit PowerPC

__LP64__ possibly an indicator of 64-bitness

You can see what your GCC defines with:


cpp -dM -E < /dev/null

You could also peruse qglobal.h for hints as to how the Qt system does it.

http://predef.sourceforge.net/ is also very useful

nomadscarecrow
16th July 2010, 00:41
By the way ... thanks for the answers ... very helpful ... ;)