Need help with running a program.

I have to run a program that has a total of three files.

1
2
3
4
5
6
//A header file.
Student.h
//A cpp file.
Student.cpp
//A main file.
main.cpp


My professor did mention to use #pragma once in the header file, but how would you run the program through the terminal with these three files?
Last edited on
You need to compile them into an executable…
Is this the first time you deal with a program split into more than one file?
Don't you use an IDE (Visual Studio, Code::Blocks…)?
It is actually,
I use virtual box.
Assuming you're compiling from the terminal with g++:


$  g++ -std=c++11 -Wall -Wextra -c Student.cpp
$  g++ -std=c++11 -Wall -Wextra -c main.cpp
$  g++ -std=c++11 -Wall -Wextra -o myprogram Student.o main.o

That's the general process. Each cpp file compiles to an object (.o) file and those are then "linked" together into the executable (the last command). But you can actually compile it in one command like this:


$  g++ -std=c++11 -Wall -Wextra -o myprogram main.cpp Student.cpp


The first way allows you to compile separate cpp files which is useful when you have a bunch of them, but the process is usually controlled by a makefile (or cmake or an ide, etc.).
Last edited on
Topic archived. No new replies allowed.