Thread: Compiling Visual C++ code using a different compiler

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    67
    Thanks for the additional input. Given my previous good experiences with GCC, and cyberfish's caution about the Intel compiler, I'm planning to stick with the GCC compiler. I just learned that one of my colleagues has had experience with making the switch from Visual C++ to GCC, and recommended that instead of using numerous individual files, I should simply replace all of the "include" statements in main.cpp, with the actual files' contents -- he's able to compile on GCC using this method (and hasn't discovered any simpler way to do it that works).

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by CodeKate View Post
    I just learned that one of my colleagues has had experience with making the switch from Visual C++ to GCC, and recommended that instead of using numerous individual files, I should simply replace all of the "include" statements in main.cpp, with the actual files' contents -- he's able to compile on GCC using this method (and hasn't discovered any simpler way to do it that works).
    He hasn't looked too hard. His advice is close to the worst that I've ever seen an experienced programmer give to a (presumably) less experienced programmer.

    Leave the source files and headers alone. The only things you should need to change in them are related to any language or library features that are specific to VC++ (for example, pragmas, using VC++ specific libraries). Any such changes (other than pragmas) would be picked up when you compile the source files (before doing any modifications to them).

    If you are using an IDE that supports gcc (such as code::blocks or eclipse) create a new project and simply add the source files to the project. This is akin to how you will have created the project in VC++ (assuming you used the IDE), but the specific details are different (the techniques for creating "project files" are IDE specific).

    If you are using a command line version of gcc, you have two workable choices. The first is to create a script (under windows this might be a BAT file) that simply compiles the source files in sequence, and then links them.

    The second option if you are using a command line version of gcc - and the one I would suggest in the long run - is to look up the unix make command (as a version of this is typically distributed with gcc distributions under windows). The syntax for creating a makefile (the input file to make) takes a little effort to learn, has specific features for orchestrating compiling multiple source files in a project in order to create libraries and executables.

    Whether you are using an IDE or a command line compiler, you will need to do some homework to learn how to build projects. But the effort is worth it. You should never need to "replace all of the "include" statements in main.cpp, with the actual files' contents".
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling preprocesed code in Visual Studio 2008
    By SolidSnake745 in forum C Programming
    Replies: 7
    Last Post: 02-23-2011, 10:19 AM
  2. compiling C code at visual C++ 6.0
    By hattusili in forum C Programming
    Replies: 7
    Last Post: 02-10-2008, 01:26 PM
  3. Replies: 2
    Last Post: 02-04-2008, 02:34 AM
  4. compiling c code in c++ compiler..???Noob
    By roalme00 in forum C Programming
    Replies: 2
    Last Post: 06-30-2007, 07:25 AM
  5. Compiling in Unix vs Visual C++
    By stimpyzu in forum C++ Programming
    Replies: 2
    Last Post: 09-30-2002, 06:41 AM

Tags for this Thread