Create Desktop Icon to Execute C++ Code

Hi,

I have tried various ways to start C++ & Unix (Mint)and struggled. I have programmed Expert Advisors for MetaTrader (A forex platform) which looks very similar to C++.

I have created your Hello Word program in the Dev-C++ environment and all works but I have to use the Dev-C++ and subsequently runs in the terminal.

How could I create a Desktop ICON to run the compiled code. Maybe eventually generates "My C++ Programs" from which I can select which to run?

Thanks in hope and anticipation
I have created your Hello Word program in the Dev-C++ environment and all works but I have to use the Dev-C++ and subsequently runs in the terminal.

You can use that IDE in order to develop and build the program. But when you've completed that, the result is an executable program (a .exe file) which you can run by clicking on that file. You could also drag the .exe to create a shortcut on the desktop.

One minor problem you may encounter with console programs run in this way is that the program would end and the console window close immediately. There are various solutions, such as adding a cin.get() before the the end of main, or creating a .bat file to run the program for you.
To get your executable to show it's own unique icon you have to embed the image in the binary itself. Use a resource file and it's accompanying "compiler" (rc.exe) in Windows: https://msdn.microsoft.com/en-us/library/windows/desktop/aa381055(v=vs.85).aspx and 'objcopy' from the GCC toolkit for *nix based systems: http://www.linuxjournal.com/content/embedding-file-executable-aka-hello-world-version-5967 .
So, I have a quick option on windows, open your file browser and find your executable, right click the .exe and select 'Create Shortcut', then move the shortcut to your desktop.

For 'Nix systems, open up a console/terminal and use the ln command to create a link. Or figure out the syntax for a Desktop Shortcut for whatever window manager or desktop environment you are using...

If you are wanting to distribute your file to other computers, then look up how to find your dynamic linked libraries (dll's on Windows) or how to statically link your libraries. I personally have only done dll's on a Windows system, but that's the preferred way if you are writing in Qt since it doesn't violate their free-use-license.
Last edited on
Many thanks everyone - plenty to keep me out of mischief!

I have VB EXcel programs for analysing bank accounts etc and would like eventually to be platform independent i.e. C++ on W10 or Linux

This could be the start
Chervil,

Thanks - your solution worked but as you stated immediately exits terminal.

I included:- the line you suggested
1
2
3
4
{
  std::cout << "Hello World!";
  cin.get();						// prevents exit from terminal when running from executable file
}

but got the following failure

7 3 F:\MyFiles\C++\main3.cpp [Error] 'cin' was not declared in this scope

Presumably I need to include a reference to some libraries or similar
In that example, it should be
 
std::cin.get();	
Gotcha - works fine.
Topic archived. No new replies allowed.