Reputation: 8897
I'm trying to make the project polyworld but get an error compiling qt_clust.o
g++ -o bin/qt_clust .bld/qt_clust/tools/clustering/qt_clust.o -L/usr/lib -L/usr/local/lib -L/usr/include -lz -lgsl -lgslcblas -lgomp
and get
"_alloca", referenced from:
__Z38find_valid_neighbors__measureNeighborsP7ClusterRSt6vectorIiSaIiEEP22GeneDistanceDeltaCacheP19PopulationPartition.omp_fn.4 in qt_clust.o
(maybe you meant: ParsedCluster* std::vector<ParsedCluster, std::allocator<ParsedCluster> >::_M_allocate_and_copy<__gnu_cxx::__normal_iterator<ParsedCluster const*, std::vector<ParsedCluster, std::allocator<ParsedCluster> > > >(unsigned long, __gnu_cxx::__normal_iterator<ParsedCluster const*, std::vector<ParsedCluster, std::allocator<ParsedCluster> > >, __gnu_cxx::__normal_iterator<ParsedCluster const*, std::vector<ParsedCluster, std::allocator<ParsedCluster> > >))
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
I'm pretty sure the problem is with this file: https://github.com/JaimieMurdock/polyworld/blob/master/tools/clustering/qt_clust.cpp
I'm on OSX Mountain Lion.
Upvotes: 0
Views: 841
Reputation: 56068
If you changed these lines:
float dists[clusterNeighborCandidates.size() - (i+1)];
compute_distances( distance_deltaCache,
neighborPartition->genomeCache,
clusterNeighborCandidates,
i, i+1, clusterNeighborCandidates.size(),
dists );
to this:
::std::vector<float> dists(clusterNeighborCandidates.size() - (i+1));
compute_distances( distance_deltaCache,
neighborPartition->genomeCache,
clusterNeighborCandidates,
i, i+1, clusterNeighborCandidates.size(),
&(dists[0]) );
I bet the problem would go away.
The problem is that the original code has a dynamically sized array on the stack. The compiler generated code that calls the 'alloca' to allocate memory off the stack. Unfortunately, that function is non-standard and has kind of a shady history in general.
And dynamically sized arrays, while legal C99, are not legal C++03 or C++11. I think both g++ and clang support them as an extension. But apparently that support is slightly broken under OS X.
::std::vector
neatly sidesteps that problem. It does not allocate the array on the stack. It allocates it on the heap.
Upvotes: 3