c++geoslibgeos

warning "The GEOS C++ API is unstable, please use the C API instead"


I am trying to develop a small .cpp example in ubuntu using GEOS. To this end I am trying to build a first example, e.g. https://github.com/vmx/geos/blob/master/doc/example.cpp

I installed both libgeos++dev and libgeos-dev using synaptics. This way it finds the .h files and compiles.

However when linking (-lgeos), I get:

warning "The GEOS C++ API is unstable, please use the C API instead"

It seems to me it tries to use the c++ library... Any way to force him to use the correct one and avoid the warning?

Edit:

As noted, this warning is produced when compiling my c++ file, because I have libgeos++dev and specified -lgeos at linking. If I remove libgeos++dev and leave libgeos-dev, from the readme, the library asks for e.g. To compile programs against GEOS:

    CFLAGS += -I`geos-config --includes`
    LDFLAGS += `geos-config --libs`

Headers: #include <geos.h>

This basically means:

CFLAGS += -I/usr/include
LDFLAGS += -L/usr/lib/x86_64-linux-gnu -lgeos-3.8.0

But when I try to compile using e.g.

g++ -c -I/usr/include  -o "bfc.o" "bfc.cpp" 

I get:

bfc.cpp:22:10: fatal error: geos.h: No such file or directory
   22 | #include <geos.h>
      |          ^~~~~~~~

(bfc.cpp does #include <geos.h>)


Solution

  • Turns out the flag to include the C version of GEOS is -lgeos_c ...

    -lgeos always tries to include the C++ version (whether it is installed or not)