clang编译luabind项目报错和tcmalloc内存释放

想尝试新的东西总是会不小心踩到一些坑。下面记录最近在开发中遇到的clang编译luabind项目报错及tcmalloc内存释放问题。
1 由于项目大量使用模板和各种库导致编译如蜗牛,网上搜索了下据说clang编译器比gcc快,抱着尝试和锻炼的心态弄了一个来玩玩,要说改变项目编译环境那是不可能。但是在编译的过程中发现发现包含的luabind库文件有报错,报错如下:

/usr/local/include/luabind/detail/format_signature.hpp:104:33: error: reference to 'object' is ambiguous
LUABIND_TYPE_TO_STRING(luabind::object)
                                ^
/usr/local/include/luabind/detail/format_signature.hpp:82:27: note: expanded from macro 'LUABIND_TYPE_TO_STRING'
    struct type_to_string<x> \
                          ^
/usr/local/include/luabind/object.hpp:824:12: note: candidate found by name lookup is 'luabind::object'
using adl::object;
           ^
/usr/local/include/luabind/detail/format_signature.hpp:18:7: note: candidate found by name lookup is 'luabind::object'
class object;
      ^
/usr/local/include/luabind/detail/format_signature.hpp:105:33: error: reference to 'argument' is ambiguous
LUABIND_TYPE_TO_STRING(luabind::argument)
                                ^
/usr/local/include/luabind/detail/format_signature.hpp:82:27: note: expanded from macro 'LUABIND_TYPE_TO_STRING'
    struct type_to_string<x> \
                          ^
/usr/local/include/luabind/object.hpp:825:12: note: candidate found by name lookup is 'luabind::argument'
using adl::argument;
           ^
/usr/local/include/luabind/detail/format_signature.hpp:19:7: note: candidate found by name lookup is 'luabind::argument'
class argument;
      ^
/usr/local/include/luabind/detail/format_signature.hpp:111:23: error: reference to 'table' is ambiguous
struct type_to_string<table<Base> >
                      ^
/usr/local/include/luabind/object.hpp:1187:12: note: candidate found by name lookup is 'luabind::table'
using adl::table;
           ^
/usr/local/include/luabind/detail/format_signature.hpp:21:8: note: candidate found by name lookup is 'luabind::table'
struct table;
       ^
/usr/local/include/luabind/detail/format_signature.hpp:111:29: error: 'Base' does not refer to a value
struct type_to_string<table<Base> >
                            ^
