On Oct 9, 2013 1:01 PM, <mobiled...@gmail.com> wrote:
>
> For a year I used this solution to be able to use a c++ library
> in my project. I had to use gccgo as only then available solution
> for this case.
if your c++ library can expose a c interface, go 1.2's cgo will do.
alternatively, swig is also supported and it can wrap native c++ interface.
> gccgo + c++ library as a Golang package
> https://groups.google.com/forum/#!searchin/golang-nuts/service/golang-nuts/0PtkEbR-Y7k/yjshat2uJ7IJ
>
> Because gccgo is way behind ver. 1.2 I am wondering it is possible
> to do the same now without gccgo?
>
>
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
... however a C wrapper is a possibility. For example:
interface.cpp:
================================================================
#include "GeographicLib/Geodesic.hpp"
extern "C"
void GeodInverse(double lat1, double lon1, double lat2, double lon2,
double *s12, double *azi1, double *azi2) {
GeographicLib::Geodesic::WGS84.Inverse(lat1, lon1, lat2, lon2,
*s12, *azi1, *azi2);
return;
}
================================================================
main.c
================================================================
#include <stdio.h>
void GeodInverse(double lat1, double lon1, double lat2, double lon2,
double *s12, double *azi1, double *azi2);
int main() {
double lat1, lon1, lat2, lon2;
double s12, azi1, azi2;
scanf("%lf %lf %lf %lf\n", &lat1, &lon1, &lat2, &lon2);
GeodInverse(lat1, lon1, lat2, lon2, &s12, &azi1, &azi2);
printf("%.8f %.8f %.3f\n", azi1, azi2, s12);
}
================================================================
Makefile
================================================================
test: main.o interface.o
g++ -o $@ $^ -lGeographic -Wl,--rpath -Wl,/usr/local/lib
main.o: main.c
gcc -c $^
interface.o: interface.cpp
g++ -c $^
================================================================
make test
echo 1 2 3 4 | ./test
45.14416881 45.21398561 313705.445
svn checkout svn://gcc.gnu.org/svn/gcc/branches/gccgo gccgo