There are two ways to do this. While both work, one is "cleaner" than the other. Side note: As trojanfoe pointed out, you may have left off the .o
on the compile/link command.
Here's a two step process:
cc -c main.c
c++ -o mypgm example.cpp main.o
This is a bit ugly because the usual convention is that the source that gets compiled is the one with main
Here's the more usual way:
c++ -c example.cpp
cc -c main.c
c++ -o mypgm main.o example.o
NOTE: In both cases, the "linker" must be c++
to resolve the std::*
that example.cpp
uses
UPDATE:
What is mypgm
?
mypgm
[just an example name] is the name of the [fully linked and ready to run] output executable or program. It's the argument for the -o
option. The linker takes your relocatable input .o
files, links them together to produce the output file [that can now be run as a command].
It's pretty standard nomenclature for something that is arbitrary in example instruction or code sequences [like here on SO]. You could replace "mypgm" with "ursa_majors_test_program" or "example", or whatever you'd like. To run the program, then type ./mypgm
[or ./ursa_majors_test_program
or ./example
]
There's no magic to the name, just like there was no magic to you naming your source files main.c
and example.cpp
It should be descriptive of function. If you had said you were working on a text editing program, in my example, I might have used -o editor