Linux app using C++ and visual studio - c++

I want to write an app in visual studio that will work in linux. It's main function will be to monitor multiple linux systems and provide health and status to the GUI... I.e disk usage, bad drives, network throughput, mysql reads/inserts, ect... Can I cross compile with visual studio 2010?
Should I even bother using visual studio? Or should I bail and use Java or C++ on linux?
Thanks for the help guys, looks like the inevitable is true! I was just looking at netbeans, so I guess I will use that. I don't normally write for Linux, so I will just have to plow through it :)
Thanks

If you like the VS IDE, you can certainly use it to write code that's portable to Linux, though actually compiling the code for Linux will be separate. In theory, you could probably configure VS to compile your code with gcc as a post-build step, for example, but it would probably be more work than it was worth.
At least IMO, if you're trying write code that's portable to Windows and Linux (e.g., using Qt for its UI), and you're comfortable with VS, it's probably worth using VS to do most of the work. If you prefer Linux tools or you're writing the code exclusively for Linux, then you're probably better off using Linux tools throughout.

No; Microsoft Visual Studio does not contain a cross compiler for Linux. Nothing says you cannot use the C++ you build in Visual Studio on Linux machines though; you would just need to compile to code there.

As Visual Studio does neither run on Linux natively nor can it produce native Linux code, I would recommend you use the target platform's native toolchain to build your software.
If your goal is to create a portable application that runs on both Windows and Linux, starting one Windows with Visual Studio and recompiling the code on the Linux system on a regular basis is probably a pretty decent approach.

It is possible to use Visual Studio to develop, but you can't create the Linux executable with it - for that you need to use the gcc compiler under Linux. You'll find a few differences between the compilers that will give you some grief, and unfortunately a lot of those differences will be in the areas you're targeting - O/S services. It's a judgement call which would be easier but in your case I'd bite the bullet and use the Linux tools exclusively.

Bail.
Maybe look into monodevelop which is much less nice than Visual Studio.
Netbeans and/or Eclipse for linux are nice though.

Bail, Visual Studio is definitively not the best tool for this particular job.
If you want to code C++ for GNU/Linux, there are a lot of good IDEs in there: Eclipse, NetBeans, KDevelop, Codeblocks...
Also, check the answers on this question: C++ IDE for Linux?, I think you'll find some useful stuff there.

For what it's worth I've used VS to write code that was supposed to work on Windows and *nix. I'd figure out a configuration method for *nix and as you go before every major commit try compiling the code with gcc. Visual Studio's Intellisense and VC++ debugger murder Eclipse+CDT+gdb in every way.

I'm fairly partial to Qt Creator for my x-platform C++ tasks.

Related

Platform for c++ cross compile application

Currently, we are using MS Visual Studio and .NET to develop out applications on Window. We are in the process of porting the application to other OS (Linux, Android...etc) and want to get rid of MS Visual Studio and .NET stuff (they have been a pain to work with).
Is there any good development platform that you would recommend?
Thanks,
ABS
I would port the Visual Studio's solution/project files to CMake (in the downloads list you can get binaries for Windows and Linux), which allows you to generate project files for different platforms, allowing cross-toolset development. Eg:
On Windows, running CMake would detect Visual Studio and would generate solution and project files accordingly.
On Linux: running CMake would find, for instance, gcc or g++ and would generate makefiles accordingly.
I have not tried it, but for android's NDK there's this: android-cmake
[UPDATE Information on gcc/make for windows]
If you want to drop Visual Studio completely, you can try to set up the gcc/make toolchain for Windows with MinGW - Minimalist GNU for Windows, and port your solution/project files to makefiles.
Moving from Windows to other OS'es may shock you at first, but with time you'll get used to it: You do not need a "platform" or "IDE" per se.
What you will need, is cmake, gcc/g++, a decent text editor and perhaps a debugger frontend.
Optionally you may find ctags useful, Doxygen, an svn repo and a profiler (such as Valgrind/KCachegrind).
I am unaware of how exactly you can port .net stuff to C/C++ (other than re-writing from scratch).
Linux and OSX have many similarities, so porting from one to another should not be that hard. Android is a different story, although C++ for android has become a possibility.
The closest thing to what you are looking for, would probably be Eclipse or Netbeans, but again, the simpler you keep those things, the better IMHO.
As to getting rid of .NET, If your .NET code base is not in managed C++ in its entirety, I would try out Mono/Xamarin with Xamarin Studio IDE first before embarking on a full port of .NET code base to standardized C++.

Should I cross-develop for Linux under Visual Studio

