[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [xmlblaster] Compiling cpp client in mac osx



Hi,

if have added a

int main()
{
struct hostent hostbuf, *hostP = 0;
char *tmphstbuf=0;
size_t hstbuflen=0;
char serverHostName[256];
strcpy(serverHostName, "localhost");
hostP = gethostbyname_re(serverHostName, &hostbuf, &tmphstbuf, &hstbuflen);
printf("Hello '%s'\n", hostP->h_name);
return 0;
}


to msgUtil.c, please check it out from svn and compile it with

cd xmlBlaster/src/c/util
gcc -g -Wall -o msgUtil msgUtil.c helper.c -I.. -DMSG_UTIL_MAIN=1

and now edit the settings in msgUtil.c and play with the different variants:

--------------------
#ifndef _WINDOWS /* Windows does not support the reentrant ..._r() functions */
# if defined(__sun)
# define HAVE_FUNC_GETHOSTBYNAME_R_5 /* SUN */
# elif defined(__alpha)
# define HAVE_FUNC_GETHOSTBYNAME_R_3 /* OSF1 V5.1 1885 alpha */
# elif defined(__FreeBSD__)
# define LOCAL_GETHOSTBYNAME_R /* FreeBSD */
/* this should actually work for other platforms... so long as they support pthreads */
# elif defined(__hpux) /* with gcc 2.8 - 3.4.3 */
# else
# define HAVE_FUNC_GETHOSTBYNAME_R_6 /* Linux */
# endif
#endif
---------------------


... throw away everything and try the different defines directly.
(I know this is the most ugly code ever seen).

Please report which setting works for you and which __xyz??__ is defined
implicitely for MAC OS.


Ricardo Jorge Jota wrote:
Hi,
What was the change you made?
Did the C client compile well without changes (build c), where the problems in C++ only?
The problems is in the #include<malloc.h> (./src/c/util/queue/SQLiteQueue.c:#include <malloc.h>).

Now, in Mac - using Fink - you have two include locations : /sw/lib and /usr/lib. The sw is the Fink one, the usr is the os x system one.
The include malloc.h is in /usr/lib/malloc/malloc.h. In linux the right path is: /usr/lib/malloc.h. In order to solve this I changed the source code, but i'm not sure the best way to do this.
we should add an include directive into build.xml, for now you
could try in build.properties:
 CFLAGS=-I/usr/lib/malloc
or on command line
 build -verbose -DCFLAGS=-I/usr/lib/malloc c-delete c-lib

thanks
Marcel




After this problem was solved the following command (the ./build -verbose cpp showed me the command)
gcc -g -prebind -dynamiclib -o libxmlBlasterClientCD.dylib ../build.tmp/objCD/helper.o ../build.tmp/objCD/XmlBlasterAccessUnparsed.o ../build.tmp/objCD/CallbackServerUnparsed.o ../build.tmp/objCD/XmlBlasterConnectionUnparsed.o ../build.tmp/objCD/msgUtil.o ../build.tmp/objCD/xmlBlasterSocket.o ../build.tmp/objCD/SQLiteQueue.o ../build.tmp/objCD/Properties.o ../build.tmp/objCD/xmlBlasterZlib.old: warning prebinding disabled because of undefined symbols

This is the C shared lib linking output on my Linux box:

gcc -g -shared -o libxmlBlasterClientCD.so ../build.tmp/objCD/helper.o ../build.tmp/objCD/XmlBlasterAccessUnparsed.o ../build.tmp/objCD/CallbackServerUnparsed.o ../build.tmp/objCD/XmlBlasterConnectionUnparsed.o ../build.tmp/objCD/msgUtil.o ../build.tmp/objCD/xmlBlasterSocket.o ../build.tmp/objCD/SQLiteQueue.o ../build.tmp/objCD/Properties.o ../build.tmp/objCD/xmlBlasterZlib.o -L/opt/sqlite-bin/lib -lsqlite -L/opt/zlib-bin/lib -lz

I wonder why cpptasks leaves away the sqlite and zlib in your case (pthread is not needed explicitly on Linux).
I think the problem lies within the -prebind flag. From what I could gather this allows you to remove the gcc -L and -l flags. Although i'm not sure about this it seams that the /sw/lib path -the fink path - isn't prebound (OSX prebind all their dylib.). I'm not sure if you can disable -prebind in the cpp-tasks when the MAC OSX system is found.


Unfortunately _gethostbyname_r doesn't get solved and after "googling" it seems that this symbols doesn't exist in OS X.
This is just the thread safe variant of gethostbyname().
Please add your own gethostbyname_r() variant in your code and implement it using
gethostbyname().



I'd love to implement a new one. But I have some questions about you code. First and foremost i'd like to test the ones already coded. Now if I read you code correctly you use #defines to select the correct one. As the darwin - the osx "kernel"- is mostly bsd maybe the bsd implementation works. But I don't know how to find the correct #define value for osx. Can you shed some light on this ?


Thank in advance,
Ricardo Jota