0

プロジェクトをpolyworldにしようとしていますが、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

そして得る

"_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

問題はこのファイルにあると確信しています: https://github.com/JaimieMurdock/polyworld/blob/master/tools/clustering/qt_clust.cpp

OSX Mountain Lion を使用しています。

4

1 に答える 1

3

これらの行を変更した場合:

    float dists[clusterNeighborCandidates.size() - (i+1)];

    compute_distances( distance_deltaCache,
                       neighborPartition->genomeCache,
                       clusterNeighborCandidates,
                       i, i+1, clusterNeighborCandidates.size(),
                       dists );

これに:

    ::std::vector<float> dists(clusterNeighborCandidates.size() - (i+1));

    compute_distances( distance_deltaCache,
                       neighborPartition->genomeCache,
                       clusterNeighborCandidates,
                       i, i+1, clusterNeighborCandidates.size(),
                       &(dists[0]) );

問題はなくなるに違いない。

問題は、元のコードのスタックに動的なサイズの配列があることです。コンパイラは、「alloca」を呼び出してスタックからメモリを割り当てるコードを生成しました。残念ながら、その機能は非標準であり、一般的には怪しげな歴史があります。

また、動的にサイズ設定された配列は、C99は有効ですが、C++03またはC++11は有効ではありません。g++とclangの両方が拡張機能としてそれらをサポートしていると思います。しかし、どうやらそのサポートはOSXではわずかに壊れています。

::std::vectorその問題をきちんと回避します。配列をスタックに割り当てません。ヒープに割り当てます。

于 2013-01-12T02:13:08.627 に答える