How can I resolve single symbol link error when dynamically linking XCode project to lib4cxx library?

心不动则不痛 提交于 2019-12-23 04:35:25

问题


I'm writing in C++ under XCode 4.6 on Mountain Lion. I'm trying to add and use the Apache log4cxx library. I installed the library this morning via Brew. I'm linking against liblog4cxx.dylib. I'm getting a link error that just one symbol can't be found:

Undefined symbols for architecture x86_64:
"log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT const&, std::__1::basic_string, std::__1::allocator > const&, log4cxx::spi::LocationInfo const&) const", referenced from:

I know it's finding the library file because if I remove it, I get lots more undefined symbol errors relating to log4cxx.

relevant code is basically:

#include <log4cxx/logger.h>

static LoggerPtr  logger(log4cxx::Logger::getLogger("foo.bar.Baz"));

void foo(int p1, int p2)
{
    LOG4CXX_WARN(logger, "blah blah blah");
}

Creating the logger object inside the function, either as static or not, doesn't change the behavior. Also, linking with the static library, with or without defining LOG4CXX_STATIC in my project, does not change the behavior.

Looking at the macro I'm calling, I see that this symbol is the actual method that performs the log operation. If take out the logging call but leave in the code that defines the logger object, the code links fine as you might expect.

What do I need to do to have this last symbol resolve?

TIA!


回答1:


I traced my issue down to compiling the library in a non C++11 compiler, but then my target project was a C++11 compiler.

I was able to compile log4cxx in a C+11 compiler by viewing the changes to log4cxx in the development git repo, which mainly consisted of inserting static_casts, as in this update:

http://apache-logging.6191.n7.nabble.com/C-11-does-not-allow-char-literals-with-highest-bit-set-unless-cast-td34908.html

I suppose the few incompatible routines came up undefined, which is why we were getting confused with only a few seemingly random undefines. (Or I was anyway)



来源:https://stackoverflow.com/questions/15865826/how-can-i-resolve-single-symbol-link-error-when-dynamically-linking-xcode-projec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!