简体   繁体   English

这个 gdb 核心是否因违反 ODR(一个定义规则)而发生?

[英]Is this gdb core occured by violation of ODR(One Definition Rule)?

I was working with code to include rapidjson headers in my server application.我正在使用代码在我的服务器应用程序中包含rapidjson标头。 When I compiled, it was ok.我编译的时候,没问题。 but when some other library part in the application was running, it turned out to be dead with gdb core file.但是当应用程序中的其他一些库部分正在运行时,结果是 gdb 核心文件已经死了。

#0  0x00007f36c614e922 in rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>::Malloc (this=0x7f36a4037700, size=256) at ../../common/include/rapidjson/allocators.h:321
321             RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0);
...
#17 0x00007f36c57999cb in dbgw::sql::NBaseTPreparedStatement::executeQuery (this=<optimized out>) at ../../src/dbgw/dbgw3/sql/nbase_t/NBaseTPreparedStatement.cpp:85

I realized the dynamic library actually has rapidjson in it already and I solved by adding namespace to newly added rapidjson after I saw this below我意识到动态库中实际上已经有rapidjson ,我在下面看到这个后通过向新添加的rapidjson添加命名空间来解决

https://rapidjson.org/group___r_a_p_i_d_j_s_o_n___c_o_n_f_i_g.html#ga743a79d3af927391fe3eb5c979136899 https://rapidjson.org/group___r_a_p_i_d_j_s_o_n___c_o_n_f_i_g.html#ga743a79d3af927391fe3eb5c979136899

So what I am curious about is...所以我很好奇的是...

Q1.Is this happened because multiple inclusions violated ODR, shared library unexpectedly (because of overwritten symbol stuff) runned newly added (maybe different version of) rapidjson code, and it resulted to throw exception? Q1.这是不是因为多个包含违反了ODR,共享库意外(因为覆盖了符号内容)运行了新添加的(可能是不同版本的) rapidjson代码,导致抛出异常?

Q2. Q2。 Can I assume the reason that previous declaration error didn't occur while compile is that it was "shared" library and only linked when the application is run?(unlike static library)我可以假设编译时没有发生previous declaration错误的原因是它是“共享”库并且仅在应用程序运行时链接?(与静态库不同)

Is this happened because multiple inclusions violated ODR, shared library unexpectedly (because of overwritten symbol stuff) runned newly added (maybe different version of) rapidjson code, and it resulted to throw exception?这是因为多个包含违反了 ODR,共享库意外(因为覆盖了符号内容)运行了新添加的(可能是不同版本的)rapidjson 代码,并导致抛出异常?

It's possible that that is the cause, but you have supplied far too few details to tell.这可能是原因,但您提供的细节太少,无法说明。

Can I assume the reason that previous declaration error didn't occur while compile is that it was "shared" library and only linked when the application is run?(unlike static library)我可以假设编译时没有发生先前声明错误的原因是它是“共享”库并且仅在应用程序运行时链接?(与静态库不同)

Probably not.可能不是。 "Previous declaration" is a compile time error, and you wouldn't expect one here (with separate translation units). “先前声明”是一个编译时错误,您不会期望这里有一个错误(带有单独的翻译单元)。

What you are probably asking is "why didn't multiple definition link error happen?".您可能要问的是“为什么没有发生多重定义链接错误?”。 If so, yes: it is not an error to have the same symbol definition in the main executable and one (or more) shared library it is using.如果是这样,是的:在主可执行文件和它正在使用的一个(或多个)共享库中具有相同的符号定义并不是错误。 This is in fact very common, and what allows an application to use a different malloc implementation despite having malloc inside libc .这实际上很常见,并且允许应用程序使用不同的 malloc 实现,尽管在libcmalloc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM