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

  1. #16
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    Man, this thread is just saddening. When a whole group of people (the OP and her colleagues) involved with high-performance computing can't even determine, let alone expand on a basic "gcc files -o outFile" pattern to compile multiple files with gcc, what hope is there?

  2. #17
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by adeyblue View Post
    what hope is there?
    Too much hope !
    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.

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I want to smack that colleague -_-
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Elysia View Post
    I do believe

    gcc a.cpp b.cpp c.cpp ... -o MyExe.exe

    Don't forget to include

    -std=c++0x -pedantic -Wall

    at the very least.
    -pedantic is usually a little overkill. -Wall and -Wextra are sufficient most of the time.

    and on G++ 4.1, the -std=c++0x option is not available. it did not become available until 4.3.

  5. #20
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You don't need to quote all that since I edited it out on purpose.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #21
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    sorry, I quoted before you edited, and posted after. not my fault.

  7. #22
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You can change your quote while you still have the ability to edit -_-
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #23
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    I'm not going to argue this point except to say that it doesn't detract from the conversation to leave it fully quoted, nor does it help anyone for me to edit it, so unless you can convince a moderator, it stays as is.

  9. #24
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Ugh. Fine. Have it your way.
    I have reported this incident to a moderator.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #25
    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