简体   繁体   中英

Compiling from Visual Studio 2012 to g++?

I have a c++ program compiled in Visual Studio 2012. It contains the boost library. Now, I want to compile this using the g++ compiler. What are the things I must be aware of? Things that will most likely silently break my code in random places.

For example I was always assuming long is 4 bytes buy g++ treats this as 8 bytes. For this alone I need some changes.

And what version of gcc to use, 4.7.3, 4.6.4 or 4.8.2?

如果你在没有使用特定库的情况下编写有效且优秀的C ++代码,那么你应该什么都不知道。

Some of the things that you have to keep in mind. This list is not comprehensive but are those things that are on top of my mind when I read your question.

  1. pragma once : When using g++, you should gaurd file inclusion by using #ifndef, #define and #endif guards.

  2. Header inclusion : VS 2012 is very lenient and does not make a fuss of forward or backward slash while including headers. g++ will be strict in enforcing them.

  3. If you are using Win32 threads / mutex, it is best to shift to std::thread. If you are using boost for threads, you are OK.

The version of gcc you can use and get away with depends on your usage of C++11 features. gcc was always ahead of Microsoft in implementing C++11 features and you should be OK with an older version of gcc too. I cannot answer this question unless I understand what c++11 features you are using in your code. It is safe to say that the more recent version of gcc will surely support what is available in Vs 2012.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM