简体   繁体   English

如何将 CLion C++ 项目导入 Visual Studio?

[英]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,说明如下:

  1. 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来验证这一点,以查看它是您刚刚安装的版本。

  2. 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

  3. 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.

相关问题 如何将Eclipse C ++项目移植到Visual Studio? - How can I port an Eclipse C++ project to Visual Studio? 我可以在Visual Studio中的单个项目中混合使用C ++和C吗? - Can I mix C++ and C in a single project in Visual Studio? 如何将项目从Visual C ++ 6.0转换为Visual Studio Express 2010? - How can I convert a Project from Visual C++ 6.0 to Visual Studio Express 2010? 我可以在 MAC 上打开现有的 Visual Studio 项目 (C++) 吗? - Can I open an existing Visual Studio Project (C++) on MAC? 如何在Visual Studio 2010中构建这个简单的C ++ / SWIG / C#项目? - How can I build this simple C++/SWIG/C# project in Visual Studio 2010? 如何创建一个使用CLR混合C和C ++的Visual Studio项目? - How can I create a single Visual Studio project that mixes C and C++ using CLR? 如何将 VS C++ 项目转换为 CMake 文件以在 CLion for Mac 上运行? - How can I convert a VS C++ project to CMake file to run on CLion for Mac? 我应如何在C ++ Visual Studio Project中包括Bond? - How Should I Include Bond in C++ Visual Studio Project? 如何在 Visual Studio 中打开 C++ 项目文件夹? - How do I open a c++ project folder in visual studio? 如何在Visual Studio Visual C ++ Win32项目中查看主窗体,以便编辑它? - How can I view the main form in a Visual Studio Visual C++ Win32 Project so I can edit it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM