How do I set my Visual studio 2008 compiler to GNU GCC. Can I also make it specific to projects? I didn't find any conclusive answer.
Thank you.
You can't use the compiler directly.
You can, however, invoke a makefile instead of using the built-in build system.
Example of configuration:
Install MinGW (I guess this step is already done), including mingw32-make
Create a makefile for mingw32-make called MinGWMakefile , with 3 targets: clean, build, and rebuild. This can be very tedious if you've never done that before.
Create a new configuration for your project
Go to configuration properties->general->configuration type, and select "makefile"
Go to configuration properties->NMake, and use these command lines:
Build Command Line: mingw32-make -f MinGWMakefile build
ReBuild Command Line: mingw32-make -f MinGWMakefile rebuild
Clean Command Line: mingw32-make -f MinGWMakefile clean
Enable "go to line" functionality on compiler messages:
You need to transform the output of gcc, from this:
filename:line:message
To this:
filename(line):message
I was using a custom C++ program to do that, but any regular expression tool will do the trick.
For best results, use GNU make, a Visual Studio makefile project, and a tool that you write yourself. Your makefile is a skeleton, that compiles files (use a variable for the files list), and your tool parses the .sln and .vcproj files to generate this file list. The makefile includes the result. Just needs a bit of glue and elbow grease -- you'll spend a day cursing make's unwillingness to do what you want, then you'll get it working. Once up and running this approach doesn't require too much maintenance.
You can keep your tool and makefile simple, just throwing all files in all projects into the mix and linking the result, using file patterns to decide what happens to each file, and putting all compiler options in the makefile. Or you can get more clever, pull #defines and include paths from the project, and maybe add in a Win32 project configuration that the makefile generator uses to properly handle custom build steps, excluded files, compiler options, and so on.
The easy approach should satisfy most, because it lets anybody add new files to the project just as they normally do, without having to concern themselves with the makefile, whilst making it hard for people to accidentally change settings that don't want changing.
I have previously described this approach (with a tiny bit more detail):
Good techniques to use Makefiles in VisualStudio?
(Once you have it set up, it works well, and in many respects it's actually more convenient than the usual VS approach, even before taking into account the fact you can now use other compilers.)
You may be able to make a custom makefile project to solve this for you.
Visual Studio's mainstream scenario is to be an IDE for MS developer tools. The more common ways to compile using GNU tools under Windows is MinGW or Cygwin.
Use external build system. (Makefile project).
As far as I know, there's no way to accomplish this. cl is more or less integrated with Visual Studio.
I guess if you were really desperate, you could try creating a pre-build step that invokes gcc and then doing something to stop the Visual Studio build from occurring.
Related
What is MakeFile in Eclipse? From the documentation:
A makefile is a text file that is referenced by the make command that
describes the building of targets, and contains information such as
source-level dependencies and build-order dependencies. The CDT can
generate a makefile for you, such projects are called Managed Make
projects. Some projects, known as Standard Make projects, allow you to
define your own makefile.
But the explanation does not help me understand what a MakeFile is. I am moving from VisualStudio/C# to Eclipse/C++. Is MakeFile analogous to Visual Studio's Metadata? When do I need to write a MakeFile, and why do I need it besides the C++ code?
[EDIT]
I used to develop on Windows with VS and C#. And now trying Eclipse/C++ on a Mac. I have never build anyone on Linux. So the answer I have read so far does not help explain anything at all.
A makefile in the simplest terms is a file that builds a program. These are normally used from the command line. If you have ever built something on linux you may have run ./configure ; make ; make install. You are using a makefile there.
More info...
https://en.wikipedia.org/wiki/Make_(software)
In simple terms: Make helps you create cross-platform configuration settings in one file, and it will work on surprisingly many platforms, including Windows or Mac OS-es.
Mentioning Windows, you should have Make installed on the computer you're installing on (on Windows, Cygwin and MinGW include Make). It's required only if the user will actually build the code from the source.
But of course, you should include Make code for each different platform (e.g. one for Unix-like, one for Windows, etc.)
I've developed a tool in C++, using Visual Studio 2010, which I'd like to deploy on Linux systems as well. The code itself is programmed entirely platform-independent, using only the STL and the standard library.
Now my problem is: I don't have experience with Linux.
I have, however, tried to get some other programs I wrote to compile using GCC, and the results were a truckload of errors being thrown at me, which took me 3 hours to resolve - the horrors!
Noting from this experience I think that the same is about to happen, just a lot worse, if I try to port my current project to GCC.
My questions are:
What does a Visual Studio user need to know to successfully get their program running on Linux?
(do I need to learn make?)
Do you know of a good source which covers not the topic of GCC / Linux programming as a whole, but specifically the problem of switching from a Visual Studio environment?
I recommend skipping make altogether, its a rather old technology and you may face portability issues while using it. Instead, learn another build system like CMake http://www.cmake.org/ or SCons http://www.scons.org/
I use CMake myself and find it to be excellent. You write very simple build scripts (you can easily get started in an hour or two) and it generates the makefiles for you. The biggest advantage is that it can generate makefiles for almost any compiler or build system you could want. It can generate standard unix makefiles, Microsoft Visual C++ Projects, XCode Projects, Code::Blocks projects, even KDevelop and Eclipse CDT4 projects.
I haven't used SCons myself, but I do know that it actually builds your program for you and runs on python.
Getting started in Linux/Unix can really mean anything you want. Going from Visual Studio can mean going to Eclipse or another IDE, which is as simple as learning the new IDE, or it can mean going straight to the shell and forgetting you ever knew what an IDE looked like. My personal recommendation is to stick with the IDE- Eclipse is great as an industry standard and its very cross-platform (just get the CDT plugin).
On the topic of the GCC, you probably won't really be invoking it yourself very much if you're writing CMake scripts since CMake will generate the makefiles. The simplest command line arguments are:
g++ <source-files> -o <output-name> -I <another include directory> -l <library to link to>
as an example:
g++ helloworld.cpp -o world.out -I /usr/include -l mylib
To run an executable from the shell, navigate to the directory its in and type:
./world.out
Note that the default output when invoking g++ (i.e. g++ helloworld.cpp) is a.out.
And that's all you really need to know! The rest comes easily. You'll learn to love Unix, and I really recommend learning the shell even if you do go the path of the IDE. It can make your life alot easier.
EDIT: So to port your program to Linux and the GCC with CMake, here's what you would do:
Get CMake
Write the CMakeLists.txt file in your source directory (its the Makefile format CMake uses)
Invoke CMake on the directory. CMake will parse the CMakeLists.txt file automatically and generate build scripts of your choice
Build with whatever build system you used. If you're using standard Unix Makefiles, it'll mean just navigating to the build directory and typing make into the shell
Your project will be built and youre done!
P.S: I never learned normal make, although it definitely has its uses. CMake found an eager user in me.
i was going to say "man g++" but that manual is very long in lines.
just type
g++ main.cpp utility.cpp
g++ will automatically compile and link main.cpp, utility.cpp into a file named a.out
type ./a.out into command line to run the compiled code.
you won't need to learn make, but if you do, simple make scripts only take 4-5 lines of code. It's pretty easy to type in, but it's actually pretty different for a visual studio user, so it's completely non-friendly if you put bad code your Makefile.
about learning linux, there's a lot to learn. I can't even tell you where to start, but there's no secrets. Not like Microsoft products where you have to learn the workaround to make your code run.
oh and here's g++ info: http://homepages.gac.edu/~mc38/2001J/documentation/g++.html
i have source code of vc++ project. Now I am using linux.
i know how compile a single file .cpp not a whole project. So how to compile a VC project using g++ ?
A slight advantage of Makefiles would be possible integration with autotools (cough - It might prove handy to get the starting point for feature macros).[2]
There is a tool as part of winemaker that is EXCEEDINGLY helpful with fixing up a source tree that was assuming case insensitive names to work on a case-sensitive filesystem. (_it was intended mainly in order to build against winelib but that is not required)
If you want to keep using windows API's for some parts of the code, you can consider compiling with winelib (and use winegcc, producing WIN32 executables; I'm not sure whether this is what you want)
[2]: SCons is a very nice tool though
First step would be to generate Makefile out of vcproj file.
There are (obviously) some tools for that:
http://www.codeproject.com/KB/cross-platform/sln2mak.aspx
There is no easy way to do it. As others have suggested you can figure out how the build process works for this project (maybe by reading the build output in VS) and recreate that using your favorite linux build tool (scons, cmake, autotools etc.). The alternative is to use a converter tool. Aside from the below mentioned sln2mak, there is also winemaker. The docs for winemaker have a lot of old info like most linux tools docs but it can convert a .sln to a makefile. I am not sure about newer vs .sln files.
I have checked in buid directory and have not found makefile there. How does Visual Studio 2008 buid the project? Does it use makefile?
The NMAKE utility has been distributed with Visual C++ since back when it was called Microsoft C/C++ Optimizing Compiler, and is very similar to Unix make. Previous versions of the IDE actually used NMAKE makefiles, but this isn't true anymore. You can write NMAKE makefiles yourself if you want, but it sounds like you want to know what the IDE does.
Starting with VS2010, the build system changes to MSBUILD, which bertelmonster mentioned. But not in VS2008.
In VC++ 6.0, C++ projects have their own build engine integrated into msdev.exe.
In VS2002 - VS2008, it's a separate tool, VCBUILD. But you can still invoke it via the main IDE, devenv.exe, see the /BUILD option, and devenv is the best way if you have inter-project dependencies in your solution.
VS9 doesn't use makefiles by default the way Linux-flavored IDEs might. Instead, VisualStudio uses 'solution' and 'project' files. A Project file (*.vcproj for C/C++ projects) is basically a replacement for makefiles, and contains instructions, compiler directives, flags and everything else needed to compile a single 'project'. In this parlance, a project is a single output file, such as an EXE or DLL. But this same mechanism can be used to produce any kind of output, including TLBs, text files, widgets and ice cream cones (if your machine has the capable hardware :) )
A 'solution' is a collection of projects, and the solution file (*.sln) contains lists of projects needed to build an entire application suite, typically. It also contains dependancy information, so that the projects are built in the correct orders.
Solution and project files are human-readable text, but in the VS world you would virtually never want to edit these files yourself the way you would tweak a makefile by hand. Instead, you would use the IDE to change compiler flags, preprocessor directives, output directories, and all the rest.
That is how VS works by default, but VS is also capable of using makefiles in much the same way as Linux-flavored IDEs. It still uses solution files in this case, so you can mix projects that use makefiles with projects that use project files within the same solution. The VS IDE is actually quite powerful in this regard, and gives you the ability to do pretty much whatever you want. This power however comes with a price -- with so many features and capabilities available in the IDE, it can be rather complex and takes what you might think is an unwarranted ammount of user brainpower to fully understand.
If you want to create a makefile project, you can do so by doing File>New>Project... and then selecting Makefile Project from the main Visual C++ list of project templates.
So I have a visual studio 2008 project setup for a project I've been working on however its a sub project of a rather larger code base which is crossplatform, so in order to make my project complaint with the main source I need to make my project nix compilable.
Is there some way I can generate a makefile based off my vcproject? or if not is there someway I could generate a makefile any other way than writing it manually as it appears confusing as all hell when I open them up.
Microsoft has dropped the support for exporting a solution into a makefile (see this thread). I'm not aware of any external tools that convert VS solutions to makefiles.
But i had some success using CMake. With CMake you describe a project in a textfile and cmake then generates standard makefiles or project descriptions for IDE's (including VS).
Nobody ever writes a Makefile. They take an existing Makefile and modify it.
Get one of the makefiles from the existing projects and adjust it to your project (i.e. replace project name, source/object files, etc).
Other than that, simple makefiles are not so difficult, here's a very short introduction to makefiles to get you started.