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 srkraju <ra...@cmcltd.com> on 2008/06/13 15:59:39 UTC

URGENT compliation error of sample program (test.cpp)

I am using Redhat Linux AS5, with g++ version 4.1.1

 

I compiled log4cxx0.10.0.tar.gz, apr-1.2.2, apr-util-1.2.2

 

Everything is successful. (configure, make, make check)

 

When I run a sample program, with

                        log4cxx::LoggerPtr
logger(log4cxx::Logger::getLogger("com.foo"));

in main function and tried to compile it with 

                        g++
-I/home/facts/Test/apache-log4cxx-0.10.0/src/main/include/  test.cpp

 

Source (test.cpp)

 

                        #include "log4cxx/logger.h"

#include "log4cxx/basicconfigurator.h"

#include "log4cxx/propertyconfigurator.h"

#include "log4cxx/helpers/exception.h"

 

using namespace log4cxx;

using namespace log4cxx::helpers;

 

 

int main(int argc, char **argv)

{

 

                                      log4cxx::LoggerPtr
logger(log4cxx::Logger::getLogger("com.foo"));

                                      return 0;

}

 

 

its giving the following error

                        

                                    /tmp/ccFOKkNH.o: In function `main':

test.cpp:(.text+0x21): undefined reference to
`log4cxx::Logger::getLogger(char const*)'

/tmp/ccFOKkNH.o: In function
`log4cxx::helpers::ObjectPtrT<log4cxx::Logger>::~ObjectPtrT()':

 

test.cpp:(.text._ZN7log4cxx7helpers10ObjectPtrTINS_6LoggerEED1Ev[log4cxx::he
lpers::ObjectPtrT<log4cxx::Logger>::~ObjectPtrT()]+0x40): undefined
reference to `log4cxx::helpers::ObjectPtrBase::~ObjectPtrBase()'

 

test.cpp:(.text._ZN7log4cxx7helpers10ObjectPtrTINS_6LoggerEED1Ev[log4cxx::he
lpers::ObjectPtrT<log4cxx::Logger>::~ObjectPtrT()]+0x59): undefined
reference to `log4cxx::helpers::ObjectPtrBase::~ObjectPtrBase()'

 

/tmp/ccFOKkNH.o: In function
`log4cxx::helpers::ObjectPtrT<log4cxx::Logger>::~ObjectPtrT()':

 