/usr/local/include/luabind/detail/format_signature.hpp:110:17: note: declared here
template <class Base>
                ^
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/Vibranay_Script.cpp:3:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Manager.h:17:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Data.h:31:
In file included from /usr/local/include/luabind/luabind.hpp:28:
In file included from /usr/local/include/luabind/class.hpp:94:
In file included from /usr/local/include/luabind/function.hpp:8:
/usr/local/include/luabind/make_function.hpp:95:15: error: reference to 'object' is ambiguous
  LUABIND_API object make_function_aux(
              ^
/usr/local/include/luabind/object.hpp:824:12: note: candidate found by name lookup is 'luabind::object'
using adl::object;
           ^
/usr/local/include/luabind/detail/format_signature.hpp:18:7: note: candidate found by name lookup is 'luabind::object'
class object;
      ^
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/Vibranay_Script.cpp:3:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Manager.h:17:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Data.h:31:
In file included from /usr/local/include/luabind/luabind.hpp:28:
In file included from /usr/local/include/luabind/class.hpp:94:
In file included from /usr/local/include/luabind/function.hpp:8:
/usr/local/include/luabind/make_function.hpp:99:33: error: reference to 'object' is ambiguous
  LUABIND_API void add_overload(object const&, char const*, object const&);
                                ^
/usr/local/include/luabind/object.hpp:824:12: note: candidate found by name lookup is 'luabind::object'
using adl::object;
           ^
/usr/local/include/luabind/detail/format_signature.hpp:18:7: note: candidate found by name lookup is 'luabind::object'
class object;
      ^
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/Vibranay_Script.cpp:3:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Manager.h:17:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Data.h:31:
In file included from /usr/local/include/luabind/luabind.hpp:28:
In file included from /usr/local/include/luabind/class.hpp:94:
In file included from /usr/local/include/luabind/function.hpp:8:
/usr/local/include/luabind/make_function.hpp:99:33: error: reference to 'object' is ambiguous
  LUABIND_API void add_overload(object const&, char const*, object const&);
                                ^
/usr/local/include/luabind/object.hpp:824:12: note: candidate found by name lookup is 'luabind::object'
using adl::object;
           ^
/usr/local/include/luabind/detail/format_signature.hpp:18:7: note: candidate found by name lookup is 'luabind::object'
class object;
      ^
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/Vibranay_Script.cpp:3:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Manager.h:17:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Data.h:31:
In file included from /usr/local/include/luabind/luabind.hpp:28:
In file included from /usr/local/include/luabind/class.hpp:94:
In file included from /usr/local/include/luabind/function.hpp:8:
/usr/local/include/luabind/make_function.hpp:99:61: error: reference to 'object' is ambiguous
  LUABIND_API void add_overload(object const&, char const*, object const&);
                                                            ^
/usr/local/include/luabind/object.hpp:824:12: note: candidate found by name lookup is 'luabind::object'
using adl::object;
           ^
/usr/local/include/luabind/detail/format_signature.hpp:18:7: note: candidate found by name lookup is 'luabind::object'
class object;
      ^
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/Vibranay_Script.cpp:3:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Manager.h:17:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Data.h:31:
In file included from /usr/local/include/luabind/luabind.hpp:28:
In file included from /usr/local/include/luabind/class.hpp:94:
In file included from /usr/local/include/luabind/function.hpp:8:
/usr/local/include/luabind/make_function.hpp:104:1: error: reference to 'object' is ambiguous
object make_function(lua_State* L, F f, Signature, Policies)
^
/usr/local/include/luabind/object.hpp:824:12: note: candidate found by name lookup is 'luabind::object'
using adl::object;
           ^
/usr/local/include/luabind/detail/format_signature.hpp:18:7: note: candidate found by name lookup is 'luabind::object'
class object;
      ^
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/Vibranay_Script.cpp:3:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Manager.h:17:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Data.h:31:
In file included from /usr/local/include/luabind/luabind.hpp:28:
In file included from /usr/local/include/luabind/class.hpp:94:
In file included from /usr/local/include/luabind/function.hpp:8:
/usr/local/include/luabind/make_function.hpp:104:8: error: incomplete result type 'luabind::object' in function definition
object make_function(lua_State* L, F f, Signature, Policies)
       ^
/usr/local/include/luabind/detail/format_signature.hpp:18:7: note: forward declaration of 'luabind::object'
class object;
      ^
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/Vibranay_Script.cpp:3:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Manager.h:17:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Data.h:31:
In file included from /usr/local/include/luabind/luabind.hpp:28:
In file included from /usr/local/include/luabind/class.hpp:94:
In file included from /usr/local/include/luabind/function.hpp:8:
/usr/local/include/luabind/make_function.hpp:115:1: error: reference to 'object' is ambiguous
object make_function(lua_State* L, F f)
^
/usr/local/include/luabind/object.hpp:824:12: note: candidate found by name lookup is 'luabind::object'
using adl::object;
           ^
/usr/local/include/luabind/detail/format_signature.hpp:18:7: note: candidate found by name lookup is 'luabind::object'
class object;
      ^
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/Vibranay_Script.cpp:3:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Manager.h:17:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Data.h:31:
In file included from /usr/local/include/luabind/luabind.hpp:28:
In file included from /usr/local/include/luabind/class.hpp:94:
In file included from /usr/local/include/luabind/function.hpp:8:
/usr/local/include/luabind/make_function.hpp:115:8: error: incomplete result type 'luabind::object' in function definition
object make_function(lua_State* L, F f)
       ^
/usr/local/include/luabind/detail/format_signature.hpp:18:7: note: forward declaration of 'luabind::object'
class object;
      ^
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/Vibranay_Script.cpp:3:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Manager.h:17:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Data.h:31:
In file included from /usr/local/include/luabind/luabind.hpp:28:
In file included from /usr/local/include/luabind/class.hpp:94:
In file included from /usr/local/include/luabind/function.hpp:10:
/usr/local/include/luabind/detail/call_function.hpp:224:26: error: reference to 'object' is ambiguous
                        friend class luabind::object;
                                              ^
/usr/local/include/luabind/object.hpp:824:12: note: candidate found by name lookup is 'luabind::object'
using adl::object;
           ^
/usr/local/include/luabind/detail/format_signature.hpp:18:7: note: candidate found by name lookup is 'luabind::object'
class object;
      ^
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/Vibranay_Script.cpp:3:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Manager.h:17:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Data.h:31:
In file included from /usr/local/include/luabind/luabind.hpp:28:
In file included from /usr/local/include/luabind/class.hpp:94:
In file included from /usr/local/include/luabind/function.hpp:10:
In file included from /usr/local/include/luabind/detail/call_function.hpp:320:
In file included from /home/mzy/work/boost_1_56_0/boost/preprocessor/iteration/detail/iter/forward1.hpp:47:
/usr/local/include/luabind/detail/call_function.hpp:359:25: error: reference to 'object' is ambiguous
        call_function(luabind::object const& obj BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _) )
                               ^