It seems that Visual Studio and the tools you can use it is far superior to Eclipse and other Linux-platforms.
So does it make sense to cross-develop for Linux under Visual Studio, as long as the code is much the same?
I assume that you can easily share files.
Of course it depends a lot of what you know and project setup, but for the later, importing to VS might be easier than importing into Eclipse.
This is actually possible, but only if you have the right infrastructure in place on both Windows and Linux (or some other *nix variety). I used to worke for an investment bank where almost all work was done on Windows with VC++ and then moved to Solaris and recompiled. This allowed us to use the far superior (over Solaris) Windows tools. And we are talking of building multi-tier, multi-threaded servers here.
However, in order to get this to work they had put in a massive effort (I would guess about 15 man-years) in terms of senior developer time. And it was kind of worth it because Solaris development tools are pants (but the Linux ones are actually quite good). It's not something you, as an individual developer are going to find particularly easy to do, unless you are writing generic command line utilities. In which case you can do it - I routinely recompile my Windows command-line projects on Linux.
The difficult part, in my opinion, is maintaining the separate build systems. If you start the project using Visual Studio you will be tempted to setup the project using the Visual Studio build system.
Don't do that.
Instead, I recommend trying CMake. Make the build system build using CMake, and then work from that starting point.
If I had to choose between Visual Studio and Emacs, I'd go with Emacs. The fact that Visual Studio seems superior to you is just because you got used to it and don't know how to do your usual workflow using other tools. Eclipse, after all, might not be the best choice for Windows developer to move to Linux. I'd also take a look at Qt Creator.

Costs and benefits of Linux-like Windows development environment

I'm taking an Introduction to C++ this semester, so I need to set up development environments in both my Windows and Ubuntu partitions (I switch between them). I was planning to use GCC in both environments for consistency and because I plan to do my serious C++ developing in Linux with GCC.
It appears that installing MSYS and MinGW is the best way to use GCC and replicate my Linux dev environment. However, just setting up MSYS and MinGW in Windows appears to be a long and arduous process, and I'm imagining that I will have limitations or compatibility problems in the future.
Do the benefits of setting up a MSYS Linux-like development environment on Windows outweigh the costs?
Will I be able to use all the libraries that I could if I were using Visual C++?
I think you're going about this the wrong way - I would actually suggest you use Visual Studio on the Windows environment, rather than going out of your way to setup GCC. It's a benefit, not a drawback, to run your code on multiple compilers from multiple vendors.
Both GCC and Visual Studio are highly conformant (at least recent versions). You won't have any trouble with standard libraries and going between them, and if you do have trouble, it's probably an issue in your code.
I've always installed cygwin on Windows. To me, Windows is completely unusable without it. I've never really run into problems with DLLs mentioned above. However, I've also rarely used the GCC compiler, so I don't know how it compares to Visual Studio for general programming. For anything with a Windows GUI or Dot Net based, I would definitely stick with Visual Studio.
If you stick with the automated installer, MinGW installation is not painful at all. Unfortunately, that currently gives you GCC 3.4.5, rather than the newer 4.4.0 release that they also provide sans installer.
In reality, for course work, 3.4.5 will be just fine, I imagine.
Use gcc on Ubuntu and Visual Studio on Windows to get exposure to both. This is an intro course so Windows, Linux, Visual Studio, gcc are just the tools you need to master C++ and data structures. Mastering the tools will come over time and they will change.
I personally develop for windows using a pure Linux environment using mingw-gcc on Linux to cross-compile for windows.
I put a tutorial on how to set it up for OpenSSL/Qt4 # http://www.limitlessfx.com
Do you do this to get .exes or just to be able to work on both OSes?
If you feel more comfortable with GCC than VC, setting up Mingw/Cygwin is possible but doesn't give you any new functionality (beside .exes). Instead, I suggest you turn one of your partitions into a virtual machine - this way you can have both OSes open at once! (My personal choice is Windows inside Linux, YMMV.)
The benefit of developing on Linux is ready availability of tons of development tools and libraries. Also, big builds are noticably faster.
Since you said "I plan to do my serious C++ developing in Linux with GCC", VC++ may not be what you really want. Many libraries just don't compile well in VC++. Try some yourself. Instead, consider running Linux on Windows. There are several ways to do this:
Use PuTTY to connect to a Linux machine, and use Xming to see the UI windows. I would only do this over a LAN.
Consider coLinux. You can run Linux under Windows and just shut-off Linux when you are done.
Consider other virtualization options like VMWare to run Linux. Pretty much the same as coLinux, but it might be easier to setup.
You may even want to install Linux directly on your machine. You can always use tools like Wine or VMWare to run Windows if you need it.

