[pgrouting-users] Linking .cpp defined functions
Dave Potts
dave.potts at pinan.co.uk
Fri Jun 29 12:08:46 PDT 2012
Sylvain Housseman wrote:
> Hi,
>
> I am trying to add a function: 1-to-many dijkstra shortest path.
> Thus I downloaded the last git and added a folder named 1toNsp in
> "extra", which contains tomanysp.h, tomanysp.c and
> boost_wrapper_tomany.cpp.
>
> These files are highly inspired from the dijkstra.h, dijkstra.c and
> boost_wrapper.cpp files that are in the "core" directory.
> -actually for now it's mainly a copy/paste of them-
>
> I also created a .sql in extra/1toNsp/sql to define the function
> onetomany_dijkstra_shortest_path(text, int, int array, boolean ,boolean).
> I checked if this function exists by returning the distance between
> source and the first target only, using boost_dijkstra; this works well
> \o/.
>
> Now I want the (static int compute_tomany_shortest_path(char* sql, int
> start_vertex,
> int *end_vertices, int nb_targets,
> bool directed,
> bool has_reverse_cost,
> path_element_t **path, int
> *path_count)) function to call a function defined in
> boost_dijkstra_tomany.cpp (named boost_dijkstra_tomany(...)).
>
> Problem is that when I call
> routing=> SELECT * FROM onetomany_dijkstra_sp('SELECT gid AS id,
> source::int4,
> target::int4, length::double precision AS
> cost,length::double precision
> AS reverse_cost FROM ways', 3, '{7,18,179}', true, true);
> I get
> ERROR: could not load library
> "/usr/lib/postgresql/9.1/lib/librouting_tomanysp.so":
> /usr/lib/postgresql/9.1/lib/librouting_tomanysp.so: undefined symbol:
> boost_dijkstra_tomany
>
> This function (int boost_dijkstra_tomany(......)) is declared in
> tomanysp.h and called from tomanysp.c; while it is defined in
> boost_wrapper_tomany.cpp (which #includes "tomanysp.h"); once again it
> looks the same as what is done with dijkstra.h, dijkstra.c and
> boost_wrapper.cpp.
>
> my /extra/1toNsp/src/CMakeLists.txt is :
> SET(LIBRARY_OUTPUT_PATH ../../../lib/)*
> * ADD_LIBRARY(routing_tomany SHARED boost_wrapper_tomany.cpp
> tomanysp.c tomanysp.h)
> INSTALL(TARGETS routing_tomany DESTINATION ${LIBRARY_INSTALL_PATH})*
>
> *Could someone tell me what I am missing?
How have you declared this function?
In your header file you need to tell the compiler that this function is go
to be declared as c function.
So you need something like
#ifdef __cplusplus
extern "C"
{
#endif
int compute_kshortest_path(char* sql, int start_vertex,
int end_vertex, int no_paths,
bool has_reverse_cost,
ksp_path_element_t **path, int
*ksp_path_count) ;
#ifdef __cplusplus
}
#endif
>
> --------------
> Using postgresql 9.1 with ubuntu 11.10.
> _______________________________________________
> Pgrouting-users mailing list
> Pgrouting-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/pgrouting-users
>
--
More information about the Pgrouting-users
mailing list