かれ4

かれこれ4個目のブログ

word2vecをMavericksに入れる

何も考えないで、makeしてみた。

$ svn co http://word2vec.googlecode.com/svn/trunk ./word2vec 
$ cd word2vec
$ make
gcc word2vec.c -o word2vec -lm -pthread -Ofast -march=native -Wall -funroll-loops -Wno-unused-result
gcc word2phrase.c -o word2phrase -lm -pthread -Ofast -march=native -Wall -funroll-loops -Wno-unused-result
gcc distance.c -o distance -lm -pthread -Ofast -march=native -Wall -funroll-loops -Wno-unused-result
distance.c:18:10: fatal error: 'malloc.h' file not found
#include <malloc.h>
         ^
1 error generated.
make: *** [distance] Error 1

malloc.hがないと言ってる

Leopardくらいから
malloc.hはmalloc/malloc.hにあるらしく(2014/5/6 変更)
Macではmalloc.hではなく、stdlib.hを使うようです。

なので、malloc.hのところを全てstdlib.hにすれば完了です。


これ以降は情報が古いので、参考になりません。





// #include <malloc.h> 
#include <malloc/malloc.h> 

書き換える。
そしてまたmake

distance.c:46:19: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)'
  vocab = (char *)malloc((long long)words * max_w * sizeof(char));
                  ^
distance.c:46:19: note: please include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
1 warning generated.
gcc word-analogy.c -o word-analogy -lm -pthread -Ofast -march=native -Wall -funroll-loops -Wno-unused-result
word-analogy.c:18:10: fatal error: 'malloc.h' file not found
#include <malloc.h>
         ^
1 error generated.
make: *** [word-analogy] Error 1

word-analogy.cもmalloc.hをmalloc/malloc.hに書き換える。
なんかこの先何個も出てくると嫌なので、#include がどれくらいあるのか見ておく

$ ack "#include <malloc.h>"
compute-accuracy.c
19:#include <malloc.h>

word-analogy.c
18:#include <malloc.h>

これだけなら手で直してもそんなに手間じゃない。
compute-accuracy.cとword-analogy.cも
#include <malloc.h>を
#include <malloc/malloc.h>
に書き換える。

$ make 
gcc word2vec.c -o word2vec -lm -pthread -Ofast -march=native -Wall -funroll-loops -Wno-unused-result
gcc word2phrase.c -o word2phrase -lm -pthread -Ofast -march=native -Wall -funroll-loops -Wno-unused-result
gcc distance.c -o distance -lm -pthread -Ofast -march=native -Wall -funroll-loops -Wno-unused-result
distance.c:46:19: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)'
  vocab = (char *)malloc((long long)words * max_w * sizeof(char));
                  ^
distance.c:46:19: note: please include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
1 warning generated.
gcc word-analogy.c -o word-analogy -lm -pthread -Ofast -march=native -Wall -funroll-loops -Wno-unused-result
word-analogy.c:46:19: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)'
  vocab = (char *)malloc((long long)words * max_w * sizeof(char));
                  ^
word-analogy.c:46:19: note: please include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
1 warning generated.
gcc compute-accuracy.c -o compute-accuracy -lm -pthread -Ofast -march=native -Wall -funroll-loops -Wno-unused-result
chmod +x *.sh


一応出来たっぽいけど、warningがなんか気持ち悪い
distance.cとword-analogy.cでstdlib.hをincludeしてくれ的な事を言っているので、仰せのままに

$ make 
gcc word2vec.c -o word2vec -lm -pthread -Ofast -march=native -Wall -funroll-loops -Wno-unused-result
gcc word2phrase.c -o word2phrase -lm -pthread -Ofast -march=native -Wall -funroll-loops -Wno-unused-result
gcc distance.c -o distance -lm -pthread -Ofast -march=native -Wall -funroll-loops -Wno-unused-result
gcc word-analogy.c -o word-analogy -lm -pthread -Ofast -march=native -Wall -funroll-loops -Wno-unused-result
gcc compute-accuracy.c -o compute-accuracy -lm -pthread -Ofast -march=native -Wall -funroll-loops -Wno-unused-result
chmod +x *.sh

スッキリ



$ svn diff 
Index: compute-accuracy.c
===================================================================
--- compute-accuracy.c	(リビジョン 37)
+++ compute-accuracy.c	(作業コピー)
@@ -16,7 +16,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <math.h>
-#include <malloc.h>
+#include <malloc/malloc.h>
 #include <ctype.h>
 
 const long long max_size = 2000;         // max length of strings
Index: distance.c
===================================================================
--- distance.c	(リビジョン 37)
+++ distance.c	(作業コピー)
@@ -13,9 +13,10 @@
 //  limitations under the License.
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <math.h>
-#include <malloc.h>
+#include <malloc/malloc.h>
 
 const long long max_size = 2000;         // max length of strings
 const long long N = 40;                  // number of closest words that will be shown
Index: word-analogy.c
===================================================================
--- word-analogy.c	(リビジョン 37)
+++ word-analogy.c	(作業コピー)
@@ -13,9 +13,10 @@
 //  limitations under the License.
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <math.h>
-#include <malloc.h>
+#include <malloc/malloc.h>
 
 const long long max_size = 2000;         // max length of strings
 const long long N = 40;                  // number of closest words that will be shown