rdnetto / YCM-Generator

Generates config files for YouCompleteMe (https://github.com/Valloric/YouCompleteMe)
GNU General Public License v3.0
917 stars 129 forks source link

Building second target fails if depending on first target (CMake) #89

Closed 0x47 closed 7 years ago

0x47 commented 7 years ago

It seems YCM-Generator does something in-between building two targets in my CMakeLists.txt. The first target is a library which builds okay and the second target is a unit test that depends on the library (for testing it). IIRC all targets created in one project (that should even include sub-projects via add_directory()) in CMake know all other targets and can link against them automatically.

$ ycm_generator -v -F ycm -x c .
'/home/user/workspace/mylib/.ycm_extra_conf.py' already exists. Overwrite? [y/N] y
 Running cmake in '/tmp/tmpwU74Ur'...
$ cmake /home/user/workspace/mylib
-- The C compiler identification is Clang 3.8.1
-- The CXX compiler identification is Clang 3.8.1
-- Check for working C compiler: /usr/share/YCM-Generator/fake-toolchain/Unix/clang
-- Check for working C compiler: /usr/share/YCM-Generator/fake-toolchain/Unix/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/share/YCM-Generator/fake-toolchain/Unix/clang++
-- Check for working CXX compiler: /usr/share/YCM-Generator/fake-toolchain/Unix/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Could NOT find Doxygen (missing:  DOXYGEN_EXECUTABLE) 
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/tmpwU74Ur

Running make...
$ make -i -j8
Scanning dependencies of target mylib
[ 20%] Building C object CMakeFiles/mylib.dir/src/mylib/request.c.o
[ 40%] Building C object CMakeFiles/mylib.dir/src/mylib/mongoose.c.o
[ 60%] Linking C shared library libmylib.so
[ 60%] Built target mylib
Scanning dependencies of target check_request
make[2]: *** No rule to make target 'libmylib.so.0.0.1', needed by 'check_request'.  Stop.
make[2]: *** Waiting for unfinished jobs....
[ 80%] Building C object CMakeFiles/check_request.dir/tests/check_request.c.o
[100%] Built target check_request

Cleaning up...

Build completed in 1.32 sec

Collected 4 relevant entries for C compilation (0 discarded).
Collected 0 relevant entries for C++ compilation (0 discarded).
Created YCM config file with 9 C flags
rdnetto commented 7 years ago

I suspect the problem is that YCM-Gen uses out-of-tree compilation with Cmake, and your project isn't setup to handle that. See if you can compile the project when you do the following:

$ mkdir /tmp/build
$ cd /tmp/build
$ cmake /path/to/project
$ make
0x47 commented 7 years ago

After fixing the underlying problem of #88, I can no longer reproduce this issue. I assume there were hidden linker errors or something else that was fixed as a side-effect.