Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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
$wine cmd
$myc.exe
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.
I'd like to submit my approach, although it is not specific to Ubuntu. It can work with any distro with xterm installed.
Rename ConsolePauser.exe
to ConsolePauserEngine.exe
and create a new ConsolePauser.exe
text file in the same dir with the following lines:
#! /bin/sh
CMD=$(printf "%q" $@) #https://stackoverflow.com/questions/2854655/command-to-escape-a-string-in-bash#answer-2856010
CONSOLE_PAUSER_PATH=$(printf "%q" "C:\Program Files (x86)\Dev-Cpp\ConsolePauserEngine.exe")
xterm -e "wine $CONSOLE_PAUSER_PATH $CMD"
EDIT: Don't forget to make the new ConsolePauser.exe
executable.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.