Hi,<br><br>I'm working on a raster module written in C and I want to use C++ libraries to build a function but I don't know anything about linkers. I tried to use 'extern "C"' to build the function in C++ code and declare it in a header file shared by C (the local_proto.h header) but I have no idea if this could work since I haven't been able to compile. I also tried to modify my makefile in order to compile the C and the C++ files together but I have little experience on building custom makefiles...<br>
I could rewrite the whole code in C++ but that's too much work. Any hint or example code? By the way, the C++ library that I'm trying to use is GAlib, a genetic algorithms library.<br><br>This is how C++ function looks like:<br>
<br><i>extern "C" {<br>#include <grass/gis.h><br>#include <grass/glocale.h><br>#include <stdio.h><br>#include "fann.h"<br>#include "local_proto.h"<br>}<br><br>#include <math.h><br>
<br>#include <ga/GASimpleGA.h><br>#include <ga/GABin2DecGenome.h><br>#include <ga/std_stream.h><br><br>#define cout STD_COUT<br><br><br>extern "C" void genetic(struct input * init, struct layer * vars, struct output * out, char * NNconfig, int totalayers, int rows, int cols, int * fixedcat)<br>
{<br>/*Nothing yet. I have to learn how to compile this*/<br>}<br></i><br>This is my "local_proto.h" file:<br><br><i>#include <grass/gis.h><br>#include <grass/glocale.h><br><br><br>struct input<br>{<br>
const char *name, *mapset;<br> int fd;<br> CELL *buf; /**puntero del tipo double CELL**/<br>};<br><br>struct layer<br>{<br> const char *name, *mapset;<br> int fd;<br> DCELL *buf; /**puntero del tipo double CELL**/<br>
};<br><br>struct output<br>{<br> const char *name, *mapset;<br> int fd;<br> CELL *buf;<br>};<br><br><br>/* tfile.c */<br>void Create_training_file(struct input *, struct layer *, int, int, int, int);<br><br>/* simple.c */<br>
void Simple_training(char *, char *, unsigned int, unsigned int, unsigned int, float, unsigned int *);<br><br>/*interpol.c*/<br>double interpolate(struct layer, int, int, int, int);<br><br>/*run.c*/<br>void run_NN(struct input *, struct layer *, struct output *, char *, int, int, int, int *);<br>
<br>/*genetic_fann.cc*/<br><br>#ifdef __cplusplus<br>extern "C"<br>#endif<br>void genetic(struct input *, struct layer *, struct output *, char *, int, int, int, int *);<br></i><br>And my makefile (pretty much standard):<br>
<i><br>MODULE_TOPDIR = ../..<br><br><br>PGM = r.ailucc<br><br><br>LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) <br>DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)<br><br>include $(MODULE_TOPDIR)/include/Make/Module.make<br>
<br>LDFLAGS+= -lfann <br><br><br>default: cmd<br></i><br><br><br><br><br>