EasyClangComplete icon indicating copy to clipboard operation
EasyClangComplete copied to clipboard

Cannot find std headers when using libclang

Open jdumas opened this issue 9 years ago • 13 comments

On my computer (up to date Archlinux), the following MWE doesn't agree with EasyClangComplete if I set "libclang": true:

#include <vector>

int main(void) {
	std::vector<int> foo;
	foo.emplace_back(2);
	return 0;
}

With a simple CMakeLists.txt:

cmake_minimum_required(VERSION 3.0)
project(foo)
add_executable(${PROJECT_NAME} main.cpp)

And my settings for EasyClangComplete:

{
	"common_flags" : [],
	"c_flags" : [],
	"cpp_flags" : [],
	"use_libclang" : true,
	"verbose" : true,
}

And here is a screenshot of the observed behavior on my system: 2016-12-16-150010_3120x1920_scrot

If I switch to "use_libclang" : false, then it works somehow...

jdumas avatar Dec 16 '16 14:12 jdumas

Have you tried adding flag --std=c++11?

simia avatar Dec 16 '16 14:12 simia

Also, it is probably related to #88 you should manually point the plugin to standard headers.

niosus avatar Dec 16 '16 14:12 niosus

You meant to false?

Yes sorry, I edited my message.

I shouldn't have to point the plugin to the standard header or to set -std=c++11. What is the point of having a CMakeLists.txt if I need to specify additional headers to the plugin? Moreover, it /does/ work with "libclang": false, so there must be another something else.

The same issues appears with other libs even if they are specified in my CMakeLists.txt (e.g. #include <Eigen/Dense>).

jdumas avatar Dec 16 '16 14:12 jdumas

Yes, you are right. You should not specify anything. However, because of the bug in clang referenced in #88 you need to specify this location for libclang for now. This bug is fixed for clang 4.0 and will go away as soon as they release a new version.

It only targets libclang. This is why it works with "use_libclang": false.

niosus avatar Dec 16 '16 14:12 niosus

Can you also show your CMakeLists.txt? It is strange as it seems clang is able to find vector, but not the emplace. So it seems it really doesn't understand this is c++11 code. And also, as usual, the log in sublime text console since a cold start to the point when it shows error. Thanks!

niosus avatar Dec 16 '16 14:12 niosus

Hi, you are right that there was a problem with C++11, but I don't understand why this would have been working via the command line (without libclang). Maybe my system clang is compiling in C++11 by default but I don't remember doing any particular setting in that regard.

Ok, so if I add C++11 to the CMakeLists.txt, it works for emplace_back():

cmake_minimum_required(VERSION 3.0)
project(foo)
add_executable(${PROJECT_NAME} main.cpp)
target_include_directories(${PROJECT_NAME} PUBLIC /usr/include/eigen3)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 11)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD_REQUIRED ON)

But now, I still get an error with types from Eigen

jdumas avatar Dec 16 '16 16:12 jdumas

as a side note. Any reason why you are not using find_package(Eigen3)? I use this in my code and it works fine.

niosus avatar Dec 16 '16 16:12 niosus

I just didn't want to bother including the FindEigen3.cmake in my test project, but usually that is what I do yes (I reckon Eigen ships with a CMake config only since version 3.3).

jdumas avatar Dec 16 '16 16:12 jdumas

Ok, got that. Find Eigen works well with Eigen 3.2 too.

Anyway, please publish the log. Don't worry if it is long. I will cut unneeded parts.

niosus avatar Dec 16 '16 16:12 niosus

