Reputation: 6189
I'm having this undefined reference error which i don't have no clue where it is coming from:
/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(target)
#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
#ifndef TEST_DEBUGGER_CMF_HEURISTICA_CONSTRUCTIVA_GOLOSA_H
#define TEST_DEBUGGER_CMF_HEURISTICA_CONSTRUCTIVA_GOLOSA_H
#include <iostream>
#include "Clique.h"
#include "Eje.h"
#include "DisjointSet.h"
#include <list>
#include "stringTokenizer.hpp"
#include "Utils.h"
#include <fstream>
Clique heuristicaConstructiva(int n, std::list<Eje> &listaIncidencias);
Clique hconstructiva(int n, std::list<int> *listaAdyacencias);
#endif //TEST_DEBUGGER_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;
}
So, as i understand the compiler is yelling that it is not finding those cmfExacto and heuristicaConstructiva functions but i can't see the problem. What is wrong here?
Upvotes: 0
Views: 653
Reputation: 5270
Are you sure you are really compiling all the cpp files?
Looks like your CMake / compiler isn't including cmf-algo-exacto.cpp
and cmf-heuristica-constructiva.cpp
.
Also, with those files, you may get errors since you define the main
function multiple times. Best approach would probably be to create a separate main.cpp
file and put the (only) main
function there.
EDIT: Igor Tandetnik is right, the parameters don't match
Upvotes: 2