gpt4 book ai didi

C++: Visual Studio can find included header through "Go to document", but build fails()

转载 作者:bug小助手 更新时间:2023-10-22 17:35:11 25 4
gpt4 key购买 nike



I was attempting to restructure (filesystem-wise) a Visual Studio solution a little bit, and this solution uses an external library (specifically, Onnx Runtime; I use the NuGet OnnxRuntime Visual Studio extension Microsoft.ML.OnnxRuntime v1.12.0).

我试图稍微重组(文件系统方面)Visual Studio解决方案,该解决方案使用外部库(特别是Onnx Runtime;我使用NuGet OnnxRuntime Visual Studio扩展Microsoft.ML.OnnxRuntime v1.12.0)。


After restructuring, I took a look in the .vcxproj files of the various projects in my solutions, and ensured everything looked well, which it all seemed to.

重组后,我查看了解决方案中各个项目的.vcxproj文件,并确保一切看起来都很好。


When I try to build the project, however, I get this error:

然而,当我尝试构建项目时,我会遇到以下错误:


Error C1083 Cannot open include file: 'onnxruntime_cxx_api.h': No such file or directory

错误C1083无法打开包含文件:“onnxruntime_cxx_api.h”:没有这样的文件或目录


However, if I Ctrl+left click the include directive that causes this error (or alternatively: right click and choose "Go To Document"), it does manage to find it. The path of the opened file is: $(SolutionDir)\packages\Microsot.ML.OnnxRuntime.1.12.0\build\native\include\onnxruntime_cxx_api.h


(Where $(SolutionDir) is substtuted with the actual path to my solution file.)

(其中$(SolutionDir)被替换为我的解决方案文件的实际路径。)


My solution structure is a bit strange:

我的解决方案结构有点奇怪:


./solution/
./solution.sln
./packages/
./Microsoft.ML.OnnxRuntime.1.12.0/
...
./sources/
./projectA/
projectA .cpp and .hpp files
./projectB/
projectB .cpp and .hpp files
./vs_stuff/
./projectA/
projectA Visual Studio files (vcxproj, vcxproj.users, packages.config, ...)
./projectB/
projectB .cpp and .hpp files (vcxproj, vcxproj.users, packages.config, ...)

I looked at all of the vs_stuff files and made sure that they do indeed point to the appropriate paths, and as far as I could tell, they do.

我查看了所有的vs_stuff文件,并确保它们确实指向了适当的路径,而且据我所知,它们确实指向。


Potentially crucial detail: this all started after I had attempted to restructure my solution. Initially it was the classic ./solution dir containing separate project directories, each with both sources and VS-related stuff; due to various requirements I had to change it to the structure described above, and the error resulted from this.

潜在的关键细节:这一切都是在我试图重组我的解决方案之后开始的。最初它是经典/解决方案目录包含单独的项目目录,每个目录都有源和VS相关的内容;由于各种要求,我不得不将其更改为上述结构,而错误就是由此产生的。


How might I go about solving this? The only thing I could think to do was to manually add

我该如何解决这个问题?我唯一能想到的就是手动添加


$(SolutionDir)\packages\Microsot.ML.OnnxRuntime.1.12.0\build\native\include

to my include directories or something, but that seems excessive and ugly and wasn't necessary before; plus, the IDE does find the header, so I'm not sure why the compiler doesn't.

我的include目录或其他什么,但这似乎太过分和丑陋了,以前没有必要;另外,IDE确实找到了头,所以我不知道编译器为什么找不到。


更多回答

the IDE does find the header, so I'm not sure why the compiler doesn't The compiler only looks in the same folder as your cpp source files or the system includes or the global includes or your project specific include directories. The compiler does not search all the places that the IDE does. These are independent.

IDE确实找到了头,所以我不知道为什么编译器没有。编译器只在与cpp源文件或系统include或全局include或项目特定include目录相同的文件夹中查找。编译器不会像IDE那样搜索所有的位置。这些是独立的。

@drescherjm, thanks for the input; interesting. I'd have assumed the IDE would try to ensure its behavior matches that of the compiler in that sense. Do you maybe have an idea how come the IDE could find the header file initially, even though this long path into the package wasn't directly specified in any file I could find? I struggle with finding any hint on Google...

@drescherjm,感谢您的投入;有趣的从这个意义上说,我本以为IDE会努力确保它的行为与编译器的行为相匹配。你可能知道IDE最初是如何找到头文件的吗?即使在我能找到的任何文件中都没有直接指定包的长路径?我很难在谷歌上找到任何提示。。。

Correction regarding my last comment: how the compiler* could find it.

关于我最后一条评论的更正:编译器*是如何找到它的。

I have the opposite problem, VS compiles and links fine, even IntelliSense and the Debugger work, but if I try to "Go to Document" of an include, it tells me it cannot find the file in the current source folder nor the system build paths. My .sln is generated by CMake, however, and the dependencies are installed with Conan, with the includes and libraries outside of the project folder. In the .vcxproj file, the external paths occur under <ClCompile>, <ResourceCompile>, <Midl>, and <Link>. Maybe you can check these? Do you have additional paths which make "Go to Document" work?

我有相反的问题,VS编译和链接很好,即使IntelliSense和调试器也能工作,但如果我尝试“转到包含的文档”,它会告诉我在当前源文件夹中找不到文件,也找不到系统生成路径。然而,My.sln是由CMake生成的,依赖项是与Conan一起安装的,includes和库位于项目文件夹之外。在.vcxproj文件中,外部路径出现在下。也许你可以看看这些?您是否有使“转到文档”起作用的其他路径?

优秀答案推荐

The directory is added automatically by NuGet.
Please check if there is

该目录由NuGet自动添加。请检查是否有


$(MSBuildThisFileDirectory)../../build/native/include/;


I was attempting to restructure (filesystem-wise)



You may have inadvertently modified the configuration. When I moved the vcxproj file location, the line didn't exist anymore.

您可能无意中修改了配置。当我移动vcxproj文件位置时,该行已不存在。


enter image description here


To fix the problem:

要解决此问题,请执行以下操作:


1.Reinstall the Microsoft.ML.OnnxRuntime package.

1.重新安装Microsoft.ML.OnnxRuntime包。



  1. Now you may get a NuGet package error. Open the vcxproj file with text.
    There will be multiple lines (at least 3) like '..\packages\Microsoft.ML.OnnxRuntime.1.12.0\build\native\Microsoft.ML.OnnxRuntime.targets. Delete them. And there are already right directories next to them
    <ImportProject="..\..\packages\Microsoft.ML.OnnxRuntime.1.12.0\build\native\Microsoft.ML.OnnxRuntime.props"


更多回答

Hi,@AnonA May I know if you have got any chance to check my answer?

嗨,@AnonA我可以知道你是否有机会核对我的答案吗?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com