How can I resolve single symbol link error when dy

2019-05-29 19:50发布

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条回答
一纸荒年 Trace。
2楼-- · 2019-05-29 20:22

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)

查看更多
登录 后发表回答