0

I am trying to compile a program coded in C++. It compiles perfectly on Mac OSX but it fails on Linux. I have been trying on two independent clusters running on Linux and it fails to compile on both.

Here is the error I am getting:

src/LCEcomposite.cc:513: error: no matching function for call to ‘find(__gnu_cxx::__normal_iterator > >, __gnu_cxx::__normal_iterator > >, unsigned int&)’

Here is the line of code that causes the trouble (line 513 in LCEcomposite.cc)

if(find(_TraitIndices.begin(), _TraitIndices.end(), i) == _TraitIndices.end()) {

Here is the make version on Linux

gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC) 

Here is the gcc version on Linux

GNU Make 3.81
This program built for x86_64-redhat-linux-gnu

Here is the output of uname -a

Linux seawolf2 2.6.32-358.18.1.el6.x86_64 #1 SMP Wed Aug 28 17:19:38 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
6
  • Are you explicitly including <algorithm> in your code? Commented Apr 23, 2015 at 19:25
  • It is not my code, it is a big software and asked the author a few minutes ago but haven't received an answer yet. I've searched for algorithm in LCEcomposite.cc and nothing matched. Does it answer you question? Commented Apr 23, 2015 at 19:27
  • Yes. It probably was built under a tool (e.g. XCode) on MacOSX. Therefore the system included the library and the developer did not notice its necessity. But when compiling by hand, this has to be on the code. Or Apple's compiler (LLVM) does it automatically as well. Commented Apr 23, 2015 at 19:30
  • You need a newer version of GCC. Notice that GCC 5.1 has just been released (april 22, 2015). Download its source code and build and install it. Commented Apr 23, 2015 at 19:33
  • @BasileStarynkevitch Why would he need a newer version of GCC? find is in the algorithm header, and should compile perfectly fine for the version of GCC he's using, and even older ones. Commented Apr 23, 2015 at 19:34

1 Answer 1

2

Add this to your code:

#include <algorithm>

Mac included the header anyway, I guess, that's why it works there.

Sign up to request clarification or add additional context in comments.

3 Comments

I've noticed that some compilers will include things like algorithm for you but the newer versions of gcc have stopped doing that. From the viewpoint of completeness, I feel it's wrong for a compiler to include headers for you. It should force you to include headers you require so your code is complete regardless of compiler being used.
I had the same problem as OP when I first used a Mac. And yes this is bad, because it works on your machine and then you sent the project to the TA and (s)he says, well your code did not compile, what do you want me to do to? And yes, (s)he is correct! ;)
I spent so much time on this issue! Thank you so much for your help. And thanks for the short explanation.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.