Build errors

Hi everyone,

I’ve come across some difficulties building the latest version of mrtrix (master branch). The error seems to pop up when building ‘release/cmd/mrmetric.o’

Here’s the output:

ERROR: (107/430) [CC] release/cmd/mrmetric.o

clang++ -c -std=c++11 -DMRTRIX_MACOSX -fPIC -DMRTRIX_WORD64 -DMRTRIX_NO_NON_POD_VLA -isystem /usr/local/Cellar/eigen/3.2.8/include/eigen3 -Wall -O2 -DNDEBUG -Isrc -Icmd -I./lib -Icmd -isystem /usr/local/Cellar/eigen/3.2.8/include/eigen3 cmd/mrmetric.cpp -o release/cmd/mrmetric.o

failed with output

cmd/mrmetric.cpp:310:15: error: call to member function 'push_back' is ambiguous
      headers.push_back (input1);
      ~~~~~~~~^~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:700:36: note: candidate function
    _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
                                   ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:702:36: note: candidate function
    _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
                                   ^
cmd/mrmetric.cpp:311:15: error: call to member function 'push_back' is ambiguous
      headers.push_back (input2);
/var/folders/5s/1w6ckppj22j_t40zptw363yw0000gv/T/tmpmbORuN 

ERROR: (107/430) [CC] release/cmd/mrmetric.o

clang++ -c -std=c++11 -DMRTRIX_MACOSX -fPIC -DMRTRIX_WORD64 -DMRTRIX_NO_NON_POD_VLA -isystem /usr/local/Cellar/eigen/3.2.8/include/eigen3 -Wall -O2 -DNDEBUG -Isrc -Icmd -I./lib -Icmd -isystem /usr/local/Cellar/eigen/3.2.8/include/eigen3 cmd/mrmetric.cpp -o release/cmd/mrmetric.o

failed with output

cmd/mrmetric.cpp:310:15: error: call to member function 'push_back' is ambiguous
      headers.push_back (input1);
      ~~~~~~~~^~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:700:36: note: candidate function
    _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
                                   ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:702:36: note: candidate function
    _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
                                   ^
cmd/mrmetric.cpp:311:15: error: call to member function 'push_back' is ambiguous
      headers.push_back (input2);
      ~~~~~~~~^~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:700:36: note: candidate function
    _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
                                   ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:702:36: note: candidate function
    _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
                                   ^
2 errors generated.

ERROR: ( 53/430) [CC] release/cmd/mrregister.o

clang++ -c -std=c++11 -DMRTRIX_MACOSX -fPIC -DMRTRIX_WORD64 -DMRTRIX_NO_NON_POD_VLA -isystem /usr/local/Cellar/eigen/3.2.8/include/eigen3 -Wall -O2 -DNDEBUG -Isrc -Icmd -I./lib -Icmd -isystem /usr/local/Cellar/eigen/3.2.8/include/eigen3 cmd/mrregister.cpp -o release/cmd/mrregister.o

failed with output

In file included from cmd/mrregister.cpp:22:
./lib/registration/nonlinear.h:88:23: error: call to member function 'push_back' is ambiguous
              headers.push_back (im2_image);
              ~~~~~~~~^~~~~~~~~
cmd/mrregister.cpp:770:23: note: in instantiation of function template specialization 'MR::Registration::NonLinear::run<MR::Registration::Transform::Affine, MR::Image<double>, MR::Image<double>, MR::Image<double>, MR::Image<double> >' requested here
      nl_registration.run (affine, im1_image, im2_image, im1_mask, im2_mask);
                      ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:700:36: note: candidate function
    _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
                                   ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:702:36: note: candidate function
    _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
                                   ^
In file included from cmd/mrregister.cpp:22:
./lib/registration/nonlinear.h:89:23: error: call to member function 'push_back' is ambiguous
              headers.push_back (im1_image);
              ~~~~~~~~^~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:700:36: note: candidate function
    _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
                                   ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:702:36: note: candidate function
    _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
                                   ^
