1

我在 Mountain Lion 上的 XCode 4.6 下用 C++ 编写。我正在尝试添加和使用 Apache log4cxx 库。我今天早上通过 Brew 安装了库。我正在链接 liblog4cxx.dylib。我收到一个链接错误,找不到一个符号:

架构 x86_64 的未定义符号:
“log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT const&, std::__1::basic_string, std::__1::allocator > const&, log4cxx::spi::LocationInfo const& ) const",引用自:

我知道它正在查找库文件,因为如果我删除它,我会得到更多与 log4cxx 相关的未定义符号错误。

相关代码基本上是:

#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");
}

在函数内部创建记录器对象,无论是静态的还是非静态的,都不会改变行为。此外,与静态库链接,无论是否在我的项目中定义 LOG4CXX_STATIC,都不会改变行为。

查看我正在调用的宏,我看到这个符号是执行日志操作的实际方法。如果取出日志记录调用但保留定义记录器对象的代码,则代码链接正常,如您所料。

我需要做什么才能解析最后一个符号?

蒂亚!

4

1 回答 1

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)

于 2014-01-12T04:13:04.267 回答