I have an executable compiled on a 64-bit machine using Code::Blocks and GCC compiler. I also have someone on a 32-bit machine that can't run the executable. Do I need to make two separate versions of the executable, or is there a way that I can compile it to run on both 32-bit and 64-bit systems?
You could use -m32 in gcc command line to build a 32-bit version. Please make sure your code is portable from 64-bit to 32-bit.
Related
I have Centos7 and I see both 32 and 64 bit version of gdb are installed however /usr/bin/gdb is the 64bit version. How can I invoke 32bit gdb version since i need to debug application compiled with -m32 compiler option
The 64-bit GDB is perfectly capable of debugging both 64 and 32-bit programs. You don't need to invoke 32-bit GDB.
Environment and What I'm Trying to Do: I'm trying to set up a C++ coding/debugging environment with sublime text 3 on a 32 bit Windows 7 PC.
I installed Sublime Text 3 for Windows and Dev-C++(from http://orwelldevcpp.blogspot.kr/) which includes TDM-GCC 4.9.2 (32bit and 64bit).
Problem: After adding "C:\Program Files\Dev-Cpp\MinGW64\bin" to the PATH environment variable, I tried to build a simple Hello World! code, but only got this messege:
[Finished in 5.1s with exit code 1]
[shell_cmd: g++ "D:\SublimeText\main.cpp" -o "D:\SublimeText/main" && "D:\SublimeText/main"]
[dir: D:\SublimeText]
[path: (all the directories added to PATH)]
When I try to execute the main.exe file generated in D:\SublimeText, a warning that says something like 'This program is not compatible with this OS. Check your OS type if it's 32 bit or 64 bit and execute the right one'.
If I compile and run the same code in Dev-C++ after choosing the 'TDM-GCC 32bit compiler', it compiles and runs just fine.
Expected Cause: Maybe Sublime Text compiles my code with a 64bit compiler, but I couldn't find how to make it use the 32bit compiler.
I'm new to coding(registered to stack overflow an hour ago..), so a kind and detailed answer would be very appreciated! Thank You.
The TDM GCC 64 bit compiler can be installed and run on a 32-bit host
(like yours) because the compiler executables are themselves all 32-bit.
The 64-bit compiler can generate both 64- and 32-bit executables for
you, and by default will generate 64-bit ones, which will not run
on your 32-bit host. To get 32-bit executables you must explicitly tell gcc
you want them by passing it the -m32 option, for both compilation
and linkage.
I've tried to compile my source files using minGW-w64, because of new C++14 standard but when i try to compile i got this error even all things and setup is allright i guess:
Execution of 'g++.exe -c C:\Users\Denis\Desktop\isocpp.cpp -o C:\Users\Denis\Desktop\isocpp.o' in 'C:\Users\Denis\Desktop' failed.
MinGW-w64 Screenshot
My PC version is 32bit, from the official site i was notified that MinGW-w64 works for 64-32bit.
There are two distinctions to make here:
Whether gcc.exe is a 32-bit binary or a 64-bit binary
Whether that binary will generate programs that target 32-bit or 64-bit
mingw-w64 supports all four possible combinations here. But it sounds like you have downloaded a 64-bit binary. 32-bit Windows cannot run 64-bit binaries.
To fix this, use the official installer (warning:Sourceforge, although it is not hosted anywhere else so far as I know), or look out when downloading prepackaged builds.
TWO QUESTIONS HERE:
according to this in another post elsewhere --
"had to compile a 32-bit application using GNU gcc on the 64-bit version of Linux.
Luckily, gcc man page directed me to the '-m32' and '-m64' options. These options generate code for 32-bit or 64-bit environments, respectively.
The 32-bit environment sets int, long and pointer to 32 bits and generates code that runs on any i386 system.
The 64-bit environment sets int to 32 bits and long and pointer to 64 bits and generates code for AMD's x86-64 architecture."
I have this C program I modified adding features to it that I wanted and needed -- now that I have moved from a 32 bit Linux to a 64 Bit linux this program no longer works with 64 bit Linux.
before I get to ahead of myself --
Question: do I now have to re-compile it as a 64 bit program using m64 to get it to work?
when I recompiling it with the -m32 I get an error as well.
using Xlib.h
/usr/include/X11/Xlib.h:38:23: fatal error: sys/types.h: No such file or directory
I have already googled into this error -- looking at several posts and made sure I have build-essential installed, and it is.
and xlib.h are installed too.
is this looking for "sys/types.h" referencing the X11 or somewhere else?
I have no idea how to fix this problem either.
Question: do I now have to re-compile it as a 64 bit program using m64 to get it to work?
If you already have a 32-bit executable, you should be able to run it on a 64-bit Linux. Provided you have the required 32-bit system libraries installed.
when I recompiling it with the -m32 I get an error as well.
That most likely means you do not have 32-bit development packages installed.
When I run my program, which I wrote in a 64-bit Eclipse, I get a 32-bit executable. When I first opened Eclipse it asked for a kernel32.lib. Does this force Eclipse to make 32-bit applications?
Q. Is there a way to tell it to use the 64-bit kernel? Or an option to make Eclipse compile 64-bit programs?
"Bit-ness" of Eclipse has nothing to do with the executable it will produce - that depends entirely on the compiler you use or the flags passed to the compiler. You can produce 32-bit executables in 64-bit Eclipse or 64-bit executables in 32-bit Eclipse (as well as 32->32 and 64->64).
You need to tell Eclipse to compile 64-bit.
To do this go to the "Compiler/Linker" Settings Configuration page: It should be under: "GCC C Linker > Miscellaneous". Under "Linker Flags" add:
-m64