/usr/local/include/luabind/object.hpp:824:12: note: candidate found by name lookup is 'luabind::object'
using adl::object;
           ^
/usr/local/include/luabind/detail/format_signature.hpp:18:7: note: candidate found by name lookup is 'luabind::object'
class object;
      ^
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/Vibranay_Script.cpp:3:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Manager.h:17:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Data.h:31:
In file included from /usr/local/include/luabind/luabind.hpp:28:
In file included from /usr/local/include/luabind/class.hpp:94:
In file included from /usr/local/include/luabind/function.hpp:10:
In file included from /usr/local/include/luabind/detail/call_function.hpp:320:
In file included from /home/mzy/work/boost_1_56_0/boost/preprocessor/iteration/detail/iter/forward1.hpp:47:
/usr/local/include/luabind/detail/call_function.hpp:371:6: error: member access into incomplete type 'const luabind::object'
                obj.push(obj.interpreter());
                   ^
/usr/local/include/luabind/detail/format_signature.hpp:18:7: note: forward declaration of 'luabind::object'
class object;
      ^
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/Vibranay_Script.cpp:3:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Manager.h:17:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Data.h:31:
In file included from /usr/local/include/luabind/luabind.hpp:28:
In file included from /usr/local/include/luabind/class.hpp:94:
In file included from /usr/local/include/luabind/function.hpp:10:
In file included from /usr/local/include/luabind/detail/call_function.hpp:320:
In file included from /home/mzy/work/boost_1_56_0/boost/preprocessor/iteration/detail/iter/forward1.hpp:47:
/usr/local/include/luabind/detail/call_function.hpp:372:24: error: member access into incomplete type 'const luabind::object'
                return proxy_type(obj.interpreter(), 1, &detail::pcall, args);
                                     ^
/usr/local/include/luabind/detail/format_signature.hpp:18:7: note: forward declaration of 'luabind::object'
class object;
      ^
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/Vibranay_Script.cpp:3:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Manager.h:17:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Data.h:31:
In file included from /usr/local/include/luabind/luabind.hpp:28:
In file included from /usr/local/include/luabind/class.hpp:94:
In file included from /usr/local/include/luabind/function.hpp:10:
In file included from /usr/local/include/luabind/detail/call_function.hpp:320:
In file included from /home/mzy/work/boost_1_56_0/boost/preprocessor/iteration/detail/iter/forward1.hpp:47:
/usr/local/include/luabind/detail/call_function.hpp:402:27: error: reference to 'object' is ambiguous
        resume_function(luabind::object const& obj BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) BOOST_PP_ENUM(BOOST_PP_ITERATION(), LUABIND_OPERATOR_PARAMS, _) )
                                 ^
