Bonjour,
J'ai entre les mains un code censé être propre (un mec a quand même fait sa thèse dessus...).
Le code est libre, c'est le premier lien dans les Softwares http://en.wikipedia.org/wiki/K-means%2B%2B#Software (David Arthur), si ça peut vous aider...
Bref, le problème est que le code est en C++, et que moi je connais le python, le java, j'ai des notions rapides de C, mais ca s'arrête là. Heureusement, je n'ai pas l'intention de toucher au code (pour le moment), je veux juste compiler et l'exécuter.
J'ai donc cherché sur le net comment compiler du c++, ca m'a donné ça :
Déjà la première moitié on dirait des erreurs dues à linux, je les comprends pas trop trop.Citation:
> /kmpp$ g++ -o kmeans KMeans.cpp
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 20 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 21 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 22 has invalid symbol index 21
/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
/tmp/cczEr47h.o: In function `RunKMeansOnce(KmTree const&, int, int, int, double*, double*, double*, double*, double*, double, double*, double*, double*, double*, int*)':
KMeans.cpp:(.text+0xcc): undefined reference to `KmTree::DoKMeansStep(int, double*, int*) const'
KMeans.cpp:(.text+0x39a): undefined reference to `KmTree::DoKMeansStep(int, double*, int*) const'
/tmp/cczEr47h.o: In function `RunKMeans(int, int, int, double*, int, double*, int*)':
KMeans.cpp:(.text+0x93f): undefined reference to `__KMeansAssertionFailure(char const*, int, char const*)'
KMeans.cpp:(.text+0xa33): undefined reference to `KmTree::KmTree(int, int, double*)'
KMeans.cpp:(.text+0xb54): undefined reference to `__KMeansAssertionFailure(char const*, int, char const*)'
KMeans.cpp:(.text+0xd6b): undefined reference to `KmTree::~KmTree()'
KMeans.cpp:(.text+0xdd0): undefined reference to `KmTree::~KmTree()'
/tmp/cczEr47h.o: In function `RunKMeansPlusPlus(int, int, int, double*, int, double*, int*)':
KMeans.cpp:(.text+0xe16): undefined reference to `__KMeansAssertionFailure(char const*, int, char const*)'
KMeans.cpp:(.text+0xf07): undefined reference to `KmTree::KmTree(int, int, double*)'
KMeans.cpp:(.text+0x1021): undefined reference to `__KMeansAssertionFailure(char const*, int, char const*)'
KMeans.cpp:(.text+0x1074): undefined reference to `KmTree::SeedKMeansPlusPlus(int, double*) const'
KMeans.cpp:(.text+0x1152): undefined reference to `KmTree::~KmTree()'
KMeans.cpp:(.text+0x11b4): undefined reference to `KmTree::~KmTree()'
collect2: ld a retourné 1 code d'état d'exécution
> /kmpp$ ls
KMeans.cpp KMeans.cpp~ KMeans.h KmTree.cpp KmTree.h KmUtils.cpp KmUtils.h README.txt sample_input.txt spam_input.txt TestKm.cpp
Et après c'est des undefined references, que je comprends pas non plus, je sais pas ce que ca veut dire vu que ya pas ces références dans les fonctions.
Exemple, KMeans.cpp/RunKMeansPlusPlus :
Enfin voilà, moi tout ce que je veux c'est utiliser ce programme :( le modifier ca sera pour plus tard.Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 Scalar RunKMeansPlusPlus(int n, int k, int d, Scalar *points, int attempts, Scalar *ret_centers, int *ret_assignment) { KM_ASSERT(k >= 1); // Create the tree and log LOG(false, "Running k-means++..." << endl); KmTree tree(n, d, points); LOG(false, "Done preprocessing..." << endl); // Initialization Scalar *centers = (Scalar*)malloc(sizeof(Scalar)*k*d); KM_ASSERT(centers != 0); Scalar min_cost = -1, max_cost = -1, total_cost = 0; double min_time = -1, max_time = -1, total_time = 0; // Run all the attempts for (int attempt = 0; attempt < attempts; attempt++) { double start_time = GetSeconds(); // Choose centers using k-means++ seeding <<<<<-------------------- iiiiiiiiiiiiiiiiiiiiiiiiiiii tree.SeedKMeansPlusPlus(k, centers); // Run k-means RunKMeansOnce(tree, n, k, d, points, centers, &min_cost, &max_cost, &total_cost, start_time, &min_time, &max_time, &total_time, ret_centers, ret_assignment); } LogMetaStats(min_cost, max_cost, total_cost, min_time, max_time, total_time, attempts); // Clean up and return free(centers); return min_cost; }
Des inspirés ?