DEBUG:EasyClangComplete.plugin.settings.settings_storage: Reading settings...
DEBUG:EasyClangComplete.plugin.settings.settings_storage:  autocomplete_all           <-- 'False'
DEBUG:EasyClangComplete.plugin.settings.settings_storage:  c_flags                    <-- '[]'
DEBUG:EasyClangComplete.plugin.settings.settings_storage:  clang_binary               <-- 'clang++'
DEBUG:EasyClangComplete.plugin.settings.settings_storage:  common_flags               <-- '[]'
DEBUG:EasyClangComplete.plugin.settings.settings_storage:  cpp_flags                  <-- '[]'
DEBUG:EasyClangComplete.plugin.settings.settings_storage:  errors_on_save             <-- 'True'
DEBUG:EasyClangComplete.plugin.settings.settings_storage:  flags_sources              <-- '[{'file': 'CMakeLists.txt'}, {'file': 'compile_commands.json'}, {'file': '.clang_complete'}]'
DEBUG:EasyClangComplete.plugin.settings.settings_storage:  hide_default_completions   <-- 'False'
DEBUG:EasyClangComplete.plugin.settings.settings_storage:  include_file_folder        <-- 'True'
DEBUG:EasyClangComplete.plugin.settings.settings_storage:  include_file_parent_folder <-- 'True'
DEBUG:EasyClangComplete.plugin.settings.settings_storage:  max_cache_age              <-- '00:30:00'
DEBUG:EasyClangComplete.plugin.settings.settings_storage:  triggers                   <-- '['.', '->', '::']'
DEBUG:EasyClangComplete.plugin.settings.settings_storage:  use_libclang               <-- 'True'
DEBUG:EasyClangComplete.plugin.settings.settings_storage:  verbose                    <-- 'True'
DEBUG:EasyClangComplete.plugin.settings.settings_storage: Settings sucessfully read...
DEBUG:EasyClangComplete.plugin.tools: file has valid syntax: `C++`
DEBUG:EasyClangComplete.EasyClangComplete: on_activated_async view id 28
DEBUG:EasyClangComplete.plugin.settings.settings_manager: no settings for view 28. Reinitializing.
DEBUG:EasyClangComplete.plugin.tools: file has valid syntax: `C++`
DEBUG:EasyClangComplete.plugin.settings.settings_storage: Overriding settings by project ones if needed:
DEBUG:EasyClangComplete.plugin.settings.settings_storage: Valid prefixes: ['ecc_', 'easy_clang_complete_']
DEBUG:EasyClangComplete.plugin.settings.settings_storage: Reading settings...
DEBUG:EasyClangComplete.plugin.settings.settings_storage: Settings sucessfully read...
INFO:EasyClangComplete.plugin.tools: Getting version from command: `clang++ -v`
INFO:EasyClangComplete.plugin.tools: Found clang version: 3.9.0
DEBUG:EasyClangComplete.plugin.settings.settings_storage: populating common_flags with current variables.
DEBUG:EasyClangComplete.plugin.settings.settings_manager: settings initialized for view: 28
DEBUG:EasyClangComplete.plugin.tools: file has valid syntax: `C++`
DEBUG:EasyClangComplete.plugin.view_config: generate new config for path: 28
DEBUG:EasyClangComplete.plugin.tools: file has valid syntax: `C++`
DEBUG:EasyClangComplete.plugin.tools: file has valid syntax: `C++`
INFO:EasyClangComplete.plugin.view_config: init completer based on libclang
DEBUG:EasyClangComplete.plugin.completion.lib_complete: using bundled cindex: EasyClangComplete.clang.cindex39
DEBUG:EasyClangComplete.clang.utils: platform: ('64bit', '')
DEBUG:EasyClangComplete.clang.utils: python version: 3.3.6
INFO:EasyClangComplete.clang.utils: we are on 'Linux'
INFO:EasyClangComplete.clang.utils: searching for: 'libclang.so'
INFO:EasyClangComplete.clang.utils: libclang search output = '/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.2.1/../../../../lib64/libclang.so'
DEBUG:EasyClangComplete.clang.utils: real output: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.2.1/../../../../lib64/libclang.so
INFO:EasyClangComplete.clang.utils: found libclang dir: '/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.2.1/../../../../lib64'
INFO:EasyClangComplete.clang.utils: found library file: 'libclang.so'
DEBUG:EasyClangComplete.plugin.flags_sources.cmake_file: [cmake]:[get]: for file /home/jdumas/downloads/test_cpp/main.cpp
DEBUG:EasyClangComplete.plugin.flags_sources.cmake_file: [cmake]:[cached]: 'None'
DEBUG:EasyClangComplete.plugin.tools: searching 'CMakeLists.txt' from '/home/jdumas/downloads/test_cpp' to '/home/jdumas/downloads/test_cpp'
DEBUG:EasyClangComplete.plugin.tools: found 'CMakeLists.txt' file: /home/jdumas/downloads/test_cpp/CMakeLists.txt
DEBUG:EasyClangComplete.plugin.tools: found needed line: 'project(foo)
'
DEBUG:EasyClangComplete.plugin.flags_sources.cmake_file: [cmake]:[current]: '/home/jdumas/downloads/test_cpp/CMakeLists.txt'
DEBUG:EasyClangComplete.plugin.flags_sources.cmake_file: [cmake]:[generate new db]
DEBUG:EasyClangComplete.plugin.flags_sources.cmake_file: Folder /tmp/EasyClangComplete/cmake_builds/bf83f1fe76109dc1ca2fa4b7b99db038 exists.
DEBUG:EasyClangComplete.plugin.flags_sources.cmake_file: prefix paths: []
DEBUG:EasyClangComplete.plugin.flags_sources.cmake_file: merged paths: 
DEBUG:EasyClangComplete.plugin.flags_sources.cmake_file: CMAKE_PREFIX_PATH: 
INFO:EasyClangComplete.plugin.flags_sources.cmake_file: running command: cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON  "/home/jdumas/downloads/test_cpp"
INFO:EasyClangComplete.plugin.flags_sources.cmake_file: cmake produced output: 
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/EasyClangComplete/cmake_builds/bf83f1fe76109dc1ca2fa4b7b99db038

DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/tmp/EasyClangComplete/cmake_builds/bf83f1fe76109dc1ca2fa4b7b99db038/CMakeCache.txt'
DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/home/jdumas/downloads/test_cpp/CMakeLists.txt'
DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/tmp/EasyClangComplete/cmake_builds/bf83f1fe76109dc1ca2fa4b7b99db038/CMakeFiles/3.6.3/CMakeCCompiler.cmake'
DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/tmp/EasyClangComplete/cmake_builds/bf83f1fe76109dc1ca2fa4b7b99db038/CMakeFiles/3.6.3/CMakeCXXCompiler.cmake'
DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/tmp/EasyClangComplete/cmake_builds/bf83f1fe76109dc1ca2fa4b7b99db038/CMakeFiles/3.6.3/CMakeSystem.cmake'
DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/usr/share/cmake-3.6/Modules/CMakeCInformation.cmake'
DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/usr/share/cmake-3.6/Modules/CMakeCXXInformation.cmake'
DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/usr/share/cmake-3.6/Modules/CMakeCommonLanguageInclude.cmake'
DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/usr/share/cmake-3.6/Modules/CMakeGenericSystem.cmake'
DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/usr/share/cmake-3.6/Modules/CMakeLanguageInformation.cmake'
DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/usr/share/cmake-3.6/Modules/CMakeSystemSpecificInformation.cmake'
DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/usr/share/cmake-3.6/Modules/CMakeSystemSpecificInitialize.cmake'
DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/usr/share/cmake-3.6/Modules/Compiler/GNU-C.cmake'
DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/usr/share/cmake-3.6/Modules/Compiler/GNU-CXX.cmake'
DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/usr/share/cmake-3.6/Modules/Compiler/GNU.cmake'
DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/usr/share/cmake-3.6/Modules/Platform/Linux-GNU-C.cmake'
DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/usr/share/cmake-3.6/Modules/Platform/Linux-GNU-CXX.cmake'
DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/usr/share/cmake-3.6/Modules/Platform/Linux-GNU.cmake'
DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/usr/share/cmake-3.6/Modules/Platform/Linux.cmake'
DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/usr/share/cmake-3.6/Modules/Platform/UnixPaths.cmake'
DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/tmp/EasyClangComplete/cmake_builds/bf83f1fe76109dc1ca2fa4b7b99db038/CMakeFiles/cmake.check_cache'
DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/tmp/EasyClangComplete/cmake_builds/bf83f1fe76109dc1ca2fa4b7b99db038/CMakeFiles/CMakeDirectoryInformation.cmake'
DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/tmp/EasyClangComplete/cmake_builds/bf83f1fe76109dc1ca2fa4b7b99db038/CMakeFiles/foo.dir/DependInfo.cmake'
DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/home/jdumas/downloads/test_cpp/CMakeLists.txt'
DEBUG:EasyClangComplete.plugin.flags_sources.compilation_db: [db]:[get]: for file /home/jdumas/downloads/test_cpp/main
DEBUG:EasyClangComplete.plugin.flags_sources.compilation_db: [db]:[cached]: 'None'
DEBUG:EasyClangComplete.plugin.tools: searching 'compile_commands.json' from '/tmp/EasyClangComplete/cmake_builds/bf83f1fe76109dc1ca2fa4b7b99db038' to '/'
DEBUG:EasyClangComplete.plugin.tools: found 'compile_commands.json' file: /tmp/EasyClangComplete/cmake_builds/bf83f1fe76109dc1ca2fa4b7b99db038/compile_commands.json
DEBUG:EasyClangComplete.plugin.flags_sources.compilation_db: [db]:[current]: '/tmp/EasyClangComplete/cmake_builds/bf83f1fe76109dc1ca2fa4b7b99db038/compile_commands.json'
DEBUG:EasyClangComplete.plugin.flags_sources.compilation_db: [db]:[load new]
DEBUG:EasyClangComplete.plugin.flags_sources.compilation_db: [db]: put into cache: '/tmp/EasyClangComplete/cmake_builds/bf83f1fe76109dc1ca2fa4b7b99db038/compile_commands.json'
DEBUG:EasyClangComplete.plugin.tools: updating modification time for file '/tmp/EasyClangComplete/cmake_builds/bf83f1fe76109dc1ca2fa4b7b99db038/compile_commands.json'
DEBUG:EasyClangComplete.plugin.view_config: flags generated from 'CMakeLists.txt'.
DEBUG:EasyClangComplete.plugin.completion.lib_complete: view is 28
DEBUG:EasyClangComplete.plugin.completion.lib_complete: translation unit does not exist. Creating.
DEBUG:EasyClangComplete.plugin.tools: file has valid syntax: `C++`
DEBUG:EasyClangComplete.plugin.completion.lib_complete: clang flags are: ['-c', '-fsyntax-only', '-x', 'c++', '-I/home/jdumas/downloads/test_cpp', '-I/home/jdumas/downloads', '-I/usr/include/eigen3', '-std=gnu++11']
DEBUG:EasyClangComplete.plugin.completion.lib_complete: compilation started for view id: 28
DEBUG:EasyClangComplete.plugin.completion.lib_complete: compilation done in 0.42156004905700684 seconds
DEBUG:EasyClangComplete.plugin.completion.lib_complete: reparsing translation_unit for view 28
DEBUG:EasyClangComplete.plugin.completion.lib_complete: reparsed in 0.5897023677825928 seconds
DEBUG:EasyClangComplete.plugin.error_vis: generating error regions for view 28
DEBUG:root: adding error {'error': "'stdarg.h' file not found", 'row': '39', 'file': '/usr/include/wchar.h', 'col': '11'}
DEBUG:root: adding error {'error': "member reference base type 'Eigen::Vector3d' (aka 'int') is not a structure or union", 'row': '6', 'file': '/home/jdumas/downloads/test_cpp/main.cpp', 'col': '3'}
DEBUG:EasyClangComplete.plugin.error_vis: 1 error regions ready
DEBUG:EasyClangComplete.plugin.error_vis: showing error regions: [(80, 81)]
DEBUG:EasyClangComplete.plugin.view_config: starting timer to remove old configs.
DEBUG:EasyClangComplete.plugin.view_config: [timer]: start for view: 28
DEBUG:EasyClangComplete.plugin.view_config: [timer]: active for views: dict_keys([28])

jdumas avatar Dec 16 '16 16:12 jdumas

Hmm, so '-I/usr/include/eigen3' flag is there. So the plugin does what it must. This means the issue is somewhere in clang. This looks suspicious:

DEBUG:root: adding error {'error': "'stdarg.h' file not found", 'row': '39', 'file': '/usr/include/wchar.h', 'col': '11'}

Can you try to add this to your common flags?

"-I/usr/lib/clang/$clang_version/include"

niosus avatar Dec 16 '16 16:12 niosus

Interesting, it appears to be working with "-I/usr/lib/clang/$clang_version/include".

jdumas avatar Dec 16 '16 16:12 jdumas

As far as I understand this should be fixed with #88. I will close this issue for now.

niosus avatar Dec 16 '16 18:12 niosus