As I wrote previously, finding the right C/C++ IDE (other than VC Express) was not easy for me, and my last settlement was with Eclipse CDT. So porting Candle source code to other compiler and IDE on Windows, like MinGW, was not of high priority for me.
I was googling for something (I don't remember what it is) and one of the result page recommended CodeLite, and triggered me to give CodeLite a trial.
Importing the ProjectsAfter I installed CodeLite, I was able to import MSVC solution and projects without any problem. There's only one small annoyance. CodeLite imports my C/C++ source files under a default virtual directory 'src'. It seems be a restriction in CodeLite that source file must be under some virtual directory, as it does not allow me to have source files directly under a project.
Compiling the Source CodeI was able to compile with almost no change to the source code. The only changes that I can remember were:
- some typedefs for int64, and uint64, etc;
- macro for dll export/import declaration;
#if _WINDOWS #undef DLLDECL #define DLLDECL __declspec(dllexport) #endifThe source code of this module was able to compile without any problem. But when I compiled another module that depends on this one, all symbols exported from this module were not visible to that importing module. I had to take out source files one by one to finally nail down the cause of the linking problem to these few lines.
The cause of the problem was that GCC accepts MSVC's syntax of dll export declaration, __declspec(dllexport), but the symbols are not really exported. I really hate this kind of half-baked solution. GCC should either reject MSVC's syntax or if it determines to support such it, than it should support both the syntax and semantic properly.
Linking the Source CodeThere were a few linking options that needed to be specified for GCC to link properly, including:
- Library import path and Libraries; CodeLite's default conversion was not accurate;
- -Wl,--out-implib,module.a to export the import library;
- -Wl,-subsystem,windows to compile the main executable as Windows GUI program;
The Final ExecutionI was really AMAZED that the compiled executable ran smoothly on the first shoot. NO CRASH! No unexpected execution result, all test cases (although not many) passed. I really did not expect the execution to be so smooth. I thought I would have do some runtime debugging to fix some tricky porting bugs before the whole system runs properly.
This reflects a few things:
- Firstly, MinGW is indeed a CLEAN replacement for MSVC on Windows as long as you stick to standard C/C++ features and Win32 API (don't expect MinGW to support MFC/ATL/WTL/COM/ActiveX out-of-box). I even checked the compiled binary with Dependency Walker, and no extra GCC-specific DLLs were introduced.
- Candle source code is indeed highly portable;
- CodeLite works reasonably well as a C/C++ IDE:
- Pros of CodeLite:
- Able to refactor C/C++ source code (though I have not tried it out);
- Cons of CodeLite:
- The debugger is not as friendly as MSVC (this is probably more related to GCC);
- The Subversion integration seems to conflict with TortoiseSVN;
- The GUI is noisier than Eclipse CDT or MSVC. For example, in the GUI, we can see names of integrated components like BuildQ, CScope, CppCheck, SnipWiz. I think it is sufficient to just mention these names in the license or other documentation. Putting these names in the GUI is simply distracting. Instead more general names should be used.
- the 1st day to install CodeLite, importing MSVC solution, reading CodeLite documentation and getting used to its GUI;
- the 2nd day to really get hands dirty and fix all the compiling and linking problems. I manged to fix the dll export/import declaration bug at the late night of that day (or probably early morning of the 3rd day), and saw the entire Candle program running nicely at the end. It was a hard-working day for me, but also a rewarding day for me;
- the 3rd day to clean up the mess. I figured out how to get the debugger working, and linked the main program with the icon resource file;
- knows what C/C++ features to use and what to avoid;
- keep your dependencies under tight control;