- Thread: Compiling 32bit from 64bit Ubuntu(g++)
- Compiling 32bit from 64bit Ubuntu(g++)
- Re: Compiling 32bit from 64bit Ubuntu(g++)
- Re: Compiling 32bit from 64bit Ubuntu(g++)
- Re: Compiling 32bit from 64bit Ubuntu(g++)
- Re: Compiling 32bit from 64bit Ubuntu(g++)
- Re: Compiling 32bit from 64bit Ubuntu(g++)
- Re: Compiling 32bit from 64bit Ubuntu(g++)
- Re: Compiling 32bit from 64bit Ubuntu(g++)
- Re: Compiling 32bit from 64bit Ubuntu(g++)
- Linux from 64 bits
- About
- Linux futex for 64-bits
- 2 Answers 2
- How to cross compile for linux x86 with linux amd64, cmake and g++?
- Here is the information I found:
- missing pieces:
- How to determine whether a given Linux is 32 bit or 64 bit?
- 21 Answers 21
Thread: Compiling 32bit from 64bit Ubuntu(g++)
Thread Tools
Display
Compiling 32bit from 64bit Ubuntu(g++)
I’m running Ubuntu 8.10 64bit. I want to compile c++ programs into 32bit using g++. By default g++ choose 64bit because I’m on a 64bit OS.
Re: Compiling 32bit from 64bit Ubuntu(g++)
Add the command line switch «-m32». This will force the compiler to make a 32 bit executable.
Re: Compiling 32bit from 64bit Ubuntu(g++)
Thank you for the answer, I’ve already tried the -m32 swith but all I get in output is this:
Do I need some special library for this?
Re: Compiling 32bit from 64bit Ubuntu(g++)
I installed ibc6-dev-i386 and tried to compile again, result is:
Re: Compiling 32bit from 64bit Ubuntu(g++)
I also ran into this issue. I was able to work around it by specifying which libstdc++ to link to:
Re: Compiling 32bit from 64bit Ubuntu(g++)
I also ran into this issue. I was able to work around it by specifying which libstdc++ to link to:
Strange. All I installed is «build-essential» and «ia32-libs» and it worked. No special command line switches needed (except -m32 of course).
Re: Compiling 32bit from 64bit Ubuntu(g++)
Thanks again for the replies =) It’s kinda odd, I already have both build-essential and ia32-libs installed. I’ve tried compiling in different ways, the output’s:
g++ -m32 server.cpp -o server:
It will run just fine if I compile it to 64bit (g++ server.cpp -o server) but then the whole point is gone.
The example I compiled here is just a simple socket server. Here is the code if it has anything to do with the problem:
Last edited by Zer0d; April 14th, 2009 at 09:47 PM .
Re: Compiling 32bit from 64bit Ubuntu(g++)
Thanks again for the replies =) It’s kinda odd, I already have both build-essential and ia32-libs installed. I’ve tried compiling in different ways, the output’s:
g++ -m32 server.cpp -o server:
I just cut-n-pasted your code into «server.cpp», then ran your command line exactly:
It compiled — no errors and produced a 10K executable.
I don’t know how to test if it works though. the only part I tried was to run it in two different terminals at once. The first one runs, the second one exits with the message «Bind» as I would expect from reading the code.
Re: Compiling 32bit from 64bit Ubuntu(g++)
I just cut-n-pasted your code into «server.cpp», then ran your command line exactly:
It compiled — no errors and produced a 10K executable.
I don’t know how to test if it works though. the only part I tried was to run it in two different terminals at once. The first one runs, the second one exits with the message «Bind» as I would expect from reading the code.
What happens if you compile it this way:
g++ -m32 -L/usr/lib32/ -lstdc++ server.cpp -o server
Does that also work for you?
The program only act as a «server» and is running at port 10000. You can’t have two programs running at same port thats why you got the «bind» message Even getting «error» message «bind» shows that it compiled successful for you.
Источник
Linux from 64 bits
Linux Userspace x86_64 Emulator with a twist
Box64 lets you run x86_64 Linux programs (such as games) on non-x86_64 Linux systems, like ARM (host system needs to be 64bit little-endian).
You can find many more Box64 video on Youtube in the MicroLinux, Pi Labs or The Byteman Channels
Because Box64 uses the native versions of some «system» libraries, like libc, libm, SDL, and OpenGL, it’s easy to integrate and use with most applications, and performance can be surprisingly high in many cases. Take a look at thoses bench analysis for an example here.
Box64 integrates a DynaRec (dynamic recompiler) for the ARM64 platform, providing a speed boost between 5 to 10 times faster than only using the interpreter. Some high level information on how the Dynarec work can be found here.
Some x64 internal opcodes use parts of «Realmode X86 Emulator Library», see x64primop.c for copyright details
Logo and Icon made by @grayduck, thanks!
There are a few environment variables to control the behaviour of Box64.
See here for all environment variables and what they do.
Note: Box64’s Dynarec uses a mechanism with Memory Protection and a SegFault signal handler to handle JIT code. In simpler terms, if you want to use GDB to debug a running program that use JIT’d code (like mono/Unity3D), you will still have many «normal» segfaults triggering. It is suggested to use something like handle SIGSEGV nostop in GDB to not stop at each segfault, and maybe put a breakpoint inside my_memprotectionhandler in signals.c if you want to trap SegFaults.
Compilation instructions can be found here
The change log is available here
Notes about 32-bit platforms
Because Box64 works by directly translating function calls from x86_64 to host system, the host system (the one Box64 is running on) needs to have 64-bits libraries. Box64 doesn’t include any 64-bits 32-bits translation.
So understand that box64 will only runs 64bits linux binaries. For 32bits binaries, you need box86 (with all the multiarch or proot trickery it imply on 64bits OS). Note that many installer (mojo setup based) will fall back to «x86» when detecting ARM64 OS, and so will try to use box86 for the setup, even if an x86_64 version exist. You can hack your way around with a fake «uname» that return «x86_64» when argument is «-m»
Notes about Unity game emulation
Running Unity games is a hit or miss for now. Unity uses Mono (which uses signals that are not always emulated in a 100% accurate way). You should also note that some Unity3D games require OpenGL 3+ which can be tricky to provide on ARM SBC (single-board computers) for now. So, not all Unity games work and can require a high OpenGL profile, but many actualy works now Hint: on Pi4, use MESA_GL_VERSION_OVERRIDE=3.2 and with Panfrost use PAN_MESA_DEBUG=gl3 to use higher profile if the game start then quit before showing anything.
Notes about GTK programs
GTK libraries are not wrapped yet on box64 (contrary to box86). Many games use gtk (setup too), like Unity game for the Screen Selection dialog. While Unity game can run without that dialog (using default setup), many just can’t. For now, you’ll need o put the set of gtk x86_64 libraries in the game folder (or some other folder known by box64) to get gtk support. GTK Wrapping is planned on box64.
Notes about Steam
Not that Steam is an hybrid 32bits / 64bits. You NEED box86 to run steam, as the client app is a 32bits binaries. It also use a 64bits local server binaries, but like most stuff using libcef/chromium. it’s not working correctly on box64 for now. So: no Steam for now on box64.
Notes about Wine
Wine 64bits is supported on box64. Be aware that 64bits wine also include 32bits componant, to be able to run 32bits windws programs. The 32bits will need box86 and will not run without it. On a system where both box64 and box86 are present and working, a wine 64bits setup can run both 32bits and 64bits windows program (just use wine and wine64 respectivelly)
Notes about Vulkan
Box64 Does not wrap Vulkan libraries yet. It’s planned, but for now, vulkan program will not run on box64.
I want to thank everyone who has contributed to box64 developpement. There are many ways to contribute: code contribution, financial, hardware and advertisement! So, in no particular order, I want to thank:
- For their major code contribution: rajdakin
- For their major financial contribution: FlyingFathead, stormchaser3000
- For hardware contribution and LoongArch migration: xiaoji, Deepin Beijing Develop Team
- For their hardware contribution: Radxa, Pine64
- For their continous advertisement of box64 project: salva (microLinux), PILab/TwisterOS team, The Byteman, NicoD, ekianjo (Boilingsteam)
And I also thank the many other people who participated even once in the project.
(If you use Box64 in your project, please don’t forget to mention it!)
About
Box64 — Linux Userspace x86_64 Emulator with a twist, targeted at ARM64 Linux devices
Источник
Linux futex for 64-bits
I am on a 64-bit Linux box:
Linux illin793 2.6.32-279.5.2.el6.x86_64 #1 SMP Tue Aug 14 11:36:39 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux
int futex(int *uaddr, int op, int val, const struct timespec *timeout, int *uaddr2, int val3);
So, here futex works with 32-bits value.
Is there futex on Linux that works with 64-bits value?
2 Answers 2
There is currently no support for 64-bit futexes on Linux. There have been patches to add support circulating from as far back as 2007, but I have no idea why they haven’t been integrated.
There is no 64-bit futex support on Linux, probably because Linus Torvalds seems to be dead-set against the idea. Quoting from a 64-bit futex patch submitted by Ulrich Drepper:
It’s worth reading the other messages before and after this one, because there is some good discussion of the tradeoffs inherent in implementing a fast read-write lock with 32-bit futexes.
Linus’s idea above is that even if you need more than 32 «atomic bits» to implement your algorithm, you can probably work around the lack of 64-bit futexes by keeping your additional data outside of the 32-bit futex value. Later on he elaborates on a variant of that scheme, suggesting using two adjacent 32-bit words and ensuring that whatever state needs to be protected by any given futex call fits into one of the 32-bit halves. You can still do 64-bit atomic operations on both halves simultaneously in user space, but you just have to restrict yourself to a 32-bit subset for the actual block/wake decisions.
Источник
How to cross compile for linux x86 with linux amd64, cmake and g++?
+1 for each piece of information that helps to complete the whole picture. You don’t need to know the whole answer. I’ll appreciate individual pieces of the puzzle just as much. Thanks.
I am about to attempt my first cross-compilation. I have searched both SO and the web and found many pieces of information, but I don’t always know how to put those pieces together because there are still some missing pieces.
My host: linux Kubuntu amd64.
Target: linux kubuntu x86 (32bit) (should be easy, no?)
Tools: g++ and cmake.
Here is the information I found:
Cross-platform: selecting data types to use 32/64 bit
mentions data types. I may have to pay attention to that within my code.
#ifdef for 32-bit platform
#ifdef for 32-bit platform
links to the following, although I am not too sure yet how to use it:
http://predef.sourceforge.net/prearch.html
missing pieces:
Ideally, when I do ‘make’ (with cmake), it should spit out both a amd64 binary and a x86 one.
Part of my CMakeLists.txt looks like this:
How do I introduce the flag -m32 to create a second executable?
Should I want to make only one executable (e.g. for testing and debugging), how do I tell cmake to make either one or both binaries?
Also, you can see that I use some third party libraries, some of which I had to compile myself. Does this mean that I need to compile each of those binaries for the target host as well? Some use cmake and some use: ./configure; make;
How would I do about compiling those libraries for the target host (flags to use, etc.)?
Note: the dynamically linked libraries are already compiled and installed on the target computer, so maybe I don’t need to worry about this step. I am not sure: this is one of my missing pieces.
What I need is a kind of tutorial, or at least some of the missing pieces. I’ll update this post with more details on what I achieved and how.
Источник
How to determine whether a given Linux is 32 bit or 64 bit?
When I type uname -a , it gives the following output.
How can I know from this that the given OS is 32 or 64 bit?
This is useful when writing configure scripts, for example: what architecture am I building for?
21 Answers 21
Try uname -m . Which is short of uname —machine and it outputs:
Otherwise, not for the Linux kernel, but for the CPU, you type:
Under «flags» parameter, you will see various values: see «What do the flags in /proc/cpuinfo mean?» Among them, one is named lm : Long Mode (x86-64: amd64, also known as Intel 64, i.e. 64-bit capable)
Or using lshw (as mentioned below by Rolf of Saxony), without sudo (just for grepping the cpu width):
Note: you can have a 64-bit CPU with a 32-bit kernel installed.
(as ysdx mentions in his/her own answer, «Nowadays, a system can be multiarch so it does not make sense anyway. You might want to find the default target of the compiler»)
If you were running a 64 bit platform you would see x86_64 or something very similar in the output from uname -a
To get your specific machine hardware name run
You can also call
which returns either 32 or 64
lscpu will list out these among other information regarding your CPU:
Another useful command for easy determination is as below:
- 32, if OS is 32 bit
- 64, if OS is 64 bit
is equivalent to
but is twice as fast to type
I was wondering about this specifically for building software in Debian (the installed Debian system can be a 32-bit version with a 32 bit kernel, libraries, etc., or it can be a 64-bit version with stuff compiled for the 64-bit rather than 32-bit compatibility mode).
Debian packages themselves need to know what architecture they are for (of course) when they actually create the package with all of its metadata, including platform architecture, so there is a packaging tool that outputs it for other packaging tools and scripts to use, called dpkg-architecture. It includes both what it’s configured to build for, as well as the current host. (Normally these are the same though.) Example output on a 64-bit machine:
You can print just one of those variables or do a test against their values with command line options to dpkg-architecture.
I have no idea how dpkg-architecture deduces the architecture, but you could look at its documentation or source code (dpkg-architecture and much of the dpkg system in general are Perl).
Источник