I have NVIM v0.4.3
on macOS Mojave version 10.14.6
I have different version of g++
compilers on my machine and made the following alias in my .zshrc
file:
alias g++="/usr/local/bin/g++-9"
alias g++Old="/usr/bin/g++"
I want to compile and run the following script on my Mac that I named count6.cpp
:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> vec;
vec.push_back(11);
vec.push_back(1);
vec.push_back(8); // vec{4, 1 8}
for(auto elem: vec)
cout << elem << " ";
return 0;
}
If I run the command the
g++ count6.cpp -o count6; ./count6
I get the following output:
11 1 8 %
However if I type the same command from within nvim, I get the following warnings:
:!g++ count6.cpp -o count6; ./count6
count6.cpp:12:9: warning: 'auto' type specifier is a C++11 extension [-Wc++11-ex
tensions]
for(auto elem: vec)
^
count6.cpp:12:18: warning: range-based for loop is a C++11 extension [-Wc++11-ex
tensions]
for(auto elem: vec)
^
2 warnings generated.
11 1 8
Ny interpretation is that the command from within nvim does not point to the same binary. How can I make point to the same binary?
:!
(which wouldnt surprise me). Try:!type g++
. Also make sure it isn’t a PATH issue. Lastly, use a makefile or other buildsystem that you can invoke with:make
—then the problem disappears. – D. Ben Knoble♦ Jun 20 '20 at 17:35:!type g++
gives indeedg++ is /usr/bin/g++
. Do you have other hint for implementing your 2 other advices? – ecjb Jun 20 '20 at 17:41g++-9
. If you were using the native quickfix feature through:make
(which appeared in the late 90's) instead of the old Vi (!= vim):!compilername
trick, you should be able to just set:let $CXX = 'g++-9'
-- I expect your flavour ofmake
is correctly configured with all the usual implicit rules. – Luc Hermitte Jun 20 '20 at 20:54