2013-01-12 119 views
0

我試圖使項目polyworld但得到一個錯誤編譯qt_clust.o未定義的符號:「_alloca」

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山獅。

回答

2

如果你改變了這些行:

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都支持它們作爲擴展。但顯然這種支持在OS X下略有破壞。

::std::vector整齊地迴避了這個問題。它不會在堆棧上分配數組。它將它分配在堆上。

+0

非常感謝!它工作完美。我聽說'alloca'沒有警告堆棧溢出問題,但認爲它是在/ usr/include中編譯的。可能不會!感謝您的快速解答。 :) – crizCraig

+0

@crizCraig:不客氣。 – Omnifarious