3

I'm trying to determine if it is possible to use MinGW to compile code that requires Microsoft Foundation Classes (MFC) or Active Templace Libraries (ATL), libraries that come with Microsoft Visual C++ (MSVC).

Some context: My end goal is to be able to generate gcov reports on Windows for a C++ tool. The code contains many codepaths which will only be reached if built on Windows (i.e. section guarded by #ifdef _WIN64). This means I need to build an .exe with gcc. The reason I want to do this? I'd like to get a more complete code coverage result by running tests on Windows so that these codepaths can be tested for coverage as well. Is this viable in anyway?

This is what I've tried. Starting small, I've been trying to get this program to build using MinGW on Windows:

#include <iostream>
#include <atlstr.h>


int main() {
    CString aCString = CString(_T("A string"));
    _tprintf(_T("%s"), (LPCTSTR)aCString);
}

This compiles with MSVC with no hassle. Now, with MinGW: To build I just call gcc -fprofile-arcs -ftest-coverage test.cpp -o test. However, it fails with the following message:

test.cpp:3:10: fatal error: atlstr.h: No such file or directory
 #include <atlstr.h>
          ^~~~~~~~~~
compilation terminated.

This is expected of course. I found all the ATL, including atlstr.h, in C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\atlmfc\include, and copied that all to one of the directories MinGW looks for includes. This time it found the header files but a huge list of errors came up which I probably shouldn't include here.

Sakeeb Hossain
  • 662
  • 5
  • 19
  • 2
    You don't need to build with g++ to get code coverage data. There are quite a few tools to get you code coverage data with MSVC builds. For one example, [OpenCppCoverage](https://github.com/OpenCppCoverage/OpenCppCoverage). – Jerry Coffin Sep 10 '19 at 17:32
  • 4
    Trying to compile/build MFC/ATL code with non-MSVC compliant compilers is probably one of the fastest routes to insanity! First, the headers are full of non-standard code; second, the linked library (.lib or .dll) files will almost certainly ***not*** be binary compatible with third-party linkers. – Adrian Mole Sep 11 '19 at 15:01
  • 1
    Got it, so I'm wasting my time. Will look into OpenCppCoverage and other alternatives. Thanks guys! – Sakeeb Hossain Sep 11 '19 at 18:19

0 Answers0