/usr/local/include/luabind/object.hpp:824:12: note: candidate found by name lookup is 'luabind::object'
using adl::object;
           ^
/usr/local/include/luabind/detail/format_signature.hpp:18:7: note: candidate found by name lookup is 'luabind::object'
class object;
      ^
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/Vibranay_Script.cpp:3:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Manager.h:17:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Data.h:31:
In file included from /usr/local/include/luabind/luabind.hpp:28:
In file included from /usr/local/include/luabind/class.hpp:94:
In file included from /usr/local/include/luabind/function.hpp:10:
In file included from /usr/local/include/luabind/detail/call_function.hpp:320:
In file included from /home/mzy/work/boost_1_56_0/boost/preprocessor/iteration/detail/iter/forward1.hpp:47:
/usr/local/include/luabind/detail/call_function.hpp:414:6: error: member access into incomplete type 'const luabind::object'
                obj.push(obj.interpreter());
                   ^
/usr/local/include/luabind/detail/format_signature.hpp:18:7: note: forward declaration of 'luabind::object'
class object;
      ^
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/Vibranay_Script.cpp:3:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Manager.h:17:
In file included from /home/mzy/work/jwoll_server/Jwoll_Server0824_70/Script_Lib/./Script_Data.h:31:
In file included from /usr/local/include/luabind/luabind.hpp:28:
In file included from /usr/local/include/luabind/class.hpp:94:
In file included from /usr/local/include/luabind/function.hpp:10:
In file included from /usr/local/include/luabind/detail/call_function.hpp:320:
In file included from /home/mzy/work/boost_1_56_0/boost/preprocessor/iteration/detail/iter/forward1.hpp:47:
/usr/local/include/luabind/detail/call_function.hpp:415:24: error: member access into incomplete type 'const luabind::object'
                return proxy_type(obj.interpreter(), 1, &detail::resume_impl, args);
                                     ^
/usr/local/include/luabind/detail/format_signature.hpp:18:7: note: forward declaration of 'luabind::object'
class object;
      ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]

由于报错比较长,各种度娘不到,最后还是弄了个谷歌ip所以找到了一下解决方案:

将luabind/detail/format_signature.hpp文件中的如下内容:

namespace luabind {

class object;
class argument;
template <class Base>
struct table;

} // namespace luabind

修改为以下的形式
namespace luabind { namespace adl {
 class object;
 class argument;
 template <class Base>
 struct table;
 } // namespace adl
 using adl::object;
 using adl::argument;
 using adl::table;
 } // namespace luabind

谷歌搜索不能用真心伤不起,找个ip过几天又不能用,哎。

2  tcmalloc 内存不释放问题。

项目使用tcmalloc作为内存管理,但是最近测试服角色库增大导致内存不过,ps之后发现一个本来应该只可能需要几十M的服务器缺占用了两G多的内存,后来各种排查发现是tcmalloc没有将内存释放给系统,而是自己保存在了内存池中了。由于不知道当初编译tcmalloc库的配置,最后只好在程序中定时调用MallocExtension::instance()->ReleaseFreeMemory();将内存强制释放给系统,加上之后果然内存下降到了几十M。当内存足够的时候感觉没有人去看,也没有人检查内存泄露,项目也没有做任何工具检查测试服内存。在查这个问题的时候还发现ACE_Message_Block消息的内存泄露,不过不严重最后也就让他那样了。




你可能感兴趣的:(C++,TCMALLOC,内存释放,luabind)