[pgrouting-users] Linking .cpp defined functions

Sylvain Housseman hsylvio at gmail.com
Mon Jul 2 03:06:49 PDT 2012


Dear Dave,

thank you for your answer, I think you were right pointing the C vs C++ 
fuinctions.
I actually made my function work by putting within a class initialized 
through an interface function... Maybe the

#ifdef __cplusplus
extern "C"
{
#endif

would have been enough!


All this is not really clear to me yet but I will make a few tests and 
upload the sources of a "clean" 1_to_many dijkstra by the end of the week.

Thanks again;
Sylvain.

Le 29/06/2012 21:08, Dave Potts a écrit :
> 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