Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure out how to link CGo compiled C with CMake compiled C++ #99

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions slam_service_go/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

/*
#cgo LDFLAGS: -v -L../viam-cartographer/build -lviam-cartographer -lstdc++ -lpthread
#include "../viam-cartographer/src/c-api/slam_service_c.h"
*/
import "C"
import "fmt"

func main() {
fmt.Println(C.TestCgoC(1))
fmt.Println(C.TestCgoC(5))

fmt.Println(C.TestCgoC(100))
fmt.Println(C.TestCgoC(101))
fmt.Println(C.TestCgoC(199))
fmt.Println(C.TestCgoC(998))
}
6 changes: 6 additions & 0 deletions viam-cartographer/src/c-api/slam_service_c.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "slam_service_c.h"
#include "../slam_service/slam_service.h"

int TestCgoC(int num) {
return static_cast<int>(viam::SensorId::SensorType::IMU) + num;
}
14 changes: 14 additions & 0 deletions viam-cartographer/src/c-api/slam_service_c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef SLAM_SERVICE_C_H
#define SLAM_SERVICE_C_H

#ifdef __cplusplus
extern "C" {
#endif

int TestCgoC(int num);

#ifdef __cplusplus
}
#endif

#endif /*SLAM_SERVICE_C_H*/
2 changes: 1 addition & 1 deletion viam-cartographer/src/io/draw_trajectories.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#ifndef VIAM_CARTOGRAPHER_IO_DRAW_TRAJECTORIES_H_
#define VIAM_CARTOGRAPHER_IO_DRAW_TRAJECTORIES_H_

#include "../src/io/color.h"
#include "color.h"
#include "cairo/cairo.h"
#include "cartographer/io/color.h"
#include "cartographer/io/image.h"
Expand Down
Loading