业余写个moba手游系列之——服务器部署到Centos

之前这个LuaServer都是跑在windows上的,也就是游戏没有实际发布到现网环境下玩过,这次重构改造前准备折腾下,先把原始版本服务器在Centos上部署好跑起来,这要是都没成功在linux公网环境下部署一次,感觉缺少点成就感不是。
虽然在老版本基础上进行编译部署,但是发现,这不同平台的编译,真是道阻且长啊,一堆坑有没有。
说明下,我这台服务器是阿里云服务器,系统centos7.3

坑1:

这个服务器需要一个LuaPbIntf.a的库支持,giuhub链接地址生成规则也参考了github上的说明,在windows上一切ok,但是premake生成的makefile挪到centos怎么就根本编译不过了呢??
编译报错信息:

In file included from ../third_party/lua-intf/LuaIntf/LuaIntf.h:47:0,
from ../src/LuaPbIntf.cpp:4:
../third_party/lua-intf/LuaIntf/src/CppBindModule.cpp:122:57: error: ‘meta’ was not declared in this scope
 LUA_INLINE CppBindModuleBase::CppBindModuleBase(LuaRef& meta, const char* name)
                                                         ^    
../third_party/lua-intf/LuaIntf/src/CppBindModule.cpp:122:63: error: expected primary-expression before ‘const’
 LUA_INLINE CppBindModuleBase::CppBindModuleBase(LuaRef& meta, const char* name)
                                                               ^    
../third_party/lua-intf/LuaIntf/src/CppBindModule.cpp:122:79: error: expression list treated as compound expression in initializer [-fpermissive]
 LUA_INLINE CppBindModuleBase::CppBindModuleBase(LuaRef& meta, const char* name)
                                                                               ^    
../third_party/lua-intf/LuaIntf/src/CppBindModule.cpp:123:1: error: expected ‘,’ or ‘;’ before ‘{’ token

这提示是源代码有语法错误啊,而且一刷就是一大屏幕,全是语法错误怎么可能我vs2015上就能过?肯定是环境不对吧?利用make >error.txt 2>&1 将error信息重定向输入到error.txt中进行分析,拉到第一行,定位到问题是:

/usr/local/include/c++/4.9.3/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support for the \

这就看明白了,需要用c++11来编译,修改LuaIntf.make,添加编译选项std=c++11问题解决。这里要吐槽下,源码github工程里面为啥不添加上这选项呢。。。

坑2:

链接时报错

/usr/bin/ld: ../third_party/lib/liblua.a(lapi.o): relocation R_X86_64_32 against `luaO_nilobject_' can not be used when making a shared object; recompile with -fPIC
../third_party/lib/liblua.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make[1]: *** [bin/Debug/libluapbintf.so] Error 1
make: *** [LuaPbIntf] Error 2

是编译的lua.a问问题,需要在编译lua.a时加上-fPIC。。。

坑3:

编译lua.a时也给我来个error:

lua.c:80:31: fatal error: readline/readline.h: No such file or directory
 #include <readline/readline.h>

查了下,是缺少libreadline-dev依赖包,执行如下命令,问题解决

centos: yum install readline-devel
debian: apt-get install libreadline-dev.

坑4:

LuaPbIntf还需要protobuf.a,在protobuf目录下执行autogen.sh时报错:

possibly undefined macro: AC_PROG_LIBTOOL

网上搜了一通,用下面两行解决:

yum install libtool  
yum install libsysfs

坑5:

不想说话了,直接贴error

Linking LuaPbIntf
/usr/bin/ld: cannot find -llibprotobuf
collect2: error: ld returned 1 exit status
make[1]: *** [bin/Release/libluapbintf.so] Error 1

什么东西啊,明明都生成了libprotobuf.a了,链接地址也是对的,你凭啥找不到啊。。。周五6点下班回家折腾你这玩意都到22:44分了,说好的夜跑都取消了,你还没给编译完,奔溃中。。。
好了,折腾不动了,下次再更新。
睡了一觉,脑子果然清醒多了。
早上一来,解决了。是生成的makefile里面把protobuf的名称写错了!!!我的库名叫libprotobuf.a,对于的编译链接应该是-lprotobuf而不是-llibprotobuf。。。。抓狂,好在解决了。。

坑填完了,服务器成功在我的centos上跑起来了,开心!!!
看看看

发布了47 篇原创文章 · 获赞 8 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/it_wjw/article/details/89577010