Search code examples
vimclangclang-complete

clang_complete - cc_args.py won't generate .clang_complete file


I have setup a simple project to test viability of VIM as C++ complier plus a simple makefile from a tutorial, but I can't seem to generate .clang_complete file from cc_args.py script.

Readme says I should run:

make CC='~/.vim/bin/cc_args.py gcc' CXX='~/.vim/bin/cc_args.py g++' -B

But it won't generate .clang_complete file from makefile.

Here is my simple project.

//hello.cpp
#include "hello.h"

int main(void)
{
    hello();
    return 0;
}

//hello_fn.cpp
#include <iostream>
#include "hello.h"

void hello()
{
    std::cout << "Hello world!";
}

//hello.h
#ifndef HELLO_H
#define HELLO_H
void hello();
#endif

Makefile:

CC=g++
CFLAGS=-Ihead
DEPS = hello.h
OBJ = hello.cpp hello_fn.cpp

%.o: %.cpp $(DEPS)
    $(CC) -c -o $@ $< $(CFLAGS)

hello: $(OBJ)
    g++ -o $@ $^ $(CFLAGS)

hello.h is in directory called head.

Running:

make CC='.vim/bundle/clang_complete/bin/cc_args.py gcc' CXX='.vim/bundle/clang_complete/bin/cc_args.py g++' -B

or:

make CXX='.vim/bundle/clang_complete/bin/cc_args.py g++' -B

yields no .clang_complete file.


Solution

  • Your Makefile ignores the CC and CXX environmental variables and just uses g++ directly. Change the hello rule to

    hello: $(OBJ)
        $(CXX) -o $@ $^ $(CFLAGS)
    

    And then make CXX='.vim/bundle/clang_complete/bin/cc_args.py g++' -B should work.

    The %.o: %.cpp $(DEPS) rule does use CC, but this rule is never used since your OBJS variable are all .cpp and not .o variables.