歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux安裝skynet問題總結

Linux安裝skynet問題總結

日期:2017/2/28 13:57:30   编辑:Linux教程

skynet是為在線游戲服務器打造的輕量級框架,使用c+lua實現,支持Linux 。使用這套框架能獲得很大收益,其中一個就是,基本只需要用lua開發,很少用到c,提高了開發效率。但是,skynet本身對系統有很大依賴性,安裝說明過於簡單,沒有提及到。所以文章這裡總結Linux安裝skynet問題,希望有所幫助。

skynet的安裝過程
git clone https://github.com/cloudwu/skynet.git
cd skynet make linux 簡單3步,對於很多高版本的系統來說,可能就這3步。但是,低版本系統可能無法安裝,如下: 1. gcc版本問題 2. 缺少 readline 3. 缺少 ncurses 4. 缺少 git (非必要項,則要手動下載skynet及3rd下的jemalloc) 5. 缺少 autoconf 所以,這裡以CentOS5.5系統做說明,這系統不具備以上幾個條件,甚至連git都無法通過包管理來安裝。在skynet的編譯過程中,如果在make步驟出現錯誤,要用 make cleanall 清除已編譯的文件,不然會出現莫名其妙的錯誤。 在早期的skynet版本,lua不能清除干淨,若是這樣,執行:cd 3rd/lua && make clean && cd -

問題1:缺少git

# git clone https://github.com/cloudwu/skynet.git
bash: git: command not found 解決: 這裡要安裝git,在安裝git過程中,非常重要一步是安裝curl,而這一步會把git所有的依賴裝上,如curl和openssl,而git編譯時也要找到curl庫
yum -y install curl curl-devel wget --no-check-certificate https://www.kernel.org/pub/software/scm/git/git-2.5.2.tar.gz tar -zxf git-2.5.2.tar.gz cd git-2.5.2 ./configure --prefix=/usr make make install

問題2:git https錯誤

# git clone https://github.com/cloudwu/skynet.git
Cloning into 'skynet'...
fatal: Unable to find remote helper for 'https' 解決: 很多網友都是說把https換成git解決,但也只是暫時性的。報錯是git安裝時系統缺少curl導致的,參考問題1重裝git 重裝git後,如果還不行,應該是git軟連接問題,如下修正: ln -sf /usr/bin/git /bin/git

問題3:缺少readline

lua.c:81:31: error: readline/readline.h: No such file or directory lua.c:82:30: error: readline/history.h: No such file or directory lua.c: In function ‘pushline’: lua.c:311: warning: implicit declaration of function ‘readline’ lua.c:311: warning: assignment makes pointer from integer without a cast lua.c: In function ‘addreturn’: lua.c:342: warning: implicit declaration of function ‘add_history’ make[3]: *** [lua.o] Error 1 make[3]: Leaving directory `/data/git-2.5.2/skynet/3rd/lua' make[2]: *** [linux] Error 2 make[2]: Leaving directory `/data/git-2.5.2/skynet/3rd/lua' make[1]: *** [3rd/lua/liblua.a] Error 2 make[1]: Leaving directory `/data/git-2.5.2/skynet' make: *** [linux] Error 2 解決: yum -y install readline-devel

問題4:缺少ncurses

cc -std=gnu99 -o lua lua.o liblua.a -lm -Wl,-E -ldl -lreadline /usr/lib/gcc/i386-RedHat-linux/4.1.2/../../../libreadline.so: undefined reference to `PC' /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libreadline.so: undefined reference to `tgetflag' /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libreadline.so: undefined reference to `tgetent' /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libreadline.so: undefined reference to `UP' /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libreadline.so: undefined reference to `tputs' /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libreadline.so: undefined reference to `tgoto' /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libreadline.so: undefined reference to `tgetnum' /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libreadline.so: undefined reference to `BC' /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libreadline.so: undefined reference to `tgetstr' collect2: ld returned 1 exit status make[3]: *** [lua] Error 1 make[3]: Leaving directory `/data/skynet/3rd/lua' make[2]: *** [linux] Error 2 make[2]: Leaving directory `/data/skynet/3rd/lua' make[1]: *** [3rd/lua/liblua.a] Error 2 make[1]: Leaving directory `/data/skynet' make: *** [linux] Error 2 解決:
很多網友說修改Makefile,在SYSLIBS變量中追加" -lncurses "選項,但這樣不方便,以後還會遇到這個問題。所以這裡建議手動安裝readline
yum -y install ncurses-devel wget ftp://ftp.gnu.org/gnu/readline/readline-6.2.tar.gz tar -zxf readline-6.2.tar.gz cd readline-6.2 ./configure --prefix=/usr make SHLIB_LIBS=-lncurses make install ldconfig 備注: 1、國內連接gnu.org網站不是很穩定,可能wget要多試幾次。 2、通過ldconfig -p |grep readline可以測試readline的庫是否成功加載 3、如果還無法解決,執行以下命令(建議先備份下): rm -rf /usr/lib/libreadline* ldconfig 如果是64位機器: rm -rf /usr/lib64/libreadline* ldconfig

問題5:lua整數編譯報錯

3rd/lua/luaconf.h:560:2: error: #error "Compiler does not support 'long long'. Use option '-DLUA_32BITS' or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)" In file included from skynet-src/malloc_hook.c:5: 3rd/lua/lua.h:93: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘lua_Integer’ 3rd/lua/lua.h:96: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘lua_Unsigned’ 3rd/lua/lua.h:182: warning: type defaults to ‘int’ in declaration of ‘lua_Integer’ 3rd/lua/lua.h:182: error: ‘lua_Integer’ declared as function returning a function 3rd/lua/lua.h:182: warning: parameter names (without types) in function declaration 3rd/lua/lua.h:226: error: expected declaration specifiers or ‘...’ before ‘lua_Integer’ 3rd/lua/lua.h:244: error: expected declaration specifiers or ‘...’ before ‘lua_Integer’ 3rd/lua/lua.h:246: error: expected declaration specifiers or ‘...’ before ‘lua_Integer’ 3rd/lua/lua.h:261: error: expected declaration specifiers or ‘...’ before ‘lua_Integer’ 3rd/lua/lua.h:263: error: expected declaration specifiers or ‘...’ before ‘lua_Integer’ skynet-src/malloc_hook.c: In function ‘update_xmalloc_stat_alloc’: skynet-src/malloc_hook.c:55: warning: value computed is not used skynet-src/malloc_hook.c: In function ‘update_xmalloc_stat_free’: skynet-src/malloc_hook.c:65: warning: value computed is not used skynet-src/malloc_hook.c: In function ‘dump_mem_lua’: skynet-src/malloc_hook.c:237: error: too many arguments to function ‘lua_pushinteger’ skynet-src/malloc_hook.c:238: error: expected ‘)’ before ‘data’ skynet-src/malloc_hook.c:238: error: too many arguments to function ‘lua_rawseti’ In file included from skynet-src/skynet_log.c:1: skynet-src/skynet_log.h:14:7: warning: no newline at end of file make[1]: *** [skynet] Error 1 make[1]: Leaving directory `/data/skynet' make: *** [linux] Error 2 解決: 這個是skynet最常見的編譯失敗了,和gcc版本有關,升級gcc可以解決問題。 最簡單的方法:修改Makefile,在CFLAGS 加入 -std=gnu99 如果不想手動改,可用以下命令: sed -i "s|CFLAGS =|CFLAGS = -std=gnu99 |" Makefile 如果是升級gcc參考問題6的解決方式。

問題6:gcc編譯器問題