In file included from cmd/mrregister.cpp:22:
./lib/registration/nonlinear.h:88:23: error: call to member function 'push_back' is ambiguous
              headers.push_back (im2_image);
              ~~~~~~~~^~~~~~~~~
cmd/mrregister.cpp:772:23: note: in instantiation of function template specialization 'MR::Registration::NonLinear::run<MR::Registration::Transform::Rigid, MR::Image<double>, MR::Image<double>, MR::Image<double>, MR::Image<double> >' requested here
      nl_registration.run (rigid, im1_image, im2_image, im1_mask, im2_mask);
                      ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:700:36: note: candidate function
    _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
                                   ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:702:36: note: candidate function
    _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
                                   ^
In file included from cmd/mrregister.cpp:22:
./lib/registration/nonlinear.h:89:23: error: call to member function 'push_back' is ambiguous
              headers.push_back (im1_image);
              ~~~~~~~~^~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:700:36: note: candidate function
    _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
                                   ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:702:36: note: candidate function
    _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
                                   ^
4 errors generated.

ERROR: (133/430) [CC] release/lib/registration/transform/initialiser_helpers.o

clang++ -c -std=c++11 -DMRTRIX_MACOSX -fPIC -DMRTRIX_WORD64 -DMRTRIX_NO_NON_POD_VLA -isystem /usr/local/Cellar/eigen/3.2.8/include/eigen3 -Wall -O2 -DNDEBUG -Isrc -Icmd -I./lib -Icmd -isystem /usr/local/Cellar/eigen/3.2.8/include/eigen3 lib/registration/transform/initialiser_helpers.cpp -o release/lib/registration/transform/initialiser_helpers.o

failed with output

In file included from lib/registration/transform/initialiser_helpers.cpp:20:
./lib/registration/transform/search.h:234:23: error: call to member function 'push_back' is ambiguous
              headers.push_back (im1);
              ~~~~~~~~^~~~~~~~~
./lib/registration/transform/search.h:151:40: note: in instantiation of member function 'MR::Registration::RotationSearch::ExhaustiveRotationSearch<MR::Registration::Metric::MeanSquaredNoGradient>::get_parameters' requested here
                ParamType parameters = get_parameters ();
                                       ^
lib/registration/transform/initialiser_helpers.cpp:194:18: note: in instantiation of member function 'MR::Registration::RotationSearch::ExhaustiveRotationSearch<MR::Registration::Metric::MeanSquaredNoGradient>::run' requested here
          search.run();
                 ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:700:36: note: candidate function
    _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
                                   ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:702:36: note: candidate function
    _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
                                   ^
In file included from lib/registration/transform/initialiser_helpers.cpp:20:
./lib/registration/transform/search.h:235:23: error: call to member function 'push_back' is ambiguous
              headers.push_back (im2);
              ~~~~~~~~^~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:700:36: note: candidate function
    _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
                                   ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:702:36: note: candidate function
    _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
                          

The output of my ./configure script is as follows:

Detecting OS: darwin
Checking for C++11 compliant compiler [clang++]: 4.2.1 - tested ok
Detecting pointer size: 64 bit
Detecting byte order: little-endian
Checking for variable-length array support: yes
Checking for non-POD variable-length array support: no
Checking for zlib compression library: 1.2.5
checking for Eigen 3 library: 3.2.8
Checking shared library generation: yes
Checking for Qt moc: moc (version 5.6.0)
Checking for Qt qmake: qmake (version 5.6.0)
Checking for Qt rcc: rcc (version 5.6.0)
Checking for Qt: 5.6.0

Any ideas what might be causing this?

Hi Kwan,

Looks like your compiler is a little more stringent than what was used in the development of the new registration tools; which in the long term is a good thing, since that line is indeed ‘ambiguous’ as the compiler states, and the two possibilities it has to choose from would yield very different results.

