I am trying to build log4cxx version 0.10.0 under Visual Studio 2013. I have done all the fixes as specified in building log4cxx in vs 2010 c++.
However, it is now failing at the link stage, when trying to create log4cxx.lib, with the following errors:
unresolved external symbol __InterlockedIncrement referenced in function _apr_atomic_inc32@4
unresolved external symbol __InterlockedExchangeAdd referenced in function _apr_atomic_add32@8
unresolved external symbol __InterlockedExchange referenced in function _apr_atomic_set32@8
unresolved external symbol __InterlockedDecrement referenced in function _apr_atomic_dec32@4
unresolved external symbol __InterlockedCompareExchange referenced in function _apr_atomic_cas32@12
According to MSDN, these function should be in kernel32.lib, and I have added this to the linker, with no effect. Looking at ht elib, this appears to contain _InterlockedIncrement
(single underscore) and _imp_InterlockedIncrement
Does anyone know what I can do to get it working?
Also, the fix suggested in Building log4cxx with VS 2012 on Windows 7 does not make any different
The following worked for me with respect to log4cxx:
VS2013 APR link issue
The cause of the linking errors is the APR (Apache Portable Runtime) library.
In the file
atomic\win32\apr_atomic.c
, there are calls to the various interlocked functions, in the form:where
apr_atomic_win32_ptr_fn
is defined asAs the compiler is building a 32 bit executable, the second call is used. This cast causes the compiler not to recognise
InterlockedIncrement
as a built in, and generate a call to__InterlockedIncrement()
, rather than the expected intrinsic.As a temporary fix, I have edited the calls to use the same call as the 64 bit version.
The procedure below is a complete process for building Log4CXX under VS2013, for both 32 and 64 bit builds. Note the 32 bit build has been very lightly tested, and the 64 bit build has been slightly more extensively tested (I.E, it's the version we're using).
apache-log4cxx-0.10.0.zip
,apr-x.y.z-win32.src.zip
andapr-util-1.5.4-win32.src.zip
, wherex
,y
andz
are the latest versions.apr-x.y.z
andapr-utls-x.y.z
to remove the version numbers.log4cxx
. See below.For the 32 bit version, patch
apr\atomic\win32\apr_atomic.c
.Replace all occurrences of
defined(_M_IA64) || defined(_M_AMD64))
withdefined(_M_IA64) || defined(_M_AMD64) || (_MSC_VER == 1800))
This is only really a temporary fix, but it works.
apache-log4cxx-0.10.0\configure.bat
.apr-util
.include\apu.hw
, changeAPU_HAVE_APR_ICONV
to be defined as 0.include\apr_ldap.hw
, changeAPR_HAS_LDAP
to be defined as 0.apache-log4cxx-0.10.0\projects\log4cxx.dsw
into Visual Studio 2013. You will be prompted to upgrade the projects. Accept, and wait for the conversion to complete. This will createlog4cxx.sln
which you should use next time you open the projectBuild->Configuration Manager
. Create x64 project contexts forlog4cxx
, both release and debug. Check the build box for these items.Upgrade VC++ compiler ...
.log4cxx
project, and selectproperties
.Debug / All platforms
configuration setup.Configuration Properties / General / Target name
to have "_d" as end of file name.Linker / All Options / Output File
to have "_d" as end of file name.Linker / All Options / Import Library
to have "_d" as end of file name.Build -> Configuration manager
.Below is the patch required for
log4cxx
.