Linking a 3rd party library

Hello everyone,

I am trying to link a 3rd party library in FreeFem++ called cwipi, the library in coded in C++. I changed the pref file to link the .so and the .h files but it did not work (I can load the library but I can’t use any function). I was wondering if I should transform the c++ functions then compile with ff-c++, but that’s a tedious task… Is there any way to directly link 3rd party libraries?

I was wondering if I should transform the c++ functions then compile with ff-c++

That is exactly what you need to do. FreeFEM can’t guess what functions you need from the library, so you need to interface them yourself. There are many examples in plugin/seq/ and plugin/mpi/.

Thank you for your reply, I will check them out.

I tried an example that worked, the function is called LinkTest in this file:
linktocwipi.log (764 Bytes)

However when I try to convert a function using the same method I get the following errors:

invalid conversion from ‘void ()(const char, int)’ to 'OneOperator2_<void, const char, int>*
invalid use of void expression {return SetAny( f( GetAny((*a0)(s)) , GetAny((*a1)(s)) ) );}

Do you have any idea on how to fix it? I am passing the correct arguments for the function. Thank you in advance.

There are a couple of issues:

  • cannot return void, return a long instead (return 0L;)
  • cannot use int, need long instead
  • cannot use const char *, need std::string* (look at plugin/seq/addNewType.cpp)

I see, I tried correcting with the above modifications: linktocwipi.log (815 Bytes)

I’m still getting the following error: invalid conversion from ‘long int ()(std::__cxx11::string, long int)’ {aka ‘long int (*)(std::_ _cxx11::basic_string*, long int)’} to ‘OneOperator2_<long int, std::__cxx11::basic_string*, long int>::func’ {aka ‘l ong int ()(std::__cxx11::basic_string const&, const long int&)’} [-fpermissive]

Is it also related to the string declaration?

Please look at some more examples and see what your compiler is telling you. You cannot use values, but need to pass const references instead, see, e.g., plugin/seq/BinaryIO.cpp:Global.Add("LoadFlag", "(", new OneOperator2_< double, long int *, string * >(LoadFlag));