Reputation: 1
I am a newish programmer trying to figure out how to compile two separate .cpp
files and .h
file. From my google search so far, I have found that I need to enter something like:
gcc -o myprogram file1.cpp file2.cpp
Can someone expand on this?
Upvotes: 0
Views: 602
Reputation: 38267
For a temporary session (or in a possibly local .vimrc
file), you can specify the builtin makeprg
variable (see also :help makeprg
)
set makeprg=g++\ -o\ myprogram\ file1.cpp\ file2.cpp
and invoke the compilation via :make
. This will open up the quickfix window if you had any compilation errors or warnings, which can be handy.
Note, however, that this is nothing but a temporary hack for quick trial-and-error cycles. When these two files are meant to be something more serious, choose a build system and configure it accordingly. Then, adjust the makeprg
variable again to invoke e.g. make
(which is the default anyway), ninja
, scons
(in case you hate yourself) or whatever tool you chose.
Upvotes: 3