test.cpp:(.text._ZN7log4cxx7helpers10ObjectPtrTINS_6LoggerEED0Ev[log4cxx::he
lpers::ObjectPtrT<log4cxx::Logger>::~ObjectPtrT()]+0x40): undefined
reference to `log4cxx::helpers::ObjectPtrBase::~ObjectPtrBase()'

 

                                                ........

 

I understand that it's unable to locate the function in libraries. But there
were no shared objects generated. How can resolve this?

thanks& regards

srkraju

 


DISCLAIMER

“The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you"

Re: URGENT compliation error of sample program (test.cpp)

Posted by Curt Arnold <ca...@apache.org>.
On Jun 14, 2008, at 8:24 AM, Dale King wrote:

> On Sat, Jun 14, 2008 at 2:51 AM, srkraju <ra...@cmcltd.com> wrote:
>> Though its giving the same error.
>> I downloaded Ant-1.6.5. and extracted into
>> /home/facts/Test/apache-ant-1.6.5/ directory.
>>
>> g++  test.cpp -I/home/facts/Test/apache-log4cxx-0.10.0/src/main/ 
>> include
>> -L/home/facts/Test/apache-ant-1.6.5/lib/
>
> -L tells the linker where to look for libraries. You have to actually
> specify what libraries to look for as well using the -l option.
>
> So if your directory had libfoo.so in it that you needed to link with,
> you would add -l foo to your command line.


Apache Ant is a build tool implemented in Java.  You are placing the  
library directory of that product which contains only Java .jar files  
in the search path of a linker command that operates on .so, .a, .la  
or the like.  That accomplishes nothing.  log4cxx does provides for  
itself both autotools build script (the common approach for Unix  
environments) and an Ant based build script that is used for Unix and  
other platforms.  However, what build script used to build your  
application is independent.

What you likely should do is run:

cd apache-log4cxx-0.10.0
make
sudo make install

which will build log4cxx and then "install" it to /usr/local/lib.

Then you should be able to do:

g++ test.cpp -llog4cxx

(unlikely, but if it can't find log4cxx add a -L/usr/local/lib).

Re: URGENT compliation error of sample program (test.cpp)

Posted by Dale King <da...@gmail.com>.
On Sat, Jun 14, 2008 at 2:51 AM, srkraju <ra...@cmcltd.com> wrote:
> Though its giving the same error.
> I downloaded Ant-1.6.5. and extracted into
> /home/facts/Test/apache-ant-1.6.5/ directory.
>
> g++  test.cpp -I/home/facts/Test/apache-log4cxx-0.10.0/src/main/include
> -L/home/facts/Test/apache-ant-1.6.5/lib/

-L tells the linker where to look for libraries. You have to actually
specify what libraries to look for as well using the -l option.

So if your directory had libfoo.so in it that you needed to link with,
you would add -l foo to your command line.
-- 
Dale King

Re: URGENT compilation error of sample program

Posted by Dale King <da...@gmail.com>.
On Mon, Jun 16, 2008 at 2:22 AM, srkraju <ra...@cmcltd.com> wrote:
>                log4j.appender.A4=org.apache.log4j.DailyRollingFileAppender
>                log4j.appender.A4.File=example.log
>
>                log4j.appender.A4.DataPattern='.'yyyy-MM-dd-HH-mm


That should be DatePattern

-- 
Dale King

RE: URGENT compilation error of sample program

Posted by srkraju <ra...@cmcltd.com>.
Thanks Mr. Arnold. 
I am able to write simple configuration files for sample c++ programs.
I am able to view the log files when I used
		1. Log4j.appender.A1=org.apache.log4j.ConsoleAppender
		2. Log4j.appender.A2=org.apache.log4j.FileAppender
		3. log4j.appender.A3=org.apache.log4j.RollingFileAppender
		

	But when I configure like
		
		log4j.rootLogger=DEBUG, A4

		log4j.appender.A4=org.apache.log4j.DailyRollingFileAppender
		log4j.appender.A4.File=example.log
		
		log4j.appender.A4.DataPattern='.'yyyy-MM-dd-HH-mm
		log4j.appender.A4.Append=false

		log4j.appender.A4.layout=org.apache.log4j.PatternLayout
		log4j.appender.A4.layout.ConversionPattern=[%5p] %d{mm:ss} 


its giving the following error:
	log4cxx: Could not parse configuration file [Conf3.xml].
	log4cxx: Illegal state
	log4cxx: No appender could be found for logger (Conf3.xml).
	log4cxx: Please initialize the log4cxx system properly.
Any  Idea? Shall we have to use other keyword instead of 'Daily'	 in
the configuration file? Please find the version info in this mail.



thanks& regards
srkraju

~-----Original Message-----
~From: Curt Arnold [mailto:carnold@apache.org]
~Sent: Sunday, June 15, 2008 1:50 AM
~To: Log4CXX User
~Subject: Re: URGENT compilation error of sample program
~
~
~On Jun 14, 2008, at 6:58 AM, srkraju wrote:
~
~> Thanks Mr. Dale.
~> I solved the link error problem by location the shared objects
~> generated by
~> Log4Cxx_0.10.0, Apr_1.2.2, Apr-Util_1.2.2 packages. [ Redhat
~> Enterprise
~> Linux AS5, g++ version 4.1.1]
~>
~> I am trying to run the sample programs (bar.h, bar.cpp, MyApp2 given
~> in the
~> link
~> 		http://logging.apache.org/log4cxx/index.html
~> I am not getting the output exactly as expected.
~>
~> When I don't pass any argument it's giving
~> 		[facts@localhost Examples_srk]$ ./MyApp2
~>
~> 			0 [0xb7faaa20] INFO MyAppSrk null - Entering
~> application.
~> 			0 [0xb7faaa20] DEBUG com.foo.bar null - Did it
~> again!
~> 			0 [0xb7faaa20] INFO MyAppSrk null - Exiting
~> application.
~>
~> When I pass one argument it's giving
~> 		[facts@localhost Examples_srk]$ ./MyApp2 TestFile
~>
~> 			log4cxx: Could not read configuration file
~> [TestFile].
~> 			log4cxx: No appender could be found for logger
~> (MyAppSrk).
~> 			log4cxx: Please initialize the log4cxx system
~> properly
~>
~> I understand that the configuration file is not properly written.
~> What is
~> the format to write the configuration file? Can anybody give a
~> template of
~> configuration file? I also tried with the configuration file given
~> in the
~> above link. Still it is giving the same output.
~
~Is there a file named TestFile in your current working directory?
~log4cxx is reporting that you told it to read "TestFile" from the
~current working directory and use it as its configuration and the file
~could not be found.  There is an example of what the contents of the
~configuration file could look like following the source of MyApp2.cpp
~in the tutorial.  You should save that as TestFile and place that in
~the current directory.


DISCLAIMER

“The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you"

Re: URGENT compilation error of sample program

Posted by Curt Arnold <ca...@apache.org>.
On Jun 14, 2008, at 6:58 AM, srkraju wrote:

> Thanks Mr. Dale.
> I solved the link error problem by location the shared objects  
> generated by
> Log4Cxx_0.10.0, Apr_1.2.2, Apr-Util_1.2.2 packages. [ Redhat  
> Enterprise
> Linux AS5, g++ version 4.1.1]
>
> I am trying to run the sample programs (bar.h, bar.cpp, MyApp2 given  
> in the
> link
> 		http://logging.apache.org/log4cxx/index.html
> I am not getting the output exactly as expected.
>
> When I don't pass any argument it's giving
> 		[facts@localhost Examples_srk]$ ./MyApp2
>
> 			0 [0xb7faaa20] INFO MyAppSrk null - Entering
> application.
> 			0 [0xb7faaa20] DEBUG com.foo.bar null - Did it
> again!
> 			0 [0xb7faaa20] INFO MyAppSrk null - Exiting
> application.
>
> When I pass one argument it's giving
> 		[facts@localhost Examples_srk]$ ./MyApp2 TestFile
>
> 			log4cxx: Could not read configuration file
> [TestFile].
> 			log4cxx: No appender could be found for logger
> (MyAppSrk).
> 			log4cxx: Please initialize the log4cxx system
> properly
>
> I understand that the configuration file is not properly written.  
> What is
> the format to write the configuration file? Can anybody give a  
> template of
> configuration file? I also tried with the configuration file given  
> in the
> above link. Still it is giving the same output.

Is there a file named TestFile in your current working directory?   
log4cxx is reporting that you told it to read "TestFile" from the  
current working directory and use it as its configuration and the file  
could not be found.  There is an example of what the contents of the  
configuration file could look like following the source of MyApp2.cpp  
in the tutorial.  You should save that as TestFile and place that in  
the current directory.

RE: URGENT compilation error of sample program

Posted by srkraju <ra...@cmcltd.com>.
Thanks Mr. Dale.
I solved the link error problem by location the shared objects generated by
Log4Cxx_0.10.0, Apr_1.2.2, Apr-Util_1.2.2 packages. [ Redhat Enterprise
Linux AS5, g++ version 4.1.1] 

I am trying to run the sample programs (bar.h, bar.cpp, MyApp2 given in the
link
		http://logging.apache.org/log4cxx/index.html
I am not getting the output exactly as expected.

When I don't pass any argument it's giving
		[facts@localhost Examples_srk]$ ./MyApp2

			0 [0xb7faaa20] INFO MyAppSrk null - Entering
application.
			0 [0xb7faaa20] DEBUG com.foo.bar null - Did it
again!
			0 [0xb7faaa20] INFO MyAppSrk null - Exiting
application.

When I pass one argument it's giving
		[facts@localhost Examples_srk]$ ./MyApp2 TestFile

			log4cxx: Could not read configuration file
[TestFile].
			log4cxx: No appender could be found for logger
(MyAppSrk).
			log4cxx: Please initialize the log4cxx system
properly

I understand that the configuration file is not properly written. What is
the format to write the configuration file? Can anybody give a template of
configuration file? I also tried with the configuration file given in the
above link. Still it is giving the same output.
		

thanks& regards
srkraju

~-----Original Message-----
~From: Dale King [mailto:dalewking@gmail.com]
~Sent: Friday, June 13, 2008 7:56 PM
~To: Log4CXX User
~Subject: Re: URGENT compliation error of sample program (test.cpp)
~
~On Fri, Jun 13, 2008 at 9:59 AM, srkraju <ra...@cmcltd.com> wrote:
~>                         g++
~> -I/home/facts/Test/apache-log4cxx-0.10.0/src/main/include/  test.cpp
~>
~> its giving the following error
~>
~> test.cpp:(.text+0x21): undefined reference to
~> `log4cxx::Logger::getLogger(char const*)'
~
~That is a link error, not a compile error. The command line you show
~says to compile and link, but you didn't specify ant libraries to link
~against so it is not linking against log4cxx.
~
~--
~Dale King


DISCLAIMER

“The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you"

RE: URGENT compliation error of sample program (test.cpp)

Posted by srkraju <ra...@cmcltd.com>.
Though its giving the same error.
I downloaded Ant-1.6.5. and extracted into
/home/facts/Test/apache-ant-1.6.5/ directory. 

g++  test.cpp -I/home/facts/Test/apache-log4cxx-0.10.0/src/main/include
-L/home/facts/Test/apache-ant-1.6.5/lib/

Still its giving the same set of errors.
	test.cpp:(.text+0x21): undefined reference to
`log4cxx::Logger::getLogger(char const*)'
/tmp/ccnWzKdr.o: In function
`log4cxx::helpers::ObjectPtrT<log4cxx::Logger>::~ObjectPtrT()':
test.cpp:(.text._ZN7log4cxx7helpers10ObjectPtrTINS_6LoggerEED1Ev[log4cxx::he
lpers::ObjectPtrT<log4cxx::Logger>::~ObjectPtrT()]+0x40): undefined
reference to `log4cxx::helpers::ObjectPtrBase::~ObjectPtrBase()'
test.cpp:(.text._ZN7log4cxx7helpers10ObjectPtrTINS_6LoggerEED1Ev[log4cxx::he
lpers::ObjectPtrT<log4cxx::Logger>::~ObjectPtrT()]+0x59): undefined
reference to `log4cxx::helpers::ObjectPtrBase::~ObjectPtrBase()'


thanks& regards
srkraju
~-----Original Message-----
~From: Dale King [mailto:dalewking@gmail.com]
~Sent: Friday, June 13, 2008 7:56 PM
~To: Log4CXX User
~Subject: Re: URGENT compliation error of sample program (test.cpp)
~
~On Fri, Jun 13, 2008 at 9:59 AM, srkraju <ra...@cmcltd.com> wrote:
~>                         g++
~> -I/home/facts/Test/apache-log4cxx-0.10.0/src/main/include/  test.cpp
~>
~> its giving the following error
~>
~> test.cpp:(.text+0x21): undefined reference to
~> `log4cxx::Logger::getLogger(char const*)'
~
~That is a link error, not a compile error. The command line you show
~says to compile and link, but you didn't specify ant libraries to link
~against so it is not linking against log4cxx.
~
~--
~Dale King


DISCLAIMER

“The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you"

Re: URGENT compliation error of sample program (test.cpp)

Posted by Dale King <da...@gmail.com>.
On Fri, Jun 13, 2008 at 9:59 AM, srkraju <ra...@cmcltd.com> wrote:
>                         g++
> -I/home/facts/Test/apache-log4cxx-0.10.0/src/main/include/  test.cpp
>
> its giving the following error
>
> test.cpp:(.text+0x21): undefined reference to
> `log4cxx::Logger::getLogger(char const*)'

That is a link error, not a compile error. The command line you show
says to compile and link, but you didn't specify ant libraries to link
against so it is not linking against log4cxx.

-- 
Dale King