1. 程式人生 > >clang編譯luabind專案報錯和tcmalloc記憶體釋放

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訊息的記憶體洩露,不過不嚴重最後也就讓他那樣了。