40

What's the best and easiest way to build (for Linux) a C++ application which was written in Visual Studio? 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? Are there any docs describing this?

EDIT: Some more information:

  • Libs used: stl, wxwidgets, boost, asio, cryptlib.

  • Very little Linux know-how.

EDIT#2: I chose the following solution: Make new project with kdevelop and compile everything there.

Jason Plank
  • 2,336
  • 5
  • 31
  • 40
mspoerr
  • 2,680
  • 5
  • 32
  • 35

4 Answers4

19

We're using CMake for Linux projects. 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. The KDevelop generator is fine, so you can edit and compile in KDevelop (which will in turn call 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). 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.

OregonGhost
  • 23,359
  • 7
  • 71
  • 108
  • I would like to have it the way, that I can use the existing VisualStudio settings and save it as makefile? and use it under Linux. Is that possible? /mspoerr – mspoerr Apr 29 '09 at 16:06
  • 2
    Visual C++, at least some time ago, supported exporting a project/solution to a makefile. You can try it, but the resulting makefile is (or was at that time) a bloody mess. You could also try to create an XSLT to transform the project file (not the solution, though) to anything you like, including a Makefile or CMake file. – OregonGhost Apr 29 '09 at 16:32
8

8 years later ...

I stumbled across this question today and thought you might like to take a look at 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. 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!!

Looks like this is almost exactly what @mspoerr was asking for :)

Rich Turner
  • 10,800
  • 1
  • 51
  • 68
7

Here is how to compile C code manually under Linux without additional build tools:

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. If you use a build tool, it will run gcc under the hood, with similar arguments above. 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 (e.g. libuse1.so* and libuse2.so*) from directories libdir1 and libdir2, using libraries use1 (corresponding to file name libuse1.so*) and use2.

If you get undefined symbol errors in your .c files, you have to specify more -I flags. If you get undefined symbol errors in the .o file, you have to specify more -l flags. If you get cannot find -l... errors, you have to specify more -L flags.

pts
  • 80,836
  • 20
  • 110
  • 183
  • 6
    I'm assuming he has more than one file. Compiling without Makefiles is silly. – Zifre May 08 '09 at 19:30
  • 1
    @Zifre: I've updated my answer, recommending a build tool. I think my answer was and is insightful and useful for troubleshooting, even if a build tool is used. – pts Dec 04 '13 at 21:41
4

What's the best and easiest way to build a c++ application, which was written with Visual Studio, for Linux? The code itself is ready - I used only cross-plattform libs.

  • Check if there is anything that is not part of Standard C++
  • Rinse and repeat
  • Create a makefile or a KDevelop project

Et voilà!

dirkgently
  • 108,024
  • 16
  • 131
  • 187
  • 1
    can this makefile be generated from VisualStudio? Which changes are needed to make it work under Linux? /mspoerr – mspoerr Apr 29 '09 at 16:05
  • 2
    Some versions of VS can generate makefiles for nmake -- a Windows CLI based build system. The make you find on *nix systems is a bit different. You will need to weed out the differences. IMO, it'll be easier EITHER to 1) Use Code::Blocks (or some cross-platform IDE) and gcc on your Windows to get a build system working and then use it on Linux OR 2) use KDevelop which has a look-n-feel similar to VS to add source files/libs etc and get a autoconf based build system created for you. – dirkgently Apr 29 '09 at 16:13