I want to try some C libraries that are only available in windows so i installed wine and install dev C++.
Unlike on windows, after i compile and run, it successfuly generate/compile into "exe" but the cmd is not showing up .
I found a way on how to run the exe by launching the terminal and putting
It works but it takes time to manually launch the "exe".
How can i make dev c++ to automatically find cmd in wine and execute the compiled code?
Thank you in advance.
UPDATE :
The time I posted this question, I'm new to Linux/Ubuntu that's why I'm looking/expecting for that functionality in wine. But now after 2 years amany months i figured out that codeblock running on wine which is for windows and cannot call ubuntu terminal once compiled.
Dev-C++, by default, relies on a simple file called ConsolePauser.exe
. This file calls the compiled .exe
file, and gives the familiar Process exited after 0.xxxxx seconds with return value x.
notice after it exits.
However, ConsolePauser.exe
is a native Windows binary, it cannot be executed in Ubuntu, unless called by Wine. Also, the ConsolePauser
calls the bare name of the executable, instead of a call to Wine, which is required.
Therefore, what you need to do to make Dev-C++ to run .exe
files automatically after you press F9
is to build your OWN ConsolePauser. This is quite simple, actually:
#include <chrono>
#include <iostream>
#include <string>
int main(int agrc, char ** argv)
{
using namespace std;
string s = argv[1];
string s1;
for (const auto & ss : s)
{
if ((ss == ' ') || (ss == '\\')) s1.push_back('\\');
s1.push_back(ss);
}
s = "wine " + s1;
auto begin = chrono::high_resolution_clock::now();
auto retVal = system(s.c_str());
auto end = chrono::high_resolution_clock::now();
cout << "-------------------------------------" << endl;
cout << "Process completed after " << chrono::duration_cast<chrono::milliseconds>(end - begin).count();
cout << " milliseconds with return value " << retVal << "." << endl;
cout << "Press any key to continue. . ." << endl;
cin.get();
return 0;
}
What it simply does is parsing the argument, escaping required characters, and pass it to Wine. It is a quick and dirty version, you start improving it by checking if argc == 1
.
Compile it as ConsolePauser.exe
with Ubuntu's compiler, put it anywhere in your computer's PATH
and it should work.
Another problem exists, however. For unknown reasons, Ubuntu's executables don't get executed in a separate window, if called by an app like Dev-C++, unlike Windows. Therefore, you will have to find a way to bring the ConsolePauser.exe
to a new window.
A simple approach is rename your file to ConsolePauser1.exe
, and use this code for ConsolePauser.exe
:
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char ** argv)
{
string s = argv[1];
//Opens new window through gnome-terminal:
string command = "gnome-terminal -e ";
command += string("\"") + "bash -c ";
command += string("\\\"") + "ConsolePauser1.exe ";
command += string("\\\\\\\"") + s;
command += string("\\\\\\\"");
command += string("\\\"");
command += string("\"");
system(command.c_str());
cerr << command << endl;
//Make sure that window lingers...
system("exec bash");
return 0;
}
Put these two files in the same folder in your PATH
, and the familiar old Console Pauser will work like a charm.