running exe in Linux - c++

I have built a simple console application in c++ vs2010 that just displays one line of text. Is it possible to run this executable from the Release folder in Linux?
Say I put the Release folder on a thumb drive, open it on a linux machine?
I was under the impression that console application written in c++ could run in both windows in linux? how mislead am I?

a) You need to run the executable with wine and emulate a windows environment
- OR -
b) You need to compile your code for your Linux distribution.

Related

Windows executable got executed on my linux

I wrote a simple code and compiled using g++ in linux in .exe format, suprisingly it got executed in my linux terminal. Can u say the reason for this ? Can linux terminal execute machine code in any format ? Can I run the same in windows ?
Code :
#include<iostream>
using namespace std;
int main(){
cout<<"Hello World !"<<endl;
return 0;
}
Compile code:
g++ main.cpp -o program.exe
OS: Linux Mint 20 Cinnamon.
I execute by typing ./program.exe
Q: I wrote a simple code and compiled using g++ in linux in .exe format, suprisingly it got executed in my linux terminal
A: There's nothing "surprising". I assume you compiled it under Linux? So why shouldn't you be able to run it under Unix?
Q: Will an .exe I build on Windows run on Linux (if I copied the binary)? A: Short answer: No.
Longer answer: you can install Wine to run Windows applications on Linux.
Q: Will an .exe I build on Ubuntu run on Windows? A: No.
Q: Does an executable I build on Ubuntu need to have the suffix .exe? A: No. File suffixes are irrelevant.
Q: Does an executable I build on Windows need to have the suffix .exe? A: Yes.
To answer your additional questions:
There are many reasons why an .exe built for one platform cannot load or run on a different platform.
Sam Varshavchik put it well:
It's for the same reason a radiator for your Toyota won't fit into a
Dodge
More to the point, an "executable image" is much more than just "the machine code".
An .exe is an example of "executable images". They come in many different formats: https://en.wikipedia.org/wiki/Category:Executable_file_formats. Most of these formats are platform-specific.
Any image must be loaded by the operating system in order to become a running process. This, too, is platform-specific.
The running process will need resources like file I/O , memory and shared libraries, which are also platform-specific.
I hope that helps...
Since you compiled the code using g++ on Linux, you should be able to run it on Linux but it won't work on Windows because the binary executable is compiled for Linux.
On Windows, .exe is the extension of the executable file but the binary code must be compiled for Windows so that it can run. On Linux, you can use any extension, .mp4 or anything and it will still run when typing ./program.mp4 in terminal.

Run Mac application of C++ and Qt on another Mac

I am trying run a simple C++ with QT application on another mac. I am trying to avoid having to install Qt on the other mac. This application was created in Xcode with cmake.
Two notes: my application (for some reason) does not create an .app file. It just creates a file with the name of my project (and no extension). I can run this file by double clicking, but still, it is not an .app. Does this matter?
Another thing, I am linking my application to static libraries of Qt. From what I understand, this should allow to run the application even if Qt is not installed, right? The result of running my application on the other mac is simply a terminal window that says: Instruction unknown.

How to migrate Borland C++ 5.02 application to Windows 7?

Currently we are migrating our applications developed in Borland C++ 5.02 on Windows XP to Windows 7. While executing the application on Windows 7, I am getting the error message
VBX library init Failure.
While trying to find the cause on the Internet, I was able to identify the error was because of BIVBX31N.EXE and BIVBX31N.dll.
How can I port a Borland C++ 5.02 application to Windows 7, solving the BIVBX31N.EXE and BIVBX31N.dll related issues?
If you're stuck using this product, here is what I recommend.
Simple answer: Don't use the IDE, but continue to use the command line tools:
bcc32.exe (the compiler) still works fine in Windows 8.
ilink32.exe (the linker) still works fine as well.
Both can be found in the bin sub-folder.
You can get some of the command line information by opening the IDE (project) file in Notepad or a hex editor (it isn't a text file, but you can read most stuff in Notepad). Or if you do have access to Windows XP you can open it there just to copy the settings for usage in the command-line tools.
Just use some other IDE or editor like Notepad++ to edit your source files. You can use an older version of Visual C++ to edit the RC files, or Notepad or other tools.
If you want really want to make it slick, set up your IDE to run an "external tool" when you click a toolbar button, to have it run your command-line tools to compile + link (and optionally run the EXE file). You can probably find a debugger tool as well, but I haven't needed that yet, so haven't checked.
My best recommendation is to start the process of porting your code to Visual Studio.
You can use a library like OWLNext if you've used the OWL library in Borland.
The other alternative is is to use Windows Virtual PC (or other such virtual machine) to run Borland in an integrated Windows XP mode. See an example here.
This can be probable answer ???
You have to download configured Borland Compiler from http://www.4shared.com/get/Gs41_5yA/borland_for_graphics.html or http://dwij.co.in/graphics-c-programming-for-windows-7-borland-compiler/.
Put your Borland’s ‘bin’ folder into Environmental Variables.
Now go inside folder ‘bin’ & edit file bcc32.cfg as per your folder structure. This file contains settings of headers & libraries.
-I"D:\Borland\include;"
-L"D:\Borland\lib;D:\Borland\Lib\PSDK"
Now create any C/C++ Program say myprogram.cpp
Use following command to compile this bunch of code:
F:\>bcc32 myprogram.cpp
Congratulations !!!.

How to run console with a c++ application

I need to run a console when the app starts (for debug, log, etc) without a .bat file.
I use the LCC compiler on Windows 7 x86.
Look at the console APIs in Windows, start with AllocConsole.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682010%28v=vs.85%29.aspx

Problems out of my machine: how to debug outside a dev environment?

I'm developing an application in 3D in a win 7 64bits machine, in visual C++ 2008. All runs correctly. When I check this application in a clean machine in a VMWare virtual machine with XP 32bits (hardware 3D activated) or in a machine of a friend of mine, the application fails.
The behavior of the application is different (into the clean machine) depending of the compilation (debug or release) and if I compile with MD(d) or MT(d)
My question: it is possible to debug the application into the clean machine? Exists a central log like /var/log/message but in windows? How to check what dll are in use in my dev machine, in order to compare with the installed in the clean machine?
Thanks!!
If its on the same network you can you the remote debugger ! But you may first want to check if its not a 64bit app on a 32bit OS.
Make sure the bitness is correct and that the correct VC++ distributable is installed on the test machines.
If that doesn't help, then try this for fast debugging:
Grab the debugging toolkit from MS (http://www.microsoft.com/whdc/devtools/debugging/default.mspx)
Install it on your development machine.
Copy the installation folder to the machine you want to debug on.
Copy / Install your program to the machine, remember the *.PDB files.
Start WinDBG from the debugger folder and use the 'File->Open executable' command to start your app. WinDGB will break fast and you can debug from there.
If you want break points and such, look up the commands in the WinDBG help files.
You could try running your app under dependency walker (www.dependencywalker.com). If the problem is missing or incorrect dlls, dependency walker will show it up very quickly.
On XP you can use the built-in debugger, ntsd.exe. it's basically like windbg lite and requires no additional install.