如何请求 Visual Studio C++ Intellisense 在外部库中查找函数定义?

huangapple go评论62阅读模式
英文:

How to ask Visual Studio C++ Intellisense to find function definitions in external libraries?

问题

摘要

当我点击(右键 -> “转到定义 F12”)时,我希望它显示我使用CMake编译的外部库的源代码。

详细信息/我尝试过的

我曾以为在(属性 -> VC++目录 -> 源目录)中添加路径,智能感知会自动识别,但似乎并不起作用。我曾将源代码复制到项目目录中(但不编译它)。那样可以,但因为“在项目中查找和替换”会导致混乱,所以变得很烦人。理论上,我可以引用CMake生成的Visual Studio项目文件,但由于所有内容已经在命令行上自动编译并在我的项目中正确链接,所以我不确定这是否是最佳选择,因为它涉及升级所有Visual Studio项目文件,可能会使项目变得不太便携。

可能相关的细节:

  • 仅依赖项使用CMake编译
  • Visual Studio版本为2022
  • 我使用“显示所有文件”方法来编译我的文件,以回答这个问题
  • 我只是想要外部库源代码的智能感知数据,它在我的项目之外
  • 外部库文件不在$(ProjectDir)

无论如何,感谢任何帮助,并随时提供关于如何设置项目的建议。

英文:

Summary

When I click (Right click -> "Go To Definition F12"), I would like it to show me the source of external libraries compiled with cmake.

Details/What I've tried

I was under the impression that in (Properties -> VC++ Directories -> Source Directories) I could just add the path and Intellisense would pick it up, but that doesn't seem to do it. I used to copy the source code into the project directory (but not compile it). That worked but that got annoying because "Find and replace in project" would really mess things up. I could theoretically reference the cmake generated visual studio project files, but since everything is already automatically compiled on the command line and linked properly in my project, I'm not sure if that's the best option because it involves upgrading all the visual studio project files and potentially cluttering the project and maybe making it less portable.

Maybe relevant details:

  • Only the dependencies are compiled with cmake
  • Visual studio version is 2022
  • I use the "show all files" method in answer to this question to compile my my files
  • I really just want Intellisense data for the external library source outside of my project
  • External library files are not in $(ProjectDir)

Anyway, any help appreciated and feel free to lend advice on how you'd setup the project.

答案1

得分: 1

这是设计的方式。
当静态库编译时,定义将存储在 lib 文件中。cpp 文件将不再使用。您可以将 cpp 文件拖到Visual Studio中,而不是复制。它能够找到源代码。

英文:

It is by design.
When the static library is compiled, the definition will be stored in lib file. And cpp files will no longer be used. You can drag the cpp files into Visual Studio instead of copying. It is able to find the source code.

huangapple
  • 本文由 发表于 2023年6月1日 09:42:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76378185.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定