Need to understand

Jun 6, 2013 at 5:19am
I have been working through a C++ course and am making slow progress. I enrolled for a course and to my surprise found it to be Active C which is for apple Mac. Whilst doing the first lesson I found very few differences so will continue with the course.

I need to try and understand the programing in C++ is really interesting and I can see that I should be able to achieve my ultimate goal.

What I would like to understand is when you have written the program is there a way to run it in windows. what I am trying to say is lets assume I write a program that does graphs in C++ and I want to save it and give it to my friends to run it on their computers running windows. is this going to be possible and what is the process to do this.

I am a long way off from this but need to know what the procedure is to achieve the end result so that I can understand the process I am working towards

Many thanks

Rodney

Jun 6, 2013 at 5:28am
> I write a program that does graphs in C++ and I want to save it and give it to my friends
> to run it on their computers running windows.
> is this going to be possible and what is the process to do this.

Write the C++ program, compile and link it to produce an executable file (typically a file with a .exe extension on Windows). If you have used third party graphics libraries in your program, link to them statically. You can then give the executable file to someone, and they would be able to run it as it is on their Windows machines.
Jun 6, 2013 at 5:38am
Thank you very much for the help. The Graphics are a long time off I fear I am still at the hello world and what is your name stage.

What do I need to use to do to produce an executable file.

I know there is no need to get a simple program to say hello world to run on anyone's computer but if possible it will help as I go along with the small projects eventually to achieve the ultimate goal.

So I think what I am asking is what do I need to do to change my c++ program to an executable file.

And is it possible to run small programs like this in Windows

Jun 6, 2013 at 5:44am
> What do I need to use to do to produce an executable file

The precise steps depend on the tool chain (compiler, linker etc) that are being used.

Are you compiling from the command line? If so, which compiler are you using?

Or are you using an IDE (Visual Studio, CodeBlocks etc.) to do the job for you? If so, which one?
Jun 6, 2013 at 5:59am
All Questions I cant answer (Sorry very embarrassed)

I write the simple code in gvim 7.3

Save it with the name.c

then compile it gcc name.c -o name

then to run it type name and the little routine returns in this javascript:editbox1.editSend()case "Hello World" do you need to see the source code?


#include <stdio.h>
int main()
{
printf("Hello world!\n");
return(0);
}
Last edited on Jun 6, 2013 at 6:02am
Jun 6, 2013 at 6:09am
> then compile it gcc name.c -o name

The name that follows the -o is the name of the executable file.

What is the output that you get when you run
> gcc -dumpmachine ?

Jun 6, 2013 at 6:48am
mingw32
Jun 6, 2013 at 6:57am
Ok. If you compile with
> gcc name.c -o name.exe

A copy of name.exe can be run on any Windows machine.
Jun 6, 2013 at 7:05am
Thank you very much. I will try this later and report back the results


Just tried it, it only runs in the cmd prompt

I wonder if I have confused what I want to find out. Where in windows would I run the name.exe program
Last edited on Jun 6, 2013 at 7:10am
Jun 6, 2013 at 7:21am
Try this (make the program wait for a new line to be entered instead of quitting in a flash):
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>

int main()
{
    printf("Hello world!\n");

    // make the program wait for a new line to be entered
    puts( "press ENTER to quit" ) ;
    int c = 0 ;
    while( c != '\n'  && c != EOF ) c = getchar() ;

    return(0);
}
Jun 6, 2013 at 3:07pm
That works perfectly thank you. Now the million dollar question. How do I convert it to a windows program save it on a flash drive and run it on another PC not in the cmd environment


Many thanks
Jun 6, 2013 at 3:49pm
Copy the executable - in the above example name.exe - to the flash drive. And then you can run it directly from the flash drive on other windows machines.
Jun 6, 2013 at 4:39pm
I would like to really thank you for your help.

Best wishes

Rodney
Topic archived. No new replies allowed.