如何解决Visual Studio 中的 Cmake 项目再也找不到标准库了
更新 1:我启动了一个新项目,该项目导致错误返回,并创建了一个额外的错误:
C1034: iostream: no include path set
更新 2:我设法通过在顶级 CMakeList 中包含以下内容来解决问题
if(WIN32)
include_directories(
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30037\\include"
"C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.19041.0\\ucrt"
)
link_directories(
"C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.19041.0\\um\\x64"
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30037\\lib\\onecore\\x64"
"C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.19041.0\\ucrt\\x64"
)
endif()
不过,我还不想将此标记为解决方案。因为我发现完全不能接受所有这些额外的冲刷对于让一个项目在一个程序中工作是必要的我的项目或实际问题。
我昨天安装了 VS2019 并编译了一个小测试程序,它只是向控制台写入一个数字。
#include <iostream>
#include <iomanip> // Included to test whether including other libs did work.
#include "Graphics/window.hpp"
int main()
{
std::cout << "Width: " << std::endl;
std::cout << "Height: " << std::endl;
return 0;
}
昨天它运行得很好,但是当我在包含 GLFW 后打开项目时,它无法找到 iostream 库并显示以下错误:
Error (active) E0135 namespace "std" has no member "endl" Slash.exe (source\Slash.exe) - x64-Debug C:\Users\Daisy\source\repos\CMakeProject1\source\main.cpp 9
Error (active) E0135 namespace "std" has no member "endl" Slash.exe (source\Slash.exe) - x64-Debug C:\Users\Daisy\source\repos\CMakeProject1\source\main.cpp 10
Error (active) E0135 namespace "std" has no member "cout" Slash.exe (source\Slash.exe) - x64-Debug C:\Users\Daisy\source\repos\CMakeProject1\source\main.cpp 9
Error (active) E0135 namespace "std" has no member "cout" Slash.exe (source\Slash.exe) - x64-Debug C:\Users\Daisy\source\repos\CMakeProject1\source\main.cpp 10
Error (active) E1696 cannot open source file "iostream" Slash.exe (source\Slash.exe) - x64-Debug C:\Users\Daisy\source\repos\CMakeProject1\source\main.cpp 1
Error (active) E1696 cannot open source file "iomanip" Slash.exe (source\Slash.exe) - x64-Debug C:\Users\Daisy\source\repos\CMakeProject1\source\main.cpp 2
Error C1083 Cannot open include file: 'iostream': No such file or directory C:\Users\Daisy\source\repos\CMakeProject1\out\build\x64-Debug\CMakeProject1 C:\Users\Daisy\source\repos\CMakeProject1\out\source\main.cpp 1
这是相关的 CMake 文件
项目根
cmake_minimum_required (VERSION 3.19)
project(Slash)
set(CMAKE_RUNTIME_OUTPUT_DIR ${PROJECT_SOURCE_DIR}/bin)
add_subdirectory(source)
项目根目录/源
add_subdirectory(Graphics)
add_executable (${CMAKE_PROJECT_NAME} main.cpp)
target_include_directories(${CMAKE_PROJECT_NAME}
PUBLIC
Graphics/include
)
target_link_libraries(${CMAKE_PROJECT_NAME}
Graphics
)
项目根目录/源代码/图形
add_library(Graphics
${CMAKE_CURRENT_LIST_DIR}/src/window.cpp
)
target_include_directories(Graphics
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include/Graphics
)
我也试过不再包含 GLFW,但这也无济于事。 (以防万一:我通过使用随附的 CMAKE 文件并使用 add_subdirectory() 命令来包含 GLFW。)
我已经手动查看了标准库,但在我的机器上找不到它们。我只是觉得很奇怪 CMake 无法再定位这些文件。
我还尝试在 samae 结果中包含其他标准库,以确保不仅仅是 iostream 给我带来了麻烦。
我使用的是库存 C++ 桌面工作负载,并选择了所有默认组件,以防出现问题。
我之前在尝试使用不同的编译器和构建系统在 Windows 上设置我的 C++ 工具时遇到了类似的问题,所以我认为这只是与 CMake 相关。
预先感谢您的任何建议。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。