/data/skynet/skynet-src/skynet_server.c:211: undefined reference to `__sync_sub_and_fetch_4' /tmp/ccC4fGch.o: In function `cmd_logoff': /data/skynet/skynet-src/skynet_server.c:589: undefined reference to `__sync_bool_compare_and_swap_4' /tmp/ccC4fGch.o: In function `cmd_logon': /data/skynet/skynet-src/skynet_server.c:568: undefined reference to `__sync_bool_compare_and_swap_4' /tmp/ccaeanLP.o: In function `reserve_id': /data/skynet/skynet-src/socket_server.c:241: undefined reference to `__sync_add_and_fetch_4' /data/skynet/skynet-src/socket_server.c:247: undefined reference to `__sync_bool_compare_and_swap_2' /data/skynet/skynet-src/socket_server.c:243: undefined reference to `__sync_and_and_fetch_4' /tmp/ccs12kTV.o: In function `get_allocated_field': /data/skynet/skynet-src/malloc_hook.c:36: undefined reference to `__sync_bool_compare_and_swap_4' /data/skynet/skynet-src/malloc_hook.c:40: undefined reference to `__sync_bool_compare_and_swap_4' collect2: ld returned 1 exit status make[1]: *** [skynet] Error 1 make[1]: Leaving directory `/data/skynet' make: *** [linux] Error 2 解決: 這是gcc版本問題,解決方法就是到高版本(如gcc4.5)下載一個linux_atomic.c文件,將其編譯為一個靜態庫鏈接到你的項目代碼,具體做法也比較麻煩。所以,這裡推薦重裝gcc。 另外,編譯skynet建議gcc最低版本4.6.0,可自動下載並更新依賴包。安裝gcc過程會比較久,要耐心等待 安裝gcc步驟如下: wget http://mirrors.ustc.edu.cn/gnu/gcc/gcc-4.6.0/gcc-4.6.0.tar.gz tar -zxf gcc-4.6.0.tar.gz cd gcc-4.6.0 mkdir build cd build
../contrib/download_prerequisites ../configure -disable-multilib make make install ln -sf /usr/local/bin/gcc /usr/bin/gcc 注意了,要確保 download_prerequisites 安裝成功。因為國內連接gnu.org網站不是很穩定,可能出現類似錯誤: Resolving gcc.gnu.org... 209.132.180.131 Connecting to gcc.gnu.org|209.132.180.131|:21... connected. Logging in as anonymous ... Logged in! ==> SYST ... done. ==> PWD ... done. ==> TYPE I ... done. ==> CWD /pub/gcc/infrastructure ... done. ==> SIZE mpfr-2.4.2.tar.bz2 ... 1077886 ==> PASV ... couldn't connect to 209.132.180.131 port 10179: Connection refused 如果重試了很多次都無法成功,嘗試手動安裝吧,主要就3個依賴gmp和mpfr、mpc,裝好後再繼續執行gcc ../configure及後面的步驟。 wget http://ftp.gnu.org/gnu/gmp/gmp-4.2.2.tar.bz2 tar -jxf gmp-4.2.2.tar.bz2 cd gmp-4.2.2 ./configure --prefix=/usr make && make install wget http://mpfr.loria.fr/mpfr-2.3.2/mpfr-2.3.2.tar.gz tar -zxf mpfr-2.3.2.tar.gz cd mpfr-2.3.2 ./configure --prefix=/usr make && make install wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz tar -zxf mpc-0.8.1.tar.gz cd mpc-0.8.1
./configure --prefix=/usr make && make install

問題7:缺少autoconf

make all PLAT=linux SKYNET_LIBS="-lpthread -lm -ldl -lrt" SHARED="-fPIC --shared" EXPORT="-Wl,-E" MALLOC_STATICLIB="3rd/jemalloc/lib/libjemalloc_pic.a" SKYNET_DEFINES="" make[1]: Entering directory `/data/skynet' cd 3rd/jemalloc && ./autogen.sh --with-jemalloc-prefix=je_ --disable-valgrind autoconf ./autogen.sh: line 5: autoconf: command not found Error 0 in autoconf make[1]: *** [3rd/jemalloc/Makefile] Error 1 make[1]: Leaving directory `/data/skynet' make: *** [linux] Error 2 解決: yum -y install autoconf

問題8:鏈接錯誤

ln -sf libjemalloc.so.2 lib/libjemalloc.so ln: creating symbolic link `lib/libjemalloc.so' to `libjemalloc.so.2': Operation not supported make[3]: *** [lib/libjemalloc.so] Error 1 make[3]: Leaving directory `/mnt/hgfs/vm/skynet/3rd/jemalloc' make[2]: *** [3rd/jemalloc/lib/libjemalloc_pic.a] Error 2 make[2]: Leaving directory `/mnt/hgfs/vm/skynet' make[1]: *** [linux] Error 2 make[1]: Leaving directory `/mnt/hgfs/vm/skynet' make: *** [default] Error 2 解決: 虛擬機共享目錄不能設置軟連接,選擇其他目錄安裝

最後語

如果還遇到其他錯誤,可以評論一起討論,正好我也一起整理下。
Copyright © Linux教程網 All Rights Reserved