Referring to the structure below, suppose that I am in /test
directory and I opened vim main.cpp
. Running :make
would invoke /test/Makefile
. Now I do :edit ../src/foo.cpp
and made changes here, too. I want to run make
on /Makefile
to create a shared library in /lib
. How can I run make
on /Makefile
without exiting Vim?
project
| Makefile
|+ lib
|+ include
|- src
| foo.cpp
|- test
| main.cpp
| Makefile
In a Makefile, each line is run in a different shell. If you want to run something in a different directory, you need to cd /dir && something .
Yes because variable and function expansion are done before executing the commands by make, whereas pwd and `pwd` is executed by the shell itself.
Including Header file from Different Directories This can be done using -I option in makefile. Assuming that functions. h file is available in /home/tutorialspoint/header folder and rest of the files are available in /home/tutorialspoint/src/ folder, then the make file would be written as follows.
some projects put their makefile in src/ subdirectory of the root directories of the projects, some projects put their makefiles in the root directory of the project.
Just run:
:make -C path_to_dir_with_your_makefile
Where -C
:
-C dir, --directory=dir
Change to directory dir before reading the makefiles or doing anything else. If multiple -C options are specified, each is interpreted relative to the previous one: -C / -C etc is
equivalent to -C /etc. This is typically used with recursive invocations of make.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With