[英]How can I import a CLion C++ project into Visual Studio?
It seems like this should be easy and I've spent hours trying to find this answer online but haven't had any luck.看起来这应该很容易,我花了几个小时试图在网上找到这个答案,但没有任何运气。
I can open the CLion folder path in Visual Studio, but that option doesn't give me the usual options to build and start the project.我可以在 Visual Studio 中打开 CLion 文件夹路径,但该选项没有为我提供构建和启动项目的常用选项。 To do that, I need to open CLion as a Project/Solution, but I can't seem to do this.
为此,我需要将 CLion 作为项目/解决方案打开,但我似乎无法做到这一点。
My professor requires that my C++ code be executable in Visual Studio, but I prefer CLion.我的教授要求我的 C++ 代码可以在 Visual Studio 中执行,但我更喜欢 CLion。 So I've done all my work in CLion and want to test that it runs in Visual Studio.
所以我已经在 CLion 中完成了所有工作,并想测试它是否在 Visual Studio 中运行。 How can I import my CLion project?
如何导入我的 CLion 项目?
Thanks!谢谢!
The link provided describes Visual Studio's CMake integration , which (similar to CLion) will install a version of CMake that Visual Studio will use.提供的链接描述了Visual Studio 的 CMake 集成,它(类似于 CLion)将安装 Visual Studio 将使用的 CMake 版本。 These instructions are pretty thorough and should provide everything needed to get your CMake project working in Visual Studio.
这些说明非常详尽,应该提供让您的 CMake 项目在 Visual Studio 中工作所需的一切。
Now, you probably have two versions of CMake installed on your machine, one that came with CLion and one that came with Visual Studio.现在,您的机器上可能安装了两个版本的 CMake,一个是 CLion 附带的,一个是 Visual Studio 附带的。 I would recommend installing the latest version of CMake on your machine separately , and configuring both Visual Studio and CLion to use that version instead.
我建议在您的计算机上单独安装最新版本的CMake ,并将 Visual Studio 和 CLion 配置为使用该版本。 However, this is probably getting outside the scope of your immediate problem.
但是,这可能超出了您当前问题的 scope 范围。
As you follow the Microsoft's instructions for "CMake projects in Visual Studio" , you mentioned receiving the error:当您按照 Microsoft 的“Visual Studio 中的 CMake 项目”说明进行操作时,您提到收到错误:
1> [CMake] CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.17/Modules/CMakeDetermineSystem.cmake:173 (file):
1> [CMake] file failed to open for writing (No such file or directory):
This looks like a permissions issue, specifically while running CMake within Visual Studio, so be sure you have read/write access to all the files in your project, and the CMake packages in your Visual Studio installation.这看起来像是权限问题,特别是在 Visual Studio 中运行 CMake 时,因此请确保您对项目中的所有文件以及 Visual Studio 安装中的 CMake 包具有读/写访问权限。 Hopefully, this doesn't require you re-install Visual Studio in another location on your machine, or run Visual Studio with elevated privileges, but perhaps that is necessary.
希望这不需要您在计算机上的另一个位置重新安装 Visual Studio,或者以提升的权限运行 Visual Studio,但这也许是必要的。
If you decide to install CMake separately , the instructions would be the following:如果您决定单独安装 CMake,说明如下:
Install the latest CMake on your machine (somewhere you have adequate permissions), and ensure it is available in your Path
environment variable.在您的机器上安装最新的 CMake(在您有足够权限的地方),并确保它在您的
Path
环境变量中可用。 You can verify this by running cmake -version
from the command line to see it is the version you just installed.您可以通过从命令行运行
cmake -version
来验证这一点,以查看它是您刚刚安装的版本。
Using Windows command prompt, navigate to your CMake project directory (containing the top-level CMakeLists.txt
file), and run the following:使用 Windows 命令提示符,导航到 CMake 项目目录(包含顶级
CMakeLists.txt
文件),然后运行以下命令:
mkdir build cd build cmake -G "Visual Studio 16 2019" -A x64..
You may run -A Win32
with the cmake
command instead if your project is a 32-bit build.如果您的项目是 32 位版本,则可以使用
cmake
命令运行-A Win32
。
Open the .sln
Visual Studio Solution file that was generated in the build
directory.打开
build
目录中生成的.sln
Visual Studio 解决方案文件。 Once, the Solution is loaded in Visual Studio, you can build the project ( CTRL + SHIFT + B ).在 Visual Studio 中加载解决方案后,您可以构建项目 ( CTRL + SHIFT + B )。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.