简体   繁体   English

如何为Linux构建Visual C ++项目?

[英]How to build a Visual C++ Project for Linux?

What's the best and easiest way to build (for Linux) a C++ application which was written in Visual Studio? 构建(用于Linux)用Visual Studio编写的C ++应用程序的最佳和最简单的方法是什么? The code itself is ready - I used only cross-platform libs. 代码本身已准备就绪 - 我只使用跨平台库。

Is it possible to prepare everything under Windows in Visual Studio and then build it with a CLI tool under Linux? 是否可以在Visual Studio中的Windows下准备一切,然后在Linux下使用CLI工具构建它? Are there any docs describing this? 有没有文件描述这个?

EDIT: Some more information: 编辑:更多信息:

  • Libs used: stl, wxwidgets, boost, asio, cryptlib. Libs使用:stl,wxwidgets,boost,asio,cryptlib。

  • Very little Linux know-how. Linux知识很少。

EDIT#2: I chose the following solution: Make new project with kdevelop and compile everything there. 编辑#2:我选择了以下解决方案:使用kdevelop创建新项目并在那里编译所有内容。

We're using CMake for Linux projects. 我们正在使用CMake for Linux项目。 CMake can generate KDevelop and Visual Studio project files, so you can just create your CMake file as the origin of platform-specific IDE files. CMake可以生成KDevelop和Visual Studio项目文件,因此您只需创建CMake文件作为特定于平台的IDE文件的来源。 The KDevelop generator is fine, so you can edit and compile in KDevelop (which will in turn call Make). KDevelop生成器很好,所以你可以在KDevelop中编辑和编译(它将依次调用Make)。

On the other hand, if you have nothing fancy, you can use CMake or just Make to build the thing on Linux, if you want to stay with your solution file (which is what I'm currently doing for a library with test applications). 另一方面,如果你没有什么花哨的东西,你可以使用CMake或者只是Make来在Linux上构建东西,如果你想继续使用你的解决方案文件(这是我目前正在为带有测试应用程序的库做的事情) 。 This approach gets complicated when your build process is more than just "throw these files at the compiler and let's see what it does", so the CMake solution is in my opinion a good thing for cross-platform development. 当您的构建过程不仅仅是“将这些文件放在编译器中并让我们看看它做什么”时,这种方法变得复杂,因此CMake解决方案在我看来对于跨平台开发是一件好事。

Here is how to compile C code manually under Linux without additional build tools : 以下是如何在Linux 手动编译C代码而无需其他构建工具

gcc -s -O2 -o prog -I. -Iincludedir1 -Iincludedir2 -Llibdir1 -Llibdir2 code1.c code2.c -luse1 -luse2

However, if your project is larger than a couple of files, you may want to use a build tool instead (such as CMake, see OregonGhost's answer) to automate compilation of many files and to make it incremental. 但是,如果您的项目大于几个文件, 您可能需要使用构建工具 (例如CMake,请参阅OregonGhost的答案)来自动编译许多文件并使其增量。 If you use a build tool, it will run gcc under the hood, with similar arguments above. 如果你使用构建工具,它将在底层运行gcc,上面有类似的参数。 It's useful to understand the arguments above, so you can troubleshoot if your automated build fails. 理解上面的参数很有用,因此您可以在自动构建失败时进行故障排除。

This will compile code1.c and code2.c to executable binary prog, loading .h files from ., includedir1 and includedir2, loading libraries (eg libuse1.so* and libuse2.so*) from directories libdir1 and libdir2, using libraries use1 (corresponding to file name libuse1.so*) and use2. 这将编译code1.c和code2.c到可执行二进制prog,从。,includedir1和includedir2加载.h文件,从目录libdir1和libdir2加载库(例如libuse1.so *和libuse2.so *),使用库use1(对应于文件名libuse1.so *)和use2。

If you get undefined symbol errors in your .c files, you have to specify more -I flags. 如果在.c文件中出现未定义的符号错误,则必须指定更多-I标志。 If you get undefined symbol errors in the .o file, you have to specify more -l flags. 如果.o文件中出现未定义的符号错误,则必须指定更多-l标志。 If you get cannot find -l... errors, you have to specify more -L flags. 如果cannot find -l...错误,则必须指定更多-L标志。

8 years later ... 8年后......

I stumbled across this question today and thought you might like to take a look at Visual C++ for Linux . 我今天偶然发现了这个问题,并认为你可能想看看Visual C ++ for Linux

Released in March 2016, VC++ for Linux allows you to create a project in VC++, and then build it in a Linux machine/VM using native Linux tools. 2016年3月发布,VC ++ for Linux允许您使用VC ++创建项目,然后使用本机Linux工具在Linux机器/ VM中构建项目。 What's more, you can also debug your app from within VS since the Linux tools allow the VS debugger to drive GDB in your Linux machine/VM via SSH!! 此外,您还可以在VS中调试您的应用程序,因为Linux工具允许VS调试器通过SSH在您的Linux机器/ VM中驱动GDB!

Looks like this is almost exactly what @mspoerr was asking for :) 看起来这几乎正是@mspoerr所要求的:)

What's the best and easiest way to build a c++ application, which was written with Visual Studio, for Linux? 使用Visual Studio为Linux编写c ++应用程序的最佳和最简单的方法是什么? The code itself is ready - I used only cross-plattform libs. 代码本身已经准备就绪 - 我只使用了跨平台的库。

  • Check if there is anything that is not part of Standard C++ 检查是否有任何不属于标准C ++的内容
  • Rinse and repeat 冲洗并重复
  • Create a makefile or a KDevelop project 创建一个makefile或一个KDevelop项目

Et voilà! Etvoilà!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM