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 Ambarish Mitra <am...@persistent.co.in> on 2006/05/08 09:31:16 UTC

Linker Error in Application

Dear all,

I have used the Apache log4cxx framework in my application, and everything
is fine. I am on Solaris 8, and am using GNU g++ 3.3.2 and Solaris ld 5.9 to
build my application. There is no problem at all.

However, recently I moved the application sources to Linux (Redhat Linux)
and found that the application was not being built there. There were a lot
of linker errors regarding undefined symbols, all related to log4cxx. The
environment there is: g++ 3.4.5 and GNU ld 2.15.

Therefore, the only difference is while in first case, I used Solaris ld,
here I have GNU ld. Does it matter?

I did not give up and further investigated. For this, I wrote a minimal
program using the log framework, and still no success. The minimal code
snippet is given below:

LoggerPtr logger = Logger::getLogger(_T("root"));
int main()
{
        USES_CONVERSION;

        const String & propertyFileName = "logconf.txt";
	  PropertyConfigurator::configure(propertyFileName);

        return 0;
}


This did not work still, when I tried to link [-L and -l switches are
correct]

g++ -c -I/home/ambarish/softwares/log4cxx_097/include -o main.o main.cpp
g++ -o log -lpthread -L/home/ambarish/softwares/log4cxx/lib -llog4cpp main.o


main.o(.text+0x195): In function `main':
: undefined reference to
`log4cxx::PropertyConfigurator::configure(std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&)'
main.o(.text+0x26d): In function
`__static_initialization_and_destruction_0(int, int)':
: undefined reference to `log4cxx::Logger::getLogger(std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&)'

Any pointers will be extremely helpful. The exact same code works in Solaris
- can the differnt ld be a cause? If anyone has faced such a situation
before, please guide. 

Regards,
Ambarish.

Re: Linker Error in Application

Posted by Andreas Fester <af...@apache.org>.
Hi Ambarish,


Ambarish Mitra wrote:
[...]
> Therefore, the only difference is while in first case, I used Solaris ld,
> here I have GNU ld. Does it matter?
It should not. I am building the SVN Head each night (see
http://www.littletux.net/log4cxx) on Debian GNU/Linux using gcc 3.3.5.

[...]
> This did not work still, when I tried to link [-L and -l switches are
> correct]
Are you sure? Shouldnt the "-llog4cpp" be "-llog4cxx" ?

Ah, I just recognized one other thing: which version are you actually
using? Your path looks like you are using 0.9.7 which has some
severe bugs and is quite out of date. You should probably try
using 0.9.8 (which is, on the other hand, still under development).
A daily dist tarball is available at the above URL.

Regards,

	Andreas

> g++ -c -I/home/ambarish/softwares/log4cxx_097/include -o main.o main.cpp
> g++ -o log -lpthread -L/home/ambarish/softwares/log4cxx/lib -llog4cpp main.o
> 
> 
> main.o(.text+0x195): In function `main':
> : undefined reference to
> `log4cxx::PropertyConfigurator::configure(std::basic_string<char,
> std::char_traits<char>, std::allocator<char> > const&)'
> main.o(.text+0x26d): In function
> `__static_initialization_and_destruction_0(int, int)':
> : undefined reference to `log4cxx::Logger::getLogger(std::basic_string<char,
> std::char_traits<char>, std::allocator<char> > const&)'
> 
> Any pointers will be extremely helpful. The exact same code works in Solaris
> - can the differnt ld be a cause? If anyone has faced such a situation
> before, please guide. 
> 
> Regards,
> Ambarish.