Coder Social home page Coder Social logo

Comments (11)

penguin1214 avatar penguin1214 commented on July 29, 2024

I put the .ycm_extra_conf.py under my ~ directory and I loaded the file successfully.
However, it seems that ycm is not working properly.
I tried :CCGenerateConfig again but still the error.

from ycm-generator.

rdnetto avatar rdnetto commented on July 29, 2024

What are the contents of your working directory when running config_gen.py? Also, what build system does the project you are trying to generate the file for use?

(You can view the current working directory with :pwd)

from ycm-generator.

penguin1214 avatar penguin1214 commented on July 29, 2024

Just to test whether YCM is working, I create a test.c file under my home directory.
When run :pwd in MacVim I got

/Users/yangyy

(yangyy is my home directory)

Also, I tried to open my Xcode project in MacVim, the path of which is ~/git/myproject/myproject/main.c.
However, when I run :pwd in MacVim I got the same message

/Users/yangyy

Actually I put the example .ycm_extra_conf.py under my home directory and add let g:ycm_global_ycm_extra_conf = '~/.ycm_global_ycm_extra_conf.py' to my.vimrc` file but it didn't work.

from ycm-generator.

rdnetto avatar rdnetto commented on July 29, 2024

test.c by itself is not enough - you need a build system like make. The working directory also needs to be set to the root of the project (where Makefile, etc. live) using :cd.

You might find it easier to get it working from the terminal (using ~/.vim/bundle/YCM-Generator/config_gen.py to invoke it, or whatever the appropriate path for your Vim plugin manager is), since changing the wording directory (cd) is more natural there.

from ycm-generator.

penguin1214 avatar penguin1214 commented on July 29, 2024

I have make and cmake installed on my mac. Does that mean I have a build system already?
What should I do with them?

In README.md

Run ./config_gen.py PROJECT_DIRECTORY, where PROJECT_DIRECTORY is the root directory of your project's build system (i.e. the one containing the root Makefile, etc.)

Yes, the config_gen.py is under ~/.vim/bundle/YCM-Generator/config_gen.py. But I'm not quite understand the one containing the root Makefile here.

Does it mean I should have a makefile under the project's root directory?
If I invoke the config_gen.py under ~/.vim/bundle/YCM-Generator/config_gen.py, why

./config_gen.py ~

not working?

from ycm-generator.

rdnetto avatar rdnetto commented on July 29, 2024

When I say build system, I mean the project's build system. That is, you should be able to compile your project by typing make (if using makefiles).
Take a look at #29 for an example of how to do this, if you've never written one before.

The reason that invoking it against your home directory (~) doesn't work is because you don't have a makefile.

YCM-Gen relies on makefiles (or another build system) to tell it how the program will be compiled, so it can pass that information to YCM.

from ycm-generator.

penguin1214 avatar penguin1214 commented on July 29, 2024

Thank god YCM-Generator is working well now. However YCM is still not auto-completing for me.
This is the message generated after I run ./config_gen.py ~

./config_gen.py ~
Preparing build directory...
$ make clean

Running make...
$ make -i -j4
Build completed in 0.03 sec

Collected 2 relevant entries for C compilation (0 discarded).
Collected 0 relevant entries for C++ compilation (0 discarded).
Created YCM config file with 3 C flags

It seems there's something wrong because I think there's should be more relevant entries?

from ycm-generator.

rdnetto avatar rdnetto commented on July 29, 2024

If it's compiling with clang, then that should be sufficient. What does your Makefile look like?

from ycm-generator.

penguin1214 avatar penguin1214 commented on July 29, 2024

I did a little modification to your example in issue #29 :

CFLAGS=-g -std=gnu99 -Wall -Wno-parentheses

all: main.o
    $(CC) $(CFLAGS) $^ -o simulate_wsn

clean:
    rm -rf *.o simulate_wsn

Run :make in main.c under ~ got

:!make  2>&1| tee /var/folders/y4/nggqfd294sz15b1h__7vj3r00000gp/T/vx1c7tk/0
cc -g -std=gnu99 -Wall -Wno-parentheses   -c -o main.o main.c
cc -g -std=gnu99 -Wall -Wno-parentheses main.o -o simulate_wsn
(1 of 2): cc -g -std=gnu99 -Wall -Wno-parentheses   -c -o main.o main.c

main.c

#include <stdio.h>

int main(){
    printf("hello,world!");
    return 0;
}

The situation is, YCM can complete library names like ctime.h when I'm trying to include header files, but it can't complete function names like scanf.

I feel that there may be something wrong with my libclang because I firstly build the YCM using

./install.sh --clang-completer

and no error generated. As the YCM doesn't work I then built it again using

./install.sh --clang-completer --system-libclang

I got the traceback

Linking CXX shared library /Users/yangyy/.vim/bundle/YouCompleteMe/third_party/ycmd/ycm_core.so
Undefined symbols for architecture x86_64:
  "_clang_parseTranslationUnit2FullArgv", referenced from:
      YouCompleteMe::TranslationUnit::TranslationUnit(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::vector<UnsavedFile, std::__1::allocator<UnsavedFile> > const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, void*) in TranslationUnit.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [/Users/yangyy/.vim/bundle/YouCompleteMe/third_party/ycmd/ycm_core.so] Error 1
make[2]: *** [ycm/CMakeFiles/ycm_core.dir/all] Error 2
make[1]: *** [ycm/CMakeFiles/ycm_core.dir/rule] Error 2
make: *** [ycm_core] Error 2
Traceback (most recent call last):
  File "/Users/yangyy/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py", line 445, in <module>
    Main()
  File "/Users/yangyy/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py", line 434, in Main
    BuildYcmdLib( args )
  File "/Users/yangyy/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py", line 342, in BuildYcmdLib
    subprocess.check_call( build_command )
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 540, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'ycm_core', '--', '-j', '4']' returned non-zero exit status 2
Traceback (most recent call last):
  File "./install.py", line 32, in <module>
    Main()
  File "./install.py", line 21, in Main
    subprocess.check_call( [ python_binary, build_file ] + sys.argv[1:] )
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 540, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python', '/Users/yangyy/.vim/bundle/YouCompleteMe/third_party/ycmd/build.py', '--clang-completer', '--system-libclang']' returned non-zero exit status 1

Is that the possible reason why YCM is not working correctly?

from ycm-generator.

rdnetto avatar rdnetto commented on July 29, 2024

ctime.h is a C++ header - the C equivalent is time.h. I just tested the files you're using and pressing Ctrl+X O should trigger autocompletion (or print an error if something isn't working).

If you want to write a Makefile for a C++ program, you should use CXXFLAGS and main.cpp instead. (On a related note, simulate_wsn is just the name of the executable to be produced - you can change that to whatever you want.)

From the YCM Readme:

You can use the system libclang only if you are sure it is version 3.8 or higher, otherwise don't. Even if it is, we recommend using the official binaries from llvm.org if at all possible. Make sure you download the correct archive file for your OS.

We STRONGLY recommend AGAINST use of the system libclang instead of the upstream compiled binaries. Random things may break. Save yourself the hassle and use the upstream pre-built libclang.

(To be fair, I use system libclang on my own PC, but I run Linux, and I have a lot more confidence in my distro's maintainers to keep it up-to-date and vanilla than Apple.)

from ycm-generator.

penguin1214 avatar penguin1214 commented on July 29, 2024

Well, I've tested both C and C++ files. I think the YCM-Generator is working well. I don't know why the YCM is not working( I've build the YCM not using the libclang and everything worked fine).
Anyway, my problem about YCM_Generator is perfectly solved. Really appreciate of your suggestions.
Please close the issue. :)

from ycm-generator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.