Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clangd error: unknown argument: '-imsvc' #6058

Open
xq114 opened this issue Jan 11, 2025 · 7 comments
Open

clangd error: unknown argument: '-imsvc' #6058

xq114 opened this issue Jan 11, 2025 · 7 comments
Assignees

Comments

@xq114
Copy link
Contributor

xq114 commented Jan 11, 2025

          我这里clangd 报错 error: unknown argument: '-imsvc'。

https://reviews.llvm.org/D95472 根据这个链接可以用/winsdkdir和/winsdkversion指定sdk版本,我试了使用 "/winsdkdir", "C:\\Program Files (x86)\\Windows Kits\\10", "/winsdkversion", "10.0.22000.0" 可以,clangd不会报错。

Originally posted by @xq114 in #3574 (comment)

@star-hengxing
Copy link
Contributor

除了 win sdk,还有一些额外的内部头文件目录应该用哪个 flag 处理?

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


In addition to win sdk, there are some additional internal header file directories which flag should be used to handle?

@xq114
Copy link
Contributor Author

xq114 commented Jan 15, 2025

https://clang.llvm.org/docs/UsersManual.html#windows-system-headers-and-library-lookup

看起来是输入 /external:xx 然后clang-cl内部转为-imsvc,但我不确定

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


https://clang.llvm.org/docs/UsersManual.html#windows-system-headers-and-library-lookup

It looks like typing /external:xx then clang-cl internally translates to -imsvc, but I'm not sure

@star-hengxing
Copy link
Contributor

可能直接判断工具链更好。

diff --git a/xmake/plugins/project/clang/compile_commands.lua b/xmake/plugins/project/clang/compile_commands.lua
index ad21cff51..16d185da2 100644
--- a/xmake/plugins/project/clang/compile_commands.lua
+++ b/xmake/plugins/project/clang/compile_commands.lua
@@ -58,12 +58,18 @@ end
 -- specify windows sdk verison
 function _get_windows_sdk_arguments(target)
     local args = {}
-    local msvc = target:toolchain("msvc")
+    local msvc = target:toolchain("msvc") or target:toolchain("clang") or target:toolchain("clang-cl")
     if msvc then
         local envs = msvc:runenvs()
         if envs then
+            local include_sys_flag
+            if target:has_tool("cxx", "cl", "clang_cl") then
+                include_sys_dir_flag = "-imsvc"
+            else
+                include_sys_dir_flag = "-isystem"
+            end
             for _, dir in ipairs(path.splitenv(envs.INCLUDE)) do
-                table.insert(args, "-imsvc")
+                table.insert(args, include_sys_dir_flag)
                 table.insert(args, dir)
             end
         end

@waruqi 我发现 clang toolchian 永远取不到 runenvs,但三个 toolchain add vs env 代码都差不多的。

@waruqi
Copy link
Member

waruqi commented Jan 17, 2025

@waruqi 我发现 clang toolchian 永远取不到 runenvs,但三个 toolchain add vs env 代码都差不多的。

不一样,目前仅仅 msvc/clang-cl 会去检测加载默认的 msvc 环境,clang 不会,仅仅对 portable build tools 做了支持

另外, clang 是独立的工具链,也不应该跟 msvc 环境完全混在一起。

https://github.com/xmake-io/xmake/blob/dev/xmake/toolchains/clang/check.lua#L67

return _check_vstudio(toolchain)

@xq114
Copy link
Contributor Author

xq114 commented Jan 20, 2025

可能直接判断工具链更好。

diff --git a/xmake/plugins/project/clang/compile_commands.lua b/xmake/plugins/project/clang/compile_commands.lua
index ad21cff51..16d185da2 100644
--- a/xmake/plugins/project/clang/compile_commands.lua
+++ b/xmake/plugins/project/clang/compile_commands.lua
@@ -58,12 +58,18 @@ end
-- specify windows sdk verison
function _get_windows_sdk_arguments(target)
local args = {}

  • local msvc = target:toolchain("msvc")
  • local msvc = target:toolchain("msvc") or target:toolchain("clang") or target:toolchain("clang-cl")
    if msvc then
    local envs = msvc:runenvs()
    if envs then
  •        local include_sys_flag
    
  •        if target:has_tool("cxx", "cl", "clang_cl") then
    
  •            include_sys_dir_flag = "-imsvc"
    
  •        else
    
  •            include_sys_dir_flag = "-isystem"
    
  •        end
           for _, dir in ipairs(path.splitenv(envs.INCLUDE)) do
    
  •            table.insert(args, "-imsvc")
    
  •            table.insert(args, include_sys_dir_flag)
               table.insert(args, dir)
           end
       end
    

@waruqi 我发现 clang toolchian 永远取不到 runenvs,但三个 toolchain add vs env 代码都差不多的。

我的toolchain就是msvc,报错没有-imsvc,如果clangd用clang-cl来解析的话说明clang-cl也没有-imsvc。msvc里的system header用/external:I指定
https://learn.microsoft.com/zh-cn/cpp/build/reference/external-external-headers-diagnostics?view=msvc-170
-imsvc这个flag应该只是clang内部有,compile_commands不能指定

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants