Error relating to C++ compiler when running ./configure on Windows

I am encountering the following error on my Windows 7 desktop.
I followed the Windows installation instructions and all went well through cloning the MRtrix3 repository.
When trying to build the MRtrix, I type

cd MRtix3 
./configure

I get an error stating that a compatible C++11 compiler has not been found. configure.log text is pasted below:

REPORT: 
MRtrix build type requested:

REPORT: release

REPORT: 

REPORT: Detecting OS: windows

REPORT: Checking for C++11 compliant compiler [g++]:
EXEC <<
CMD: g++ -dumpversion
error invoking command "g++": No such file or directory: 'g++'
>>


ERROR: compiler not found!

  MRtrix3 was unable to find an appropriate C++11 compiler.

  Set the CXX environment variable to inform 'configure' of the path to the
  compiler on your system, as follows:
    $ export CXX=/usr/bin/g++-5.5
    $./configure
  (amend with the actual path to the compiler on your system)


  See the file 'configure.log' for details. If this doesn't help and you need
  further assistance, please post on the MRtrix3 community forum
  (http://community.mrtrix.org/), and make sure to include the full contents of
  the 'configure.log' file.

The “configure.log” file contains exactly the same text as the error message (the above was actually copied from the configure.log file) and nothing else.

I’m very new to this (mostly have previous experience of “point and click” computing) so I’m not sure which file/folder to point the CXX command to. I cannot find anything called “g++”, the only thing I’ve found that I think might contain a C++ compiler is a folder called “gcc”, but again, I’m not sure of which file within this folder to point the CXX towards.

Hi there,

It’s unusual for g++ to not be present in your path if this line from the installation instructions worked successfully:
pacman -S git python pkg-config mingw-w64-x86_64-gcc mingw-w64-x86_64-eigen3 mingw-w64-x86_64-qt5
Are you definitely sure that this step worked?

Otherwise, if you can see a directory called gcc (hopefully in /usr/local/ or similar location), you want to set the CXX environment variable to the path to a binary in that directory that starts with g++: it could be g++, g++-5, g++-5.5 or some variant thereof.

If you’re still stuck, you can try running this and providing us with the output:
pacman -Ql mingw-w64-x86_64-gcc
That should print a list of the files provided by the gcc package.

Cheers
Rob

Thanks very much,
I didn’t get any error messages when I ran the above step so I believe it worked.
I did manage to find the g++ file (although it was not in the gcc folder confusingly enough). I set the CXX variable to the file path for the file as follows:
$ export CXX=C:/msys64/mingw64/bin/g++
This allowed the program to detect the g++ but then the compiler test failed. Configure log text is below:

REPORT: 
MRtrix build type requested:

REPORT: release

REPORT: 

REPORT: Detecting OS: windows

REPORT: Checking for C++11 compliant compiler [C:/msys64/mingw64/bin/g++.exe]:
EXEC <<
CMD: C:/msys64/mingw64/bin/g++.exe -dumpversion
EXIT: 0
STDOUT:
6.1.0
>>


REPORT: 6.1.0

COMPILE /tmp/tmp58deenlk.cpp:
---

struct Base {
    Base (int);
};
struct Derived : Base {
    using Base::Base;
};

int main() {
  Derived D (int); // check for contructor inheritance
  return (0);
}

---
EXEC <<
CMD: C:/msys64/mingw64/bin/g++.exe -c -std=c++11 -pthread -DMRTRIX_WINDOWS -mms-bitfields -Wa,-mbig-obj -march=native /tmp/tmp58deenlk.cpp -o /tmp/tmp58deenlk.o
EXIT: 1
>>

error deleting temporary file "/tmp/tmp58deenlk.o": No such file or directory
ERROR: compiler test failed!

  MRtrix3 was unable to compile a simple C++ program.

  Set the CXX environment variable to inform 'configure' of the path to the
  compiler on your system, as follows:
    $ export CXX=/usr/bin/g++-5.5
    $./configure
  (amend with the actual path to the compiler on your system)

  If you are using a compiler other than gcc, you can also set the CXX_ARGS
  environment variable to specify how your compiler expects different arguments
  to be presented on the command line, for instance as follows:
    $ export CXX_ARGS="-c CFLAGS SRC -o OBJECT"
    $ ./configure


  See the file 'configure.log' for details. If this doesn't help and you need
  further assistance, please post on the MRtrix3 community forum
  (http://community.mrtrix.org/), and make sure to include the full contents of
  the 'configure.log' file.

Any further advice would be greatly appreciated.
Cheers,
Tom

I had issues like this at one point, which I eventually tracked down to using the wrong shell. MSYS2 provides 3 shells, and for things to work we need the MinGW-w64 Win64 Shell. Are you sure you’re starting up with this shell when you start the terminal?

(Sorry I keep editing your posts, but surrounding the logs with [code][/code] makes them much more readable)

OK, that’s an unusual one. Though I do have some vague recollection of having had GCC version 6 installed with MSYS2 and having to revert to version 5…

If necessary I’ll try to reproduce tonight and give you more precise instructions (and update the documentation). But what I think you need to do is uninstall GCC version 6, find a package for GCC version 5, and install that.

  • To remove version 6: pacman -R mingw-w64-x86_64-gcc

  • To install version 5 will require a bit of searching around. You can try: pacman -Ss gcc: That should give you a list of available packages that contain ‘gcc’ in the name. Look for something that has the version number (5) in the title, or anything that has msys2 rather than mingw at the start of the package name. If nothing there works, you could maybe try mingw-w64-x86_64-toolchain instead of mingw-w64-x86_64-gcc. You may have to update (or just erase) the CXX environment variable so that the newly installed program is found. The CXX_ARGS variable won’t be of any use to you: that’s there for compilers other than gcc.

Make sure you check @jdtournier’s instruction too. Note that this suggestion applies not only to which shell you use, but also that the shell shortcuts need to be updated following the update-core step in the instructions.

Thanks very much to you both.
I am using the correct shell, and I have reset the shortcuts as instructed (although that also took me a while to figure out).
I’ll try uninstalling GCC version 6 and replacing it overnight and let you know how I go.

Thanks again,
Tom

I managed to find gcc version 5.3.0-3 in msys and install it.
That appears to have fixed the C++ compiler problem but now I get an error at the next step of the configure process (detecting pointer size).

Configure log is below (and I’ve hopefully got the (code) surrounding correct, apologies if not.


REPORT: 
MRtrix build type requested:

REPORT: release

REPORT: 

REPORT: Detecting OS: windows

REPORT: Checking for C++11 compliant compiler [C:/msys64/usr/bin/gcc]:
EXEC <<
CMD: C:/msys64/usr/bin/gcc -dumpversion
EXIT: 0
STDOUT:
5.3.0
>>


REPORT: 5.3.0

COMPILE /tmp/tmpvpm1i_p7.cpp:
---

struct Base {
    Base (int);
};
struct Derived : Base {
    using Base::Base;
};

int main() {
  Derived D (int); // check for contructor inheritance
  return (0);
}

---
EXEC <<
CMD: C:/msys64/usr/bin/gcc -c -std=c++11 -pthread -DMRTRIX_WINDOWS -mms-bitfields -Wa,-mbig-obj -march=native /tmp/tmpvpm1i_p7.cpp -o /tmp/tmpvpm1i_p7.o
EXIT: 0
>>

EXEC <<
CMD: C:/msys64/usr/bin/gcc /tmp/tmpvpm1i_p7.o -pthread -Wl,--allow-multiple-definition -o a.out
EXIT: 0
>>

EXEC <<
CMD: ./a.out
EXIT: 0
>>


REPORT:  - tested ok

REPORT: Detecting pointer size:

COMPILE /tmp/tmp1b891ftg.cpp:
---

#include <iostream>
int main() {
  std::cout << sizeof(void*);
  return (0);
}

---
EXEC <<
CMD: C:/msys64/usr/bin/gcc -c -std=c++11 -pthread -DMRTRIX_WINDOWS -mms-bitfields -Wa,-mbig-obj -march=native /tmp/tmp1b891ftg.cpp -o /tmp/tmp1b891ftg.o
EXIT: 0
>>

EXEC <<
CMD: C:/msys64/usr/bin/gcc /tmp/tmp1b891ftg.o -pthread -Wl,--allow-multiple-definition -o a.out
EXIT: 1
STDERR:
/tmp/tmp1b891ftg.o:tmp1b891ftg.cpp:(.text+0x1a): undefined reference to `std::ostream::operator<<(unsigned long)'
/tmp/tmp1b891ftg.o:tmp1b891ftg.cpp:(.text+0x1a): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `std::ostream::operator<<(unsigned long)'
/tmp/tmp1b891ftg.o:tmp1b891ftg.cpp:(.text+0x4e): undefined reference to `std::ios_base::Init::Init()'
/tmp/tmp1b891ftg.o:tmp1b891ftg.cpp:(.text+0x4e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `std::ios_base::Init::Init()'
/tmp/tmp1b891ftg.o:tmp1b891ftg.cpp:(.rdata$.refptr._ZNSt8ios_base4InitD1Ev[.refptr._ZNSt8ios_base4InitD1Ev]+0x0): undefined reference to `std::ios_base::Init::~Init()'
/tmp/tmp1b891ftg.o:tmp1b891ftg.cpp:(.rdata$.refptr._ZSt4cout[.refptr._ZSt4cout]+0x0): undefined reference to `std::cout'
collect2: error: ld returned 1 exit status
>>

error deleting temporary file "a.out": No such file or directory
ERROR: unable to determine pointer size!

  See the file 'configure.log' for details. If this doesn't help and you need
  further assistance, please post on the MRtrix3 community forum
  (http://community.mrtrix.org/), and make sure to include the full contents of
  the 'configure.log' file.

Any ideas? I’m not 100% confident I installed the gcc compiler correctly but it looks like the system detected and tested the compiler successfully so hopefully this is no longer the problem.

Thanks again,
Tom

Ah yes. This is something I’ve been meaning to look into more closely. In my personal experience, configure on Windows often fails at the pointer size detection step the first time, but if you simply re-run configure a second time, it then works. Can you try simply running it a few times?

That eventually worked after I exited the shell and re-opened it.

The compiler then encountered an error attempting to test zlib:


REPORT: 
MRtrix build type requested:

REPORT: release

REPORT: 

REPORT: Detecting OS: windows

REPORT: Checking for C++11 compliant compiler [g++]:
EXEC <<
CMD: g++ -dumpversion
EXIT: 0
STDOUT:
5.3.0
>>


REPORT: 5.3.0

COMPILE /tmp/tmpki_bodgh.cpp:
---

struct Base {
    Base (int);
};
struct Derived : Base {
    using Base::Base;
};

int main() {
  Derived D (int); // check for contructor inheritance
  return (0);
}

---
EXEC <<
CMD: g++ -c -std=c++11 -pthread -DMRTRIX_WINDOWS -mms-bitfields -Wa,-mbig-obj -march=native /tmp/tmpki_bodgh.cpp -o /tmp/tmpki_bodgh.o
EXIT: 0
>>

EXEC <<
CMD: g++ /tmp/tmpki_bodgh.o -pthread -Wl,--allow-multiple-definition -o a.out
EXIT: 0
>>

EXEC <<
CMD: ./a.out
EXIT: 0
>>


REPORT:  - tested ok

REPORT: Detecting pointer size:

COMPILE /tmp/tmpussq0924.cpp:
---

#include <iostream>
int main() {
  std::cout << sizeof(void*);
  return (0);
}

---
EXEC <<
CMD: g++ -c -std=c++11 -pthread -DMRTRIX_WINDOWS -mms-bitfields -Wa,-mbig-obj -march=native /tmp/tmpussq0924.cpp -o /tmp/tmpussq0924.o
EXIT: 0
>>

EXEC <<
CMD: g++ /tmp/tmpussq0924.o -pthread -Wl,--allow-multiple-definition -o a.out
EXIT: 0
>>

EXEC <<
CMD: ./a.out
EXIT: 0
STDOUT:
8
>>


REPORT: 64 bit

REPORT: Detecting byte order:

REPORT: little-endian

REPORT: Checking for variable-length array support:

COMPILE /tmp/tmp95sdma1g.cpp:
---


int main(int argc, char* argv[]) {
  int x[argc];
  return 0;
}

---
EXEC <<
CMD: g++ -c -std=c++11 -pthread -DMRTRIX_WINDOWS -mms-bitfields -Wa,-mbig-obj -march=native -DMRTRIX_WORD64 /tmp/tmp95sdma1g.cpp -o /tmp/tmp95sdma1g.o
EXIT: 0
>>

EXEC <<
CMD: g++ /tmp/tmp95sdma1g.o -pthread -Wl,--allow-multiple-definition -o a.out
EXIT: 0
>>

EXEC <<
CMD: ./a.out
EXIT: 0
>>


REPORT: yes

REPORT: Checking for non-POD variable-length array support:

COMPILE /tmp/tmp4umbpvnm.cpp:
---

#include <string>

class X {
  int x;
  double y;
  std::string s;
};

int main(int argc, char* argv[]) {
  X x[argc];
  return 0;
}

---
EXEC <<
CMD: g++ -c -std=c++11 -pthread -DMRTRIX_WINDOWS -mms-bitfields -Wa,-mbig-obj -march=native -DMRTRIX_WORD64 /tmp/tmp4umbpvnm.cpp -o /tmp/tmp4umbpvnm.o
EXIT: 0
>>

EXEC <<
CMD: g++ /tmp/tmp4umbpvnm.o -pthread -Wl,--allow-multiple-definition -o a.out
EXIT: 0
>>

EXEC <<
CMD: ./a.out
EXIT: 0
>>


REPORT: yes

REPORT: Checking for zlib compression library:

COMPILE /tmp/tmprk8n4biu.cpp:
---

#include <iostream>
#include <zlib.h>

int main() {
  std::cout << zlibVersion();
  return (0);
}

---
EXEC <<
CMD: g++ -c -std=c++11 -pthread -DMRTRIX_WINDOWS -mms-bitfields -Wa,-mbig-obj -march=native -DMRTRIX_WORD64 /tmp/tmprk8n4biu.cpp -o /tmp/tmprk8n4biu.o
EXIT: 1
STDERR:
/tmp/tmprk8n4biu.cpp:3:18: fatal error: zlib.h: No such file or directory
compilation terminated.
>>

error deleting temporary file "/tmp/tmprk8n4biu.o": No such file or directory
ERROR: error compiling zlib application!

  MRtrix3 was unable to compile a test program involving zlib.

  Set the ZLIB_CFLAGS environment variable to inform 'configure' of
  the flags it must provide to the compiler in order to compile
  programs that use zlib functionality; this may include the path to
  the zlib include files, as well as any required flags.
  For example:
    $ export ZLIB_CFLAGS="-isystem /usr/local/include"
    $./configure
  (amend with the actual path to the zlib include files on your system)

I can find a folder named zlib 1.2.8-3 in msys 64, along with a couple of other folders scattered around with zlib in the title.
Each of these folders that I’ve looked at so far has 3 files of about 1kb each, called “desc” “files” and “mtree”, respectively.

The configure log looks (to me) like the process failed when it couldn’t find a file called “zlib.h” there is such a file in msys64/mingw64/include when I do a normal Windows file search.

Thanks again for your time on this.

There’s not a lot I can suggest over and above the prompt provided by configure:

MRtrix3 was unable to compile a test program involving zlib.
  Set the ZLIB_CFLAGS environment variable to inform 'configure' of
  the flags it must provide to the compiler in order to compile
  programs that use zlib functionality; this may include the path to
  the zlib include files, as well as any required flags.
  For example:
    $ export ZLIB_CFLAGS="-isystem /usr/local/include"
    $./configure
  (amend with the actual path to the zlib include files on your system)

So if you found a candidate file in msys64/mingw64/include, you would try:

    $ export ZLIB_CFLAGS="-isystem /mingw64/include"
    $./configure

(since ‘msys64/’ will be the root directory within the MSYS2 file system)

I’m surprised things would fall over quite so spectacularly. I still think the issue is most likely to be the specific shell/terminal that you start with. On my system, I get the same ‘compiler not found’ error if I start with either the MSYS2 or MinGW Win-32 variants. Are you sure the shortcut you use to launch your terminal invokes the msys2_shell.cmd with the -mingw64 option? On my system looking into the properties of the shortcut, the Target field reads C:\msys64\msys2_shell.cmd -mingw64, and ./configure runs fine on that…

I also still remember installing MSYS2 very recently, and I can not stress enough you have to be super careful about following the instructions very, very carefully. At some points, you will have to close the terminal specifically before letting something continue, etc… and change the shortcuts to the terminals as well. To make matters even more challenging, I noticed not everything goes exactly as mentioned on that web page; so you have to combine those instructions with occasional extra instructions that actually appear on the terminal as you go. I’m not sure what happens if any specific step fails; but if (you suspect) it has, I reckon you’re better off uninstalling the whole everything and carefully trying all over again… :sweat:

Yes, I have to agree, getting MSYS2 installed has turned into a bit of a mess. It used to be pretty straightforward, but they’ve obviously made changes that make it really fiddly to update without breaking the entire system. I was hoping they’d release an updated installer to avoid users having to jump through all these hoops, but nothing’s happened so far… Maybe this is something we could try to fix up? Could we provide an up to date version of MSYS2…?

Thanks for all the advice.
I’ve tried pointing the ZLIB_CFLAGS variable to every possible candidate I could find and each time the result is identical.

With regard to the shortcut, it was missing the -mingw64 (the target just read “C:\msys64\msys2_shell.cmd”) but even after fixing this I seem to be having a very similar problem.

I think I will try uninstalling the whole lot and starting again.

Thanks again for your help.

Hi!
I have the same problem with the Eigen3 and I’ve already tried to reinstall and nothing.

MRtrix3 was unable to compile a test program involving Eigen3.
  Set the EIGEN_CFLAGS environment variable to inform 'configure' of
  the flags it must provide to the compiler in order to compile
  programs that use Eigen3 functionality; this may include the path to
  the zlib include files, as well as any required flags.
  For example:
    $ export EIGEN_CFLAGS="-isystem /usr/include/eigen3"
    $./configure
  (amend with the actual path to the Eigen3 include files on your system)

OK, it does look like there are issues with recent versions of MSYS2, as reported in this post and this one… Can I ask you to try the following:

  • bring your MSYS2 installation up to date (instructions here)

  • bring your MRtrix3 installation up to date:

    $ git checkout master 
    $ git pull
    
  • try running configure & build using the MSYS2 version of python (rather than the MinGW version):

    $ /usr/bin/python ./configure
    $ /usr/bin/python ./build
    

If that still doesn’t work, please post your configure.log file - it might give us a hint as to where the problem might be…