I need help compiling my program on vim. What would I use in my command line to
ID: 3843700 • Letter: I
Question
I need help compiling my program on vim. What would I use in my command line to get the program to run properly with these filenames. My program compiles with code::blocks so I don’t think the errors are within the programs.
Barbarian.cpp Barbarian.hpp
BlueMen.cpp BlueMen.hpp
Creature.cpp Creature.hpp
Die.cpp Die.hpp
HarryPotter.cpp HarryPotter.hpp
mainGame.cpp mainGame.hpp
Medusa.cpp Medusa.hpp
Vampire.cpp Vampire.hpp
Makefile
Thank you
//-------------------------------------------------------
Unless it's the Makefile
all: battle
battle: mainGame.o Medusa.o Barbarian.o Vampire.o BlueMen.o Die.o HarryPotter.o Creature.o
g++ mainGame.o Medusa.o Barbarian.o Vampire.o BlueMen.o Die.o HarryPotter.o Creature.o -o battle
mainGame.o: mainGame.cpp
g++ -c mainGame.cpp
Medusa.o: Medusa.cpp
g++ -c Medusa.cpp
Barbarian.o: Barbarian.cpp
g++ -c Barbarian.cpp
Vampire.o: Vampire.cpp
g++ -c Vampire.cpp
BlueMen.o: BlueMen.cpp
g++ -c BlueMen.cpp
Die.o: Die.cpp
g++ -c Die.cpp
HarryPotter.o: HarryPotter.cpp
g++ -c HarryPotter.cpp
Creature.o: Creature.cpp
g++ -c Creature.cpp
clean:
rm .o battle
Explanation / Answer
Considering we are using vim, and not vi, :make is the way to go.
On Linux-like (it also applies to cygwin, but not to mingw on windows -- in mingw case, see the other answers that alter &makeprg, leave it alone otherwise) systems where gnumake is installed, if you don't have a Makefile in your project, and if your project is made of only one file, just type :make %<. It will be enough (you can play with $CXXFLAGS, $CFLAGS and $LDFLAGS to tune the compilation options). Then to run the program, type :!./%< (IIRC).
If your project is made of several files, then you'll need a Makefile to take advantage of :make.
If you manage your project with CMake, and if you compile your project in a directory (or several -> debug, release, ...) outside the sources tree, then the integration will require a plugin. AFAIK, I'm the only one to propose such a plugin: BuildToolsWrapper integrates the management of CMake (choice of the build directory, possibility to chose between the debug, or release, or whatever build directory). It has to be coupled with one of the local_vimrc plugin.
In all cases, calling directly the compiler from within (or outside) Vim with :!g++ -o %< % or whatever is what we used to do 15 years ago on vi. Vim has a wonderful feature: it can integrate (yes, like in IDE) the compiler. See :h quickfix. Navigating between errors directly from the editor is much easier than extracting one error line with our eyes, typing back the line number into the editor, going back to the shell to see what exactly was rejected, ... It may be enough in C, but In C++ when we are "trying to call an overload that doesn't exist", we can't work this way (switching back and forth between the editor and the shell).
Finally, if you want to compile on a single keystroke those mono-file projects, you can add in your .vimrc:
If you want to adapt automatically the compilation command depending of the kind of project mono-file pet project, or real world multi-file project, well, more wiring is needed, and this is what BTW does
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.