Results 1 to 10 of 10

Thread: How to know if 32 or 64 linux.

  1. #1
    Join Date
    Feb 2010
    Posts
    21
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default How to know if 32 or 64 linux.

    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.

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to know if 32 or 64 linux.

    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.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to know if 32 or 64 linux.

    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?

  4. #4
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to know if 32 or 64 linux.

    Quote Originally Posted by ChrisW67 View Post
    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.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to know if 32 or 64 linux.

    Quote Originally Posted by SixDegrees View Post
    Actually, the 'file' utility will reveal whether any given executable is 64 or 32 bit.
    How does that differ from what I wrote?

  6. #6
    Join Date
    Feb 2010
    Posts
    21
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to know if 32 or 64 linux.

    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

  7. #7
    Join Date
    Mar 2009
    Posts
    14
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Lightbulb Re: How to know if 32 or 64 linux.

    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.

  8. The following user says thank you to perden for this useful post:

    nomadscarecrow (21st June 2010)

  9. #8
    Join Date
    Feb 2010
    Posts
    21
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to know if 32 or 64 linux.

    Quote Originally Posted by perden View Post
    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.

  10. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to know if 32 or 64 linux.

    Assuming you are are using GCC on Linux then these predefined macros may be useful:
    Qt Code:
    1. __i386__ You're compiling for a 32-bit Intel
    2. __x86_64__ You're compiling for a 64-bit Intel
    3. __ppc__ You're compiling for a 32-bit PowerPC
    4. __ppc64__ You're compiling for a 64-bit PowerPC
    5.  
    6. __LP64__ possibly an indicator of 64-bitness
    To copy to clipboard, switch view to plain text mode 
    You can see what your GCC defines with:
    Qt Code:
    1. cpp -dM -E < /dev/null
    To copy to clipboard, switch view to plain text mode 
    You could also peruse qglobal.h for hints as to how the Qt system does it.

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

  11. The following user says thank you to ChrisW67 for this useful post:

    nomadscarecrow (16th July 2010)

  12. #10
    Join Date
    Feb 2010
    Posts
    21
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to know if 32 or 64 linux.

    By the way ... thanks for the answers ... very helpful ...

Similar Threads

  1. another ide on linux ?
    By hcetiner in forum Newbie
    Replies: 3
    Last Post: 13th May 2010, 15:38
  2. linux-ipaq-g++ Vs linux-arm-g++
    By alejo in forum Installation and Deployment
    Replies: 0
    Last Post: 22nd February 2010, 01:23
  3. using win or linux?
    By mattia in forum Newbie
    Replies: 3
    Last Post: 19th March 2008, 22:46
  4. IDE for Linux
    By steg90 in forum Newbie
    Replies: 22
    Last Post: 15th July 2007, 16:27
  5. From MAC OS X to Linux
    By DoNaLd in forum Qt Programming
    Replies: 7
    Last Post: 7th July 2006, 20:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.