2017-06-20 19 views
0

私はそれがから来ているか見当もつかないしません。この未定義の参照エラー抱えている:リンカエラー:未定義の参照C++

/usr/local/clion-2017.1.1/bin/cmake/bin/cmake --build /home/jscherman/CLionProjects/algo3-tp3-cmf/cmake-build-debug --target experimentos -- -j 4 
Scanning dependencies of target experimentos 
[ 50%] Building CXX object CMakeFiles/experimentos.dir/experimentos.cpp.o 
[100%] Linking CXX executable experimentos 
CMakeFiles/experimentos.dir/experimentos.cpp.o: In function `main': 
/home/jscherman/CLionProjects/algo3-tp3-cmf/experimentos.cpp:12: undefined reference to `cmfExacto(int, int, std::__cxx11::list<Eje, std::allocator<Eje> >&)' 
/home/jscherman/CLionProjects/algo3-tp3-cmf/experimentos.cpp:13: undefined reference to `heuristicaConstructiva(int, std::__cxx11::list<Eje, std::allocator<Eje> >)' 
collect2: error: ld returned 1 exit status 
CMakeFiles/experimentos.dir/build.make:94: recipe for target 'experimentos' failed 
make[3]: *** [experimentos] Error 1 
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/experimentos.dir/all' failed 
make[2]: *** [CMakeFiles/experimentos.dir/all] Error 2 
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/experimentos.dir/rule' failed 
make[1]: *** [CMakeFiles/experimentos.dir/rule] Error 2 
Makefile:118: recipe for target 'experimentos' failed 
make: *** [experimentos] Error 2 

experimentos.cpp(ターゲット)

#include "cmf-algo-exacto.h" 
#include "cmf-heuristica-constructiva-golosa.h" 

int main(int argc, char** argv) { 
    int n = 5, m = 10; 
    std::list<Eje> grafo = Utils::generarGrafo(n, m, false, 0, 0); 
    std::cout << "Exacto: " << cmfExacto(n, m, grafo) << std::endl; 
    std::cout << "Constructiva: " << heuristicaConstructiva(n, grafo) << std::endl; 
    return 0; 
} 

CMF-heuristica-constructiva-golosa.h

​​

CMF-heuristica-constructiva.cpp

#include "cmf-heuristica-constructiva-golosa.h" 

Clique hconstructiva(int n, std::list<int> *listaAdyacencias){ 
    ... 
} 

Clique heuristicaConstructiva(int n, std::list<Eje> listaIncidencias) { 
    ... 
} 

int main(int argc, char** argv) { 
    ... 
    return 0; 
} 

CMF-ALGO-exacto.h

#ifndef TEST_DEBUGGER_CMF_ALGO_EXACTO_H 
#define TEST_DEBUGGER_CMF_ALGO_EXACTO_H 

#include <iostream> 
#include "Clique.h" 
#include "Eje.h" 
#include "DisjointSet.h" 
#include <list> 
#include "stringTokenizer.hpp" 
#include "Utils.h" 
#include <fstream> 

Clique * cmfExacto(DisjointSet &uds, std::list<Eje> ejesNoAgregados, list<int> *listaAdyacencias); 

Clique * cmfExacto(int n, int m, std::list<Eje> &listaIncidencias); 

#endif //TEST_DEBUGGER_CMF_ALGO_EXACTO_H 

CMF-ALGO-exacto.cpp

#include "cmf-algo-exacto.h" 

Clique * cmfExacto(int n, int m, std::list<Eje> &listaIncidencias) { 
    ... 
} 

Clique * cmfExacto(DisjointSet &uds, std::list<Eje> ejesNoAgregados, list<int> *listaAdyacencias){ 
    ... 
} 

int main(int argc, char** argv) { 
    ... 
    return 0; 
} 

コンパイラは、これらの関数が見つからないことを理解していますが、cmfExactoheuristicaConstructivaの関数が見つかりません。ここで何が間違っていますか?

+0

分裂と征服。 –

+0

@RSahuは何を言う? – jscherman

+2

あなたは関数 'Clique heuristicaConstructiva(int n、std :: list &listaIncidencias);を宣言し、呼び出しています。しかし、あなたはその機能を実装したことはありません。関連しない別の関数 'Clique heuristicaConstructiva(int n、std :: list listaIncidencias)'を実装しましたが、最後のパラメータを値で取っていますが、呼び出していません。 'cmfExacto(int n、int m、std :: list &listaIncidencias)と同様に ' –

答えて

2

実際にすべてのcppファイルをコンパイルしていますか? CMake /コンパイラにcmf-algo-exacto.cppcmf-heuristica-constructiva.cppが含まれていないようです。

また、これらのファイルでは、main関数を複数回定義するため、エラーが発生することがあります。最良の方法は、おそらく別のmain.cppファイルを作成し、そこに(唯一)main関数を入れることです。

EDIT:Igor Tandetnikが正しく、パラメータが一致しません。

+0

ありがとう。私は恥ずかしく、私はあらかじめその問題を見ることができませんでした。この問題は、それらの.cppファイルをコンパイルするのを忘れてしまったためです。あなたが言ったように、私は現在、これらの主な機能に今問題があります。 – jscherman