When ISMRM comes to a close, we’ll get to these errors (I don’t want to push a quick fix now since I’m not familiar with the code). Short-term, if you can get by without the particular commands that are causing the compilation issues, you can simply move the offending .cpp file out of the cmd/ directory, compile the rest of the code, then put it back.

Thanks for the report
Rob

Thanks for the response. I’ll await patiently for the fixes. Enjoy the meeting & singapore.

I can’t reproduce this on my Arch Linux system, whether I use g++ 5.3.0 or clang++ 4.2.1. My version of clang++ will differ somewhat from the MacOSX version since Apple do tweak it somewhat compared to the official version, so that might explain the difference. I don’t really see any ambiguity in the code here - this should work just fine, otherwise any use of .push_back() with copy- and move-constructible objects (i.e. pretty much anything) would yield this error. The fact that it works fine on the official clang release and g++ makes me wonder whether this is a bug within the MacOSX version of clang++… I don’t have a Mac, but maybe one of other devs can try to reproduce and see if there’s a simple fix…?

Just for the record: what clang++ seems to be complaining about is that the call:

headers.push_back (input1);

with the various classes defined as:

std::vector<Header> headers;
Image<double> input1;

is ambiguous, stating that (as far as I can tell):

std::vector<X>::push_back (const X& item);
std::vector<X>::push_back (X&& item);

are ambiguous when passing X as an lvalue.

This doesn’t seem to be correct - according to this StackOverflow post, X&& is a better match than const X&, and the compiler should use that version with no ambiguity. This tallies with the fact that g++ and the same version of clang++ on Linux accept the code as-is. So I suspect the issue lies with the modifications that Apple have made to clang++.

One other possibility is that the move semantics for some of the Image class members are non-trivial and hence introduce ambiguity in some way. There are two std::vector<ssize_t> in there (for the indices and strides), and one std::shared_ptr<Buffer> to the image header and data storage structure. These are standard C++ STL containers, I’d be very surprised if their move constructors were problematic. The other data members are trivial, so really shouldn’t cause any issues. I don’t see this being the problem…

As to what we do about this, well… I would need someone with a Mac to look into this. Might need to wait until @maxpietsch is back…

Given input1 is an Image<double>, it can’t actually cast to a Header when pushing to std::vector<Header> headers. This is actually calling the Header template constructor based on input1, and then clang can’t figure out whether to move or copy the temporary Header.

(This sort of thing is precisely why I advocated removing that template Header constructor: most of the time you don’t realize it’s actually being called)

OK, you’re right, I’d not considered the fact that there’s an implicit cast going on here… But if anything, that should make things even less ambiguous: the temporary Header is definitely an rvalue, the compiler should clearly default to using the move constructor in this case - otherwise there’s little point in C++11 move semantics… But you’re right, this may indeed be the problem. Let’s see if moving from:

headers.push_back (input1);

to

headers.push_back (Header (input1));

fixes the problem…


@Kwan_Chen: any chance you could try the following, see if that fixes the issue?

$ git fetch --all
$ git checkout fix_push_back_headers_in_registration
$ ./build release/bin/mrmetric

This should resolve the problem with mrmetric if the above was indeed the problem. But this only fixes the problem in those locations highlighted in your original post - there’s every chance there will be other places that need to be fixed. So if the above works, try a full build:

$ ./build

Hopefully that will work straight away, but there is a chance you might get other errors. If that happens, please post them here, and I’ll try to fix them and update the code. Unfortunately, I can’t reproduce the problem at my end, so it may take a few iterations to catch all occurrences of the problem…

I think the changes worked.

./build gave no errors. If that same error pops up, I’ll post it back up to the forum.

Do I need to do anything else to get back to the original branch?

Thanks again!

Great to hear, I’ve just merged these changes into master, so hopefully things will work for you from now on. To get back to the default setup, try the following commands:

$ git checkout master
$ git pull
$ ./build