metageek
metageek

Reputation: 31

Writing custom log4cxx policy, linker can't find log4cxx::helper::Object::cast

I'm using log4cxx 0.10.0, and I need to roll over either hourly or when the file size gets too large. My initial attempt was to configure rollingPolicy to be TimeBasedRollingPolicy and triggerPolicy to be SizeBasedTriggeringPolicy; but that doesn't work, because TBRP is also a triggering policy. So I've written a SizeAndTimePolicy class which inherits from TriggeringPolicy and RollingPolicy, and contains a TBRP and an SBTP, and delegates to them. It compiles, but at link time I get this error message:

/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: util/libutil_lib.a(CustomLogPolicies.cpp.o): in function `log4cxx::rolling::SizeAndTimePolicy::cast(log4cxx::helpers::Class const&) const': /home/jstracke/git/scidb/include/util/CustomLogPolicies.h:23: undefined reference to `log4cxx::helpers::Object::cast(log4cxx::helpers::Class const&) const'

And, sure enough, nm -D on /usr/lib64/liblog4cxx.so.10.0.0 does not find that symbol. The closest it finds is _ZNK7log4cxx7helpers10ObjectPtrTINS0_6ObjectEE4castERKNS0_5ClassE.

The line it's referring to is LOG4CXX_CAST_ENTRY_CHAIN(RollingPolicy). Interestingly, it doesn't complain on the previous line, which is LOG4CXX_CAST_ENTRY_CHAIN(TriggeringPolicy).

I have checked my link line to make sure that -llog4cxx comes after my CustomLogPolicies.cpp.o.

I'm on CentOS 7 (which is why I'm stuck on log4cxx 0.10.0). And, yes, C7 is ancient; but we can't quite get away from it yet. We're getting close to shipping on a more modern distro, but we might have to support C7 for a bit longer as well.

Any help would be greatly appreciated.

(Edited to add: I've built 0.13.0, and it gives me the same problem.)

Upvotes: 0

Views: 98

Answers (1)

metageek
metageek

Reputation: 31

I found a workaround, but I don't like it: I edited log4cxx 0.13.0 to give Object::cast() an implementation, instead of being pure virtual, and created an object.cpp file to contain it. I also put the virtual destructor in that file; it was previously inline, which doesn't work so well, since the file containing the virtual destructor is the file that contains the vtable.

Upvotes: 0

Related Questions