Setting up windows for C++

To quote the FAQ, 'No question is [...] too "newbie"'
What is the best way to set up an Windows system (vista, if that matters) to work with C++?
Preferably with a nice IDE, easy compiling of software (support for make files, etc.), but suitable for a beginner.
I would quite like the IDE to use a relatively portable format, such as makefiles and configure scripts, nothing too proprietary.
I would also like the ability to add new libraries etc. without much hassle, and work with the majority of C++ code others have written.
I am comfortable using the command line.
Thanks for the help, hopefully the question is clear. And apologies if it's already been answered, i did have a look for similar questions.
I know this is not exactly 'nothing to proprietary' but you should give a look at the free Express Edition of Visual C++. Under its covers you'll get all the familiar make and command line tools, but wrapped in a polished IDE.
If you're really comfortable with the command line then you can make an IDE from code editor on top of a compiler/debugger suite. MS's own command line tools come with the platform SDK (free) and you get an awesome debugger in Windbg. My personal favorite code editor is Code Insight. I wish so hard for a Mac version /sigh.
Microsoft's Visual Studio has a free express edition which contains pretty much everything you need to program c++.
For a Gui, the main choices are probably, MFC (old and ugly), CLR/.Net (new and confusing) or look at Qt(now LGPL) or wxWigets
There are quite a few good IDEs for C++ available on Windows.
The de-facto standard for professional software development is Microsoft's Visual Studio, which is available in different versions, like the free Express Editions. This will give you a great tool-chain for Windows development.
However, for a more "cross-platform" approach, you should have a look to the free Eclipse C++ Development Tooling, which is available for many platforms. As long as your own code is platform-independent, the whole project can be shared between Windows, Linux, Mac, etc.
Other alternatives are MinGW or CygWin that both allow to use the GCC toolchain on Windows.
Try the MinGW compiler, it will come with a C and C++ compiler, Make, etc--among many others. This can be used from the command line, pretty easily: g++ -o someprogram.exe somecode.cpp
As for an IDE, there are lots out there. Right now I am using Code::Blocks, and so far it's been really nice. As well, it already supports the GCC compiler, and sets many of the appropriate flags for you, so all you'll really need to do is hit the "build" button.
Some others you might want to try are Eclipse, which is really powerful, but lots of its "power" will be really confusing and difficult to use until you start getting used to it. Visual C++ is another one, which (obviously) would integrate very nicely into Windows. Of course, you could always use emacs :)
I suggest you evaluate CodeBlocks.
Microsoft's Visual Studio is powerful but rather proprietary. If you prefer open/portable stuff, I recommend Dev-C++ and Cygwin.
FWIW, I recently went through this and tried the VC++ Express and QT Creator based stuff. Coming from a linux/unix background I found that QT was a little better since it was using the Ming compilers and some make based constructs.
If you will only be hacking for windows I would go for Visual Studio. It will definitely save you time you can spend on coding instead. Most open source out there for windows either already have VC project, and if they don't it is usually very simple to set one up. And normally they have either make or nmake files for you to build VC compatible libararies to link with.

I'm starting my C++ learning, using CodeBlocks and windows, what compiler should I use?

I'm under the impression certain compilers only work for making windows applications.
If you want to develop GUI applications and/or go for maximum portability, go for MinGW for compiler, and Qt Creator for IDE (it comes with MinGW bundled).
If you want to stick to Windows, and don't mind coding UI directly using Win32 API, then Visual C++ Express would do the trick.
If you care about portability to Unix, use the mingw compilers which are based on gcc. Gcc is widely available on a lot of architectures and OS. If you only work for Windows, Visual Studio Express might be a better choice in comparison to Codeblocks.
How about Visual Studio Express? This is a complete package with a very nice IDE.
Codeblocks supports many compilers. I recommend using CB with mingw for general purpose usage.
Depends what you want to do. If you want to use POSIX APIs you may want to use mingw. If you distribute to Windows folks, you probably want to use Visual Studio since its compiler is usually better at producing optimized code.
CMake might be something you want to use if you want multiple platforms - it'll create your CodeBlocks/Eclipse/Visual Studio/GNU Make projects for you w/ all the correct settings.
If you are keen on using Codeblocks mingw is a good choice. But C++ is not like Java. It is not write once run everywhere. Also it is not write once compile on different platforms and run everywhere.
You have to change your code for different platforms (win/unix etc...) (eg: socket programming differs on Windows and Linux)
This means that you are not platform independent. So I recommend you to go for a better one. Eclipse is good, community is great but for me QT or Visual Studio (6.0 or 2008 for .Net) would be better.