[geos-devel] Status (New Example)
Dave Blasby
dblasby at refractions.net
Sun Apr 6 15:57:21 EDT 2003
Quoting Norman Vine <nhv at cape.com>:
>
> Let me try that again I cleaned up to much of
> my debugging 'cruft' from my earlier files
I've tried running your files, but I get the same results as before. (I put
the words "norman" in so I was sure it was using the correct .o files).
I had a though on friday that the c++ wrapper ("test_cpp.cpp") might need more
compile options than "-c"; say something like "-fpic".
Here's what i did (see the bottom for version info):
[dblasby at hydra work_dave]$ rm *.o
[dblasby at hydra work_dave]$ g++ -g test_cpp.cpp -c -I/usr/local/include/geos
[dblasby at hydra work_dave]$ gcc -g -o test test.c test_cpp.o -lm -lgeos -lstdc++
[dblasby at hydra work_dave]$ ./test
geom text (to be parsed norman):POLYGON((100 200,100 140,180 140,180 200,100
200))
geom (WKTWriter):POLYGON ((100.0000000000000000 200.0000000000000000,
100.0000000000000000 140.0000000000000000, 180.0000000000000000
140.0000000000000000, 180.0000000000000000 200.0000000000000000,
100.0000000000000000 200.0000000000000000))
result in C (norman) is
POLYGON ((100.0000000000000000 200.0000000000000000, 100.0000000000000000
140.0000000000000000, inf inf, inf inf, inf inf))
[dblasby at hydra work_dave]$[dblasby at hydra work_dave]$ cat test.c
//c++ -c test_cpp.cpp
//gcc -g -o test test.c test_cpp.o -lm -lgeos -lstdc++
#include "stdio.h"
#include "geos_api.h"
extern GeometryWrapper createGEOSFromText(char *wkt);
extern char * GEOSasText(GeometryWrapper g1);
int main(int argC, char* argV[])
{
GeometryWrapper g =
createGEOSFromText("POLYGON((100 200,100 140,180 140,180 200,100 200))");
printf("\nresult in C (norman) is
%s\n",GEOSasText(g));
}
[dblasby at hydra work_dave]$ cat geos_api.h
#ifdef __cplusplus
# define GEOS_C_START extern "C" {
# define GEOS_C_END }
#else
# define GEOS_C_START
# define GEOS_C_END
#endif
GEOS_C_START;
typedef void *GeometryWrapper;
GeometryWrapper createGEOSFromText(char *wkt);
char * GEOSasText(GeometryWrapper g1);
GEOS_C_END;
[dblasby at hydra work_dave]$ cat test_cpp.cpp
// g++ -g test.cpp -c -I/usr/local/include/geos
#include <string>
#include <iostream>
#include <fstream>
#include "io.h"
#include "geos_api.h"
char *GEOSasText(GeometryWrapper g)
{
Geometry *g1 = (Geometry *)g;
WKTWriter *w=new WKTWriter();
string s = w->write(g1);
char *result = (char *)s.c_str();
return result ;
}
GeometryWrapper createGEOSFromText(char *wkt)
{
cout <<"geom text (to be parsed norman):"<< wkt << endl;
Geometry *g = new Geometry;
WKTReader *r = new WKTReader(new GeometryFactory(new
PrecisionModel(),-1));
g = r->read(wkt);
WKTWriter *w=new WKTWriter();
cout << endl << "geom (WKTWriter):"<< w->write(g) << endl;
delete r;
delete w;
return (GeometryWrapper)g;
}
[dblasby at hydra work_dave]$
[dblasby at hydra work_dave]$ ldd test
libm.so.6 => /lib/libm.so.6 (0x40028000)
libgeos.so.1 => /usr/local/lib/libgeos.so.1 (0x4004a000)
libstdc++-libc6.2-2.so.3 => /usr/lib/libstdc++-libc6.2-2.so.3
(0x40100000)
libc.so.6 => /lib/libc.so.6 (0x4014e000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
[dblasby at hydra work_dave]$ gcc --version
2.96
[dblasby at hydra work_dave]$ g++ --version
2.96
[dblasby at hydra work_dave]$ ln --version
ln (fileutils) 4.1.5
Written by Mike Parker and David MacKenzie.
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
More information about the geos-devel
mailing list