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 Daniel Kasten <ma...@danielkasten.de> on 2005/10/30 19:11:18 UTC

How to compile simple test programm with static linking?

Hi,
I just build a static version from the svn head and tried to compile a little 
test programm with static linking. Without success till now. :/
Perhaps someone can give me a hint, what i might have done wrong.
So here is what I did so far:

Build SVN Version with:
ant -Ddebug=true -Doptimize=none -Dlib.type=static -Dapr.lib.type=static 
-Daprutil.lib.type=static -Dapriconv.lib.type=static 

Produced libapr-1.a, libaprutil-1.a, liblog4cxx.a and some other files in 
build/debug/static

Than I wrote a little test programm:
#include <log4cxx/logger.h>
#include <log4cxx/basicconfigurator.h>
#include <log4cxx/propertyconfigurator.h>
#include <log4cxx/helpers/exception.h>

#include <iostream>

using namespace std;
using namespace log4cxx;
using namespace log4cxx::helpers;

LoggerPtr logger(Logger::getLogger("MyLogging.Test"));

int main(int argc, char *argv[])
{
//  LOG4CXX_ERROR(logger, "My first error Log");
  cout << "jojo" << endl;


return 0;
}


And tried to compile it with:
g++ -I./include -L./lib -llog4cxx  -static -o test  test.cpp

And the result is:
/tmp/ccUOHsmb.o: In function `__static_initialization_and_destruction_0(int, 
int)':
test.cpp:(.text+0xda): undefined reference to `log4cxx::Logger::getLogger(char 
const*)'
collect2: ld returned 1 exit status

And yes, I copied the log4cxx include dir to ./include and the .a to ./lib
When I build and shared version with ant first and than do the same thing 
with .so and without -static everything works just fine.

Hope someone can help me.

Best regards, 
Daniel

PS: Anyone knows how to cross-compile log4cxx with ant? 


Re: How to compile simple test programm with static linking?

Posted by Daniel Kasten <ma...@danielkasten.de>.
Hi, 
thanks a lot. I managed to compile the the test programm with an ant build 
script.
Your libtool hint still produces some error when he tries to link.
I downloaded your binary version from littletux and libtool said that it 
misses "libaprutil-1.la", so I took a look into iblog4cxx.la and created 
the .la files for apr on my own.
But than I get this nasty linking errors again. :/
Btw. is there a better solution than hardcoding file path to libaprutil-1.la 
in the iblog4cxx.la file?

I also still didn't find out how to cross-compile with the ant build.xml, is 
it possible anyway? Hmm, perhaps this should be handeled in a different 
thread. 

Best regards,
Daniel


Am Montag, 31. Oktober 2005 12:37 schrieb Andreas Fester:
> Hi,
>
> I did not find the reason why it does not work the way
> you do it, but it works when you are using libtool:
>
> $ libtool --mode=compile g++ -static -c -I../log4cxx-0.9.8/include -o
> test.o  test.cpp
>
> $ libtool --mode=link g++ ../log4cxx-0.9.8-build/src/.libs/liblog4cxx.la
> -static -o test test.o
>
> > I just build a static version from the svn head and tried to compile a
> > little
>
> You should probably consider using the version from
> http://www.littletux.net/log4cxx since it contains some additional
> patches which have not yet been committed to SVN.
>
> Best Regards,
>
> 	Andreas
>
> [...]
>
> > #include <log4cxx/logger.h>
> > #include <log4cxx/basicconfigurator.h>
> > #include <log4cxx/propertyconfigurator.h>
> > #include <log4cxx/helpers/exception.h>
> >
> > #include <iostream>
> >
> > using namespace std;
> > using namespace log4cxx;
> > using namespace log4cxx::helpers;
> >
> > LoggerPtr logger(Logger::getLogger("MyLogging.Test"));
> >
> > int main(int argc, char *argv[])
> > {
> > //  LOG4CXX_ERROR(logger, "My first error Log");
> >   cout << "jojo" << endl;
> >
> >
> > return 0;
> > }
> >
> >
> > And tried to compile it with:
> > g++ -I./include -L./lib -llog4cxx  -static -o test  test.cpp
> >
> > And the result is:
> > /tmp/ccUOHsmb.o: In function
> > `__static_initialization_and_destruction_0(int, int)':
> > test.cpp:(.text+0xda): undefined reference to
> > `log4cxx::Logger::getLogger(char const*)'
> > collect2: ld returned 1 exit status

Re: How to compile simple test programm with static linking?

Posted by Andreas Fester <An...@gmx.de>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I did not find the reason why it does not work the way
you do it, but it works when you are using libtool:

$ libtool --mode=compile g++ -static -c -I../log4cxx-0.9.8/include -o
test.o  test.cpp

$ libtool --mode=link g++ ../log4cxx-0.9.8-build/src/.libs/liblog4cxx.la
- -static -o test test.o

> I just build a static version from the svn head and tried to compile a little 
You should probably consider using the version from
http://www.littletux.net/log4cxx since it contains some additional
patches which have not yet been committed to SVN.

Best Regards,

	Andreas

[...]
> #include <log4cxx/logger.h>
> #include <log4cxx/basicconfigurator.h>
> #include <log4cxx/propertyconfigurator.h>
> #include <log4cxx/helpers/exception.h>
> 
> #include <iostream>
> 
> using namespace std;
> using namespace log4cxx;
> using namespace log4cxx::helpers;
> 
> LoggerPtr logger(Logger::getLogger("MyLogging.Test"));
> 
> int main(int argc, char *argv[])
> {
> //  LOG4CXX_ERROR(logger, "My first error Log");
>   cout << "jojo" << endl;
> 
> 
> return 0;
> }
> 
> 
> And tried to compile it with:
> g++ -I./include -L./lib -llog4cxx  -static -o test  test.cpp
> 
> And the result is:
> /tmp/ccUOHsmb.o: In function `__static_initialization_and_destruction_0(int, 
> int)':
> test.cpp:(.text+0xda): undefined reference to `log4cxx::Logger::getLogger(char 
> const*)'
> collect2: ld returned 1 exit status

- --
Andreas Fester
mailto:andreas@littletux.net
WWW: http://www.littletux.net
ICQ: 326674288
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDZgIDZ3bQVzeW+rsRApJEAKCREhYL7mixAt525uvC1p7kxf1lCQCgqH90
8dghSvud8tqH9ecUkYSG8hg=
=IECT
-----END PGP SIGNATURE-----