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

    Compiling Visual C++ code using a different compiler

    I have a system of C++ code that was written using Visual C++ 2008 Express Edition. I need to run this code on a high-performance cluster that doesn't allow compilation with Visual C++; instead, the following compilers are available:

    Gnu compilers 4.1
    Intel compilers 11.1.056
    PGI compilers 10.5
    Java-1.6.0 -openjdk
    Python 2.7.1

    I was advised to check my code for any dependencies on the Visual C++ compiler, so that I can instead one of the above compilers. However, I'm not sure what to look for, that would indicate a Visual C++ dependency. Any suggestions?

    Also, from the list above, is there one specific compiler that would be the best choice, if I'm switching from Visual C++ code to a new compiler?

    Thanks! (I can post a more detailed description of my code system, if more specifics are needed.)

  2. #2
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    A good start might be to add /Za as a compiler option (or Project Properties -> C/C++ -> Language -> Disable Language Extensions:Yes).
    Consider this post signed

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    67
    Thanks for the suggestion, bernt. I made this change, and recompiled the code; it worked! That's definitely a good sign. I suppose that my next step is to try compiling the code on the cluster, using one of the other compilers.

    Does anyone have input about which of the compilers I listed in my OP would be my best choice, or are they all basically equivalent?

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Is Gnu compilers GCC? If so, then yes. GCC is very good.
    Intel is supposed to be good, too, at least on the optimizing part.
    The rest, I don't know.
    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.

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    It's probably more important that you pick one, Kate. The choice between the first three really depend on what license terms you need. Whichever ones you choose, you will need to exercise test cases to confirm that the program is still working as intended. Even if code compiles with multiple compilers/systems there are still things (such as binary I/O) that may work with one compiler but not another. So you need to confirm that the program works when recompiled, not just assume it.

    openjdk and Python are not C++ compilers.
    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.

  6. #6
    Registered User
    Join Date
    Jun 2010
    Posts
    67
    Thanks for your input, Elysia & grumpy. Yes, the Gnu compilers include GCC. I think I'm going to give the GCC a try, and I'll be sure to confirm that the code remains functional with the new compiler.

  7. #7
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Note that the Intel compiler, while generating code that sometimes runs a bit faster (than GCC output) on Intel CPUs, arguably intentionally generates much worse code for non-Intel CPUs.

    Agner`s CPU blog - Intel's "cripple AMD" function

  8. #8
    chococoder
    Join Date
    Nov 2004
    Posts
    515
    Quote Originally Posted by cyberfish View Post
    Note that the Intel compiler, while generating code that sometimes runs a bit faster (than GCC output) on Intel CPUs, arguably intentionally generates much worse code for non-Intel CPUs.

    Agner`s CPU blog - Intel's "cripple AMD" function
    much more likely they are able to perform undocumented optimisation routines for Intel CPUs but not for 3rd party CPUs, making the compilation unit perform better on Intel than other platforms.
    I seriously doubt Intel would put their corporate reputation at stake by deliberately generating compilation units so as to perform poorly on non-Intel hardware.

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by jwenting View Post
    much more likely they are able to perform undocumented optimisation routines for Intel CPUs but not for 3rd party CPUs, making the compilation unit perform better on Intel than other platforms.
    I seriously doubt Intel would put their corporate reputation at stake by deliberately generating compilation units so as to perform poorly on non-Intel hardware.
    You obviously don't know Intel as well as you think you do. I'd recommend you read that article and google a little on anti-trust complaints against Intel. They have tried to use illegal or poor business practices before.
    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. #10
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    much more likely they are able to perform undocumented optimisation routines for Intel CPUs but not for 3rd party CPUs, making the compilation unit perform better on Intel than other platforms.
    I seriously doubt Intel would put their corporate reputation at stake by deliberately generating compilation units so as to perform poorly on non-Intel hardware.
    It has nothing to do with undocumented optimizations. The article linked has a good explanation of what they did.

  11. #11
    Registered User
    Join Date
    Mar 2009
    Posts
    344
    Note that there are several versions of GCC available for Windows systems. Look up cygwin or mingw for specifics. Installing them would allow you to compile & debug the code on your windows system before you had to move it over to another system. There's never a guarantee, but if it works on GCC w/ Windows there's at least a better chance of it porting over to GCC w/ whatever cleanly.

  12. #12
    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).

  13. #13
    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.

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    What? You mean replacing all include statements with the actual files contents?
    That's silly. You don't need to do that with any compiler.
    Just compile all the .cpp files. Any good IDE will be able to do that for you. Code::Blocks, for example, works with GCC.
    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.

  15. #15
    Registered User
    Join Date
    Jun 2010
    Posts
    67
    What? You mean replacing all include statements with the actual files contents?
    That's silly. You don't need to do that with any compiler.
    Just compile all the .cpp files. Any good IDE will be able to do that for you. Code::Blocks, for example, works with GCC.
    When you say, "just compile all the .cpp files": if the statement that works to compile the single main.cpp file is:

    gcc main.cpp -o myExecutable

    ...what would your suggested alternative compile statement look like?

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