New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpp_standalone compilation fails with C++14 (default on gcc 6) #701

Closed
moritzaugustin opened this Issue May 24, 2016 · 7 comments

Comments

Projects
None yet
2 participants
@moritzaugustin
Contributor

moritzaugustin commented May 24, 2016

Using an up2date Arch Linux the following error occurs during (unsuccessful) compilation of the STDP_standalone example with brian2.0rc1 installed via pip (but the same error happens also with brian2.0b4). Any idea/further information required?

network.cpp: In member function ‘void Network::add(Clock*, codeobj_func)’:
network.cpp:29:71: error: no matching function for call to ‘make_pair(Clock*&, void (*&)())’                        
     objects.push_back(std::make_pair<Clock*, codeobj_func>(clock, func));                                          
                                                                       ^                                            
In file included from /usr/include/c++/6.1.1/bits/stl_algobase.h:64:0,                                              
                 from /usr/include/c++/6.1.1/vector:60,                                                             
                 from network.h:5,                                                                                  
                 from network.cpp:2:                                                                                
/usr/include/c++/6.1.1/bits/stl_pair.h:425:5: note: candidate: template<class _T1, class _T2> constexpr std::pair<typename std::__decay_and_strip<_Tp>::__type, typename std::__decay_and_strip<_T2>::__type> std::make_pair(_T1&&, _T2&&)                                                                                                                  
     make_pair(_T1&& __x, _T2&& __y)                                                                                
     ^~~~~~~~~                                                                                                      
/usr/include/c++/6.1.1/bits/stl_pair.h:425:5: note:   template argument deduction/substitution failed:              
network.cpp:29:71: note:   cannot convert ‘clock’ (type ‘Clock*’) to type ‘Clock*&&’                                
     objects.push_back(std::make_pair<Clock*, codeobj_func>(clock, func));                                          
                                                                       ^                                            
make: *** [network.o] Error 1

See also: brian_debug_2az2_E.log.txt

@moritzaugustin

This comment has been minimized.

Show comment
Hide comment
@moritzaugustin

moritzaugustin May 24, 2016

Contributor

Note that on an older Linux e.g. Ubuntu 14.04 with brian2.0rc1 (or 2.0b4) compilation of the example is successful.
Maybe is the following relevant? http://stackoverflow.com/questions/9641960/c11-make-pair-with-specified-template-parameters-doesnt-compile

Contributor

moritzaugustin commented May 24, 2016

Note that on an older Linux e.g. Ubuntu 14.04 with brian2.0rc1 (or 2.0b4) compilation of the example is successful.
Maybe is the following relevant? http://stackoverflow.com/questions/9641960/c11-make-pair-with-specified-template-parameters-doesnt-compile

@mstimberg

This comment has been minimized.

Show comment
Hide comment
@mstimberg

mstimberg May 24, 2016

Member

Hmm, I did not see this problem so far, but I don't use any bleeding-edge compiler (I guess your GCC defaults to C++11?). Reading your linked stackoverflow question I think we are using make_pair incorrectly which is probably the cause of this bug. Could you try replacing the line:

objects.push_back(std::make_pair<Clock*, codeobj_func>(clock, func));

by

objects.push_back(std::make_pair(clock, func));

manually in your network.cpp file and see whether you can then compile it using make?

Member

mstimberg commented May 24, 2016

Hmm, I did not see this problem so far, but I don't use any bleeding-edge compiler (I guess your GCC defaults to C++11?). Reading your linked stackoverflow question I think we are using make_pair incorrectly which is probably the cause of this bug. Could you try replacing the line:

objects.push_back(std::make_pair<Clock*, codeobj_func>(clock, func));

by

objects.push_back(std::make_pair(clock, func));

manually in your network.cpp file and see whether you can then compile it using make?

@moritzaugustin

This comment has been minimized.

Show comment
Hide comment
@moritzaugustin

moritzaugustin May 24, 2016

Contributor

Indeed your suggested line replacement resolved the issue. Another way was to add -std=gnu++98 to the CFLAGS in the makefile since recent GCC defaults to C++14.

GCC 6.0: https://gcc.gnu.org/gcc-6/changes.html
The default mode for C++ is now -std=gnu++14 instead of -std=gnu++98.

(found on http://stackoverflow.com/questions/21221411/when-will-gnu-c-support-c11-without-explicitly-asking-for-it)

Contributor

moritzaugustin commented May 24, 2016

Indeed your suggested line replacement resolved the issue. Another way was to add -std=gnu++98 to the CFLAGS in the makefile since recent GCC defaults to C++14.

GCC 6.0: https://gcc.gnu.org/gcc-6/changes.html
The default mode for C++ is now -std=gnu++14 instead of -std=gnu++98.

(found on http://stackoverflow.com/questions/21221411/when-will-gnu-c-support-c11-without-explicitly-asking-for-it)

@moritzaugustin moritzaugustin changed the title from cpp_standalone compilation fails on recent Linux to cpp_standalone compilation fails with C++14 (default on gcc 6) May 24, 2016

@mstimberg

This comment has been minimized.

Show comment
Hide comment
@mstimberg

mstimberg May 24, 2016

Member

[Re-posting this under the correct account...]

Ok, good to know. I'll try to apply this change and see whether the test suite runs through on all OSes (the line is slightly different on Windows, the same fix might break it).

Another way was to add -std=gnu++98 to the CFLAGS in the makefile since recent GCC defaults to C++14.

You should be able to add this to your codegen.cpp.extra_compile_args_gcc preference -- this way you don't have to manually change the CFLAGS every time.

Member

mstimberg commented May 24, 2016

[Re-posting this under the correct account...]

Ok, good to know. I'll try to apply this change and see whether the test suite runs through on all OSes (the line is slightly different on Windows, the same fix might break it).

Another way was to add -std=gnu++98 to the CFLAGS in the makefile since recent GCC defaults to C++14.

You should be able to add this to your codegen.cpp.extra_compile_args_gcc preference -- this way you don't have to manually change the CFLAGS every time.

@moritzaugustin

This comment has been minimized.

Show comment
Hide comment
@moritzaugustin

moritzaugustin May 24, 2016

Contributor

PreferenceError: Value -std=gnu++98 for preference codegen.cpp.extra_compile_args_gcc is invalid.
My solution is now using a patched network.cpp template file waiting for the final brian2 to contain the respective fix ;)

Contributor

moritzaugustin commented May 24, 2016

PreferenceError: Value -std=gnu++98 for preference codegen.cpp.extra_compile_args_gcc is invalid.
My solution is now using a patched network.cpp template file waiting for the final brian2 to contain the respective fix ;)

@mstimberg

This comment has been minimized.

Show comment
Hide comment
@mstimberg

mstimberg May 24, 2016

Member

PreferenceError: Value -std=gnu++98 for preference codegen.cpp.extra_compile_args_gcc is invalid.

I think you are trying to set the preference to the value instead of appending it to it: the value for the preference is a list, i.e. do something like this:

prefs.codegen.cpp.extra_compile_args_gcc += ['-std=gnu++98']

My solution is now using a patched network.cpp template file waiting for the final brian2 to contain the respective fix ;)

Well, that works as well ;)

Member

mstimberg commented May 24, 2016

PreferenceError: Value -std=gnu++98 for preference codegen.cpp.extra_compile_args_gcc is invalid.

I think you are trying to set the preference to the value instead of appending it to it: the value for the preference is a list, i.e. do something like this:

prefs.codegen.cpp.extra_compile_args_gcc += ['-std=gnu++98']

My solution is now using a patched network.cpp template file waiting for the final brian2 to contain the respective fix ;)

Well, that works as well ;)

@moritzaugustin

This comment has been minimized.

Show comment
Hide comment
@moritzaugustin

moritzaugustin May 24, 2016

Contributor

Thanks.

Contributor

moritzaugustin commented May 24, 2016

Thanks.

mstimberg added a commit that referenced this issue May 24, 2016

Use `std::make_pair` without template types -- the types should be au…
…tomatically inferred from the arguments

The previous code did not work correctly with GCC 6 which defaults to C++14
Fixes #701

@mstimberg mstimberg self-assigned this May 24, 2016

@mstimberg mstimberg removed the in progress label May 26, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment