You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-user@logging.apache.org by Ricardo Balbinot <rb...@gmail.com> on 2010/02/18 03:15:37 UTC

Problems using log4cxx.lib with VS2008 (link problems with applications)

I'am using log4cxx with g++ for about one and a half year, without any
problema at all...

But now I have to develop something in Windows, and I must use VS2008...

I read a lot of messages in the list, and I get that I have to build the
library as a static library, but I do think I am not doing it the proper
way...

Two steps:
1) I build the library itself... I select the static library option, /MTd
and I do set the preprocessor to these values:

OBS: apr, apr_util and xml projects use the /MDd option... I choosed not to
change that at first (at least, no one said it should be done). And I do
guess that is not important at all...
OBS2: note that with VS2008 at least, it is not possible to specify another
libraries that lib4cxx.lib has dependencies... well, the compiler does not
return any error messages anyway... it does build the lib right away...

ORIGINAL VALUES:
_DEBUG
_USRDLL
DLL_EXPORTS
LOG4CXX
APR_DECLARE_STATIC
APU_DECLARE_STATIC
WIN32

First try:
_DEBUG
_USRDLL
DLL_EXPORTS
LOG4CXX_STATIC
APR_DECLARE_STATIC
APU_DECLARE_STATIC
WIN32

Result: a log4cxx.lib file with 37MB

Second try: I delete anything that shows DLL.. :)
_DEBUG
LOG4CXX_STATIC
APR_DECLARE_STATIC
APU_DECLARE_STATIC
WIN32

Result: a log4cxx.lib file with 37MB

It is important to notice that in both cases the library is built by the
compiler with no complaints at all...

2) I try to build my applications..
I do use the LOG4CXX_STATIC preprocessor directive and I do include the
indicated libs... (advapi32.lib, mswsock.lib, shell32.lib, WS2_32.lib,
log4cxx.lib)

OBS: I also tried to insert APR_DECLARE_STATIC and APU_DECLARE_STATIC in the
directives (I guess it is not necessary at all), but with no change...

But no matter what I do, I always get a lot of messages complaining about
apr and apr_util, just like these:
1>log4cxx.lib(serversocket.obj) : error LNK2019: unresolved external symbol
_apr_poll@20 referenced in function "public: class
log4cxx::helpers::ObjectPtrT<class log4cxx::helpers::Socket> __thiscall
log4cxx::helpers::ServerSocket::accept(void)" (?accept@ServerSocket
@helpers@log4cxx@@QAE?AV?$ObjectPtrT@VSocket@helpers@log4cxx@@@23@XZ)
1>log4cxx.lib(socket.obj) : error LNK2019: unresolved external symbol
_apr_socket_connect@8 referenced in function "public: __thiscall
log4cxx::helpers::Socket::Socket(class log4cxx::helpers::ObjectPtrT<class
log4cxx::helpers::InetAddress> &,int)" (??0Socket@helpers@log4cxx@@QAE@AAV
?$ObjectPtrT@VInetAddress@helpers@log4cxx@@@12@H@Z)
1>log4cxx.lib(datagramsocket.obj) : error LNK2001: unresolved external
symbol _apr_socket_connect@8
1>log4cxx.lib(socket.obj) : error LNK2019: unresolved external symbol
_apr_sockaddr_ip_get@8 referenced in function "public: __thiscall
log4cxx::helpers::Socket::Socket(struct apr_socket_t *,struct apr_pool_t *)"
(??0Socket@helpers@log4cxx@@QAE@PAUapr_socket_t@@PAUapr_pool_t@@@Z)
1>log4cxx.lib(inetaddress.obj) : error LNK2001: unresolved external symbol
_apr_sockaddr_ip_get@8

Notice that there are LNK2019 and LNK2001 errors.

Does anyone have any idea on what am I doing wrong?

As I understand those messages the linker is complaining about a function
from apr...... but when I do build the lib4cxx static library, I guess those
apr and apr_util functions are built in together with lib4cxx... I also
tries to simply put the apr and apr_util libs in the lib path, and even
include directly on my project.. no success and no change in behavior...
I did not buils apr and apr_utils before log4cxx, cause (I guess) it is not
necessary.. simply building log4cxx from the VS project does that.

Best regards,
Ricardo

Re: Problems using log4cxx.lib with VS2008 (link problems with applications)

Posted by Ricardo Balbinot <rb...@gmail.com>.
Well, I guess I got it...

As it is so hard to properly find this information (and it would have saved
me about a day of frustrating work), here is how I did solved the problem (I
guess...):

STEP 1) TO COMPILE LIB4CXX AS A STATIC LIBRARY....

1) Just open the log4cxx project/solution already sent with the downloaded
source files....
2) Go the log4cxx project, and open its properties dialog...
3) Select Configuration Properties->General and set Configuration Type to
Static Library (.lib)
4) Go to Configuration Properties->Preprocessor and add to Preprocessor
Definitions the following (LOG4CXX_STATIC) ---> this is the only thing that
I read everywhere, but it is not enough...
5) Go to Configuration Properties->Code Generation and set RunTime Library
to Multi-threaded Debug (/MTd) --> with you want a release (without debug
option), you have to change this option... I do not know if it is really
necessary, but aldo DO SET the same property for apr, apr_util and xml...
6) Build log4cxx
7) My result is a file named log4cxx.lib with about 37MB of space... (I have
seen another option of the lib with only 15MB... why? I REALLY do not
know...)

STEP 2) HOW TO USE LIB4CXX AS A STATIC LIBRARY

If you usually program in C++ for Linux as I do, this is quite interesting
(and I feel like really stupid after discovering it): you have to list all
(I mean ALL) static libraries need for log4cxx.lib... this is just not
necessary for g++, as it has all libs in one place (usually) and is quite
capable of searching for those dependency libraries.... but guess what...
VC++ does not do that...
So...
1) First of all... you project has to match the log4cxx version.. that
means, if you use a /MTd definition while building the lib, you do have to
use the same option with your project... So, go to Configuration
Properties->Code Generation and set RunTime Library to Multi-threaded Debug
(/MTd) or any other option you want (in the case of a static lib, only
/MT...)
2) Second of all, as it is found in some messages, you do have to add
LOG4CXX_STATIC to Preprocessor Definitions of your project also...
3) This was my error.... you do have to explicit all paths and libs you use,
so add the path to log4cxx.lib (obvious), but also to apr-1.lib,
aprutil-1.lib, xml.lib...
4) Add all libs you need (Linker->Input->Additional Dependencies) and DO ADD
the following: WS2_32.Lib, MsWSock.Lib, AdvAPI32.Lib, odbc32.lib (this is
already said in the list)... AND ALSO ADD log4cxx.lib - this is what you
want, after all, but also add the apr, apr_util and xml static libraries...
in my case: apr-1.lib, aprutil-1.lib, xml.lib
Build your project, and it should work... (if I did not forgot anything
else...).

I will try to elaborate this a little, but I guess something like that
should be inserted in log4cxx wiki...

If you want an easier solution (yesterday I got this, but I was not happy
with the fact that I was unable to do it myself):
http://www.dreamcubes.com/b2/software-development/28/log4cxx-for-win32-with-vs2005/

Also, I guess it should be said: if you want to debug you project, you need
a debug log4cxx.lib version, if you want to release it, you need a release
version of the lib, and so on...
Also, as the lib uses a lot of C++, a lib version for VS2003 will not work
in VS2008, cause there is a lot of changes from STL from VS2003 to
VS2008.... you do need to compile it using the same compile version... (as I
searched in the web, this is true for most of the static libraries at least
with VC++).

If I said anything or a lot of things that is wrong, please correct me :) :)


Regards,
Ricardo






2010/2/17 Ricardo Balbinot <rb...@gmail.com>

>
> I'am using log4cxx with g++ for about one and a half year, without any
> problema at all...
>
> But now I have to develop something in Windows, and I must use VS2008...
>
> I read a lot of messages in the list, and I get that I have to build the
> library as a static library, but I do think I am not doing it the proper
> way...
>
> Two steps:
> 1) I build the library itself... I select the static library option, /MTd
> and I do set the preprocessor to these values:
>
> OBS: apr, apr_util and xml projects use the /MDd option... I choosed not to
> change that at first (at least, no one said it should be done). And I do
> guess that is not important at all...
> OBS2: note that with VS2008 at least, it is not possible to specify another
> libraries that lib4cxx.lib has dependencies... well, the compiler does not
> return any error messages anyway... it does build the lib right away...
>
> ORIGINAL VALUES:
> _DEBUG
> _USRDLL
> DLL_EXPORTS
> LOG4CXX
> APR_DECLARE_STATIC
> APU_DECLARE_STATIC
> WIN32
>
> First try:
> _DEBUG
> _USRDLL
> DLL_EXPORTS
> LOG4CXX_STATIC
> APR_DECLARE_STATIC
> APU_DECLARE_STATIC
> WIN32
>
> Result: a log4cxx.lib file with 37MB
>
> Second try: I delete anything that shows DLL.. :)
> _DEBUG
> LOG4CXX_STATIC
> APR_DECLARE_STATIC
> APU_DECLARE_STATIC
> WIN32
>
> Result: a log4cxx.lib file with 37MB
>
> It is important to notice that in both cases the library is built by the
> compiler with no complaints at all...
>
> 2) I try to build my applications..
> I do use the LOG4CXX_STATIC preprocessor directive and I do include the
> indicated libs... (advapi32.lib, mswsock.lib, shell32.lib, WS2_32.lib,
> log4cxx.lib)
>
> OBS: I also tried to insert APR_DECLARE_STATIC and APU_DECLARE_STATIC in
> the directives (I guess it is not necessary at all), but with no change...
>
> But no matter what I do, I always get a lot of messages complaining about
> apr and apr_util, just like these:
> 1>log4cxx.lib(serversocket.obj) : error LNK2019: unresolved external symbol
> _apr_poll@20 referenced in function "public: class
> log4cxx::helpers::ObjectPtrT<class log4cxx::helpers::Socket> __thiscall
> log4cxx::helpers::ServerSocket::accept(void)" (?accept@ServerSocket
> @helpers@log4cxx@@QAE?AV?$ObjectPtrT@VSocket@helpers@log4cxx@@@23@XZ)
> 1>log4cxx.lib(socket.obj) : error LNK2019: unresolved external symbol
> _apr_socket_connect@8 referenced in function "public: __thiscall
> log4cxx::helpers::Socket::Socket(class log4cxx::helpers::ObjectPtrT<class
> log4cxx::helpers::InetAddress> &,int)" (??0Socket@helpers@log4cxx@@QAE@AAV
> ?$ObjectPtrT@VInetAddress@helpers@log4cxx@@@12@H@Z)
> 1>log4cxx.lib(datagramsocket.obj) : error LNK2001: unresolved external
> symbol _apr_socket_connect@8
> 1>log4cxx.lib(socket.obj) : error LNK2019: unresolved external symbol
> _apr_sockaddr_ip_get@8 referenced in function "public: __thiscall
> log4cxx::helpers::Socket::Socket(struct apr_socket_t *,struct apr_pool_t *)"
> (??0Socket@helpers@log4cxx@@QAE@PAUapr_socket_t@@PAUapr_pool_t@@@Z)
> 1>log4cxx.lib(inetaddress.obj) : error LNK2001: unresolved external symbol
> _apr_sockaddr_ip_get@8
>
> Notice that there are LNK2019 and LNK2001 errors.
>
> Does anyone have any idea on what am I doing wrong?
>
> As I understand those messages the linker is complaining about a function
> from apr...... but when I do build the lib4cxx static library, I guess those
> apr and apr_util functions are built in together with lib4cxx... I also
> tries to simply put the apr and apr_util libs in the lib path, and even
> include directly on my project.. no success and no change in behavior...
> I did not buils apr and apr_utils before log4cxx, cause (I guess) it is not
> necessary.. simply building log4cxx from the VS project does that.
>
> Best regards,
> Ricardo
>
>


-- 
-------------------------------
Me. Ricardo Balbinot