2,190
社区成员
发帖
与我相关
我的任务
分享
#ifndef ALGORITHM_DLL_H
#define ALGORITHM_DLL_H
#ifdef __cplusplus
extern "C" {
#endif
__declspec(dllexport) int add(int a, int b);
__declspec(dllexport) int sub(int a, int b);
#ifdef __cplusplus
}
#endif
#include "Algorithm.h"
int add(int a, int b)
{
return a + b;
}
int sub(int a, int b)
{
return a - b;
}
// main.go
package main
/*
#cgo CFLAGS: -Iinclude
#cgo LDFLAGS: -Llib -lAlgorithm
#include "Algorithm.h"
*/
import "C"
import (
"fmt"
)
func main() {
fmt.Println("Hello World!")
ret := int32(C.add(2, 3))
fmt.Println(ret)
}