Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 嵌入C++;go程序中的可执行函数_C++_Go - Fatal编程技术网

C++ 嵌入C++;go程序中的可执行函数

C++ 嵌入C++;go程序中的可执行函数,c++,go,C++,Go,我的目标是将编译后的可执行文件中的函数包含到go程序中 我的目录结构设置如下: ProjectDir/ include/ <header files> main.go libMyLibrary.dylib otherMain.cpp otherMain.hpp 但是,当我尝试运行go build main.go时,链接器出现以下错误: # command-line-arguments Undefined symbols for

我的目标是将编译后的可执行文件中的函数包含到go程序中

我的目录结构设置如下:

ProjectDir/
    include/
        <header files>
    main.go
    libMyLibrary.dylib
    otherMain.cpp
    otherMain.hpp
但是,当我尝试运行
go build main.go
时,链接器出现以下错误:

# command-line-arguments
Undefined symbols for architecture x86_64:
  "_myFunction", referenced from:
      __cgo_159d40466606_Cfunc_myFunction in main.cgo2.o
     (maybe you meant: __cgo_159d40466606_Cfunc_myFunction)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我一直对此感到困惑,不明白为什么链接器找不到库。有什么想法吗

otherMain.hpp:

#include <stdio.h>
#include <string.h>
#include <memory.h>

#include <Carbon/Carbon.h>

#define MAX_NUM_MEASUREMENTS 100

#include "<a header file in include>.h"

int main(int argc, char* argv[]);
gtype_real64 myFunction();
#包括
#包括
#包括
#包括
#定义最大测量值100
#包括“.h”
intmain(intargc,char*argv[]);
gtype_real64 myFunction();

我在这里没有看到任何关于
myFunction()
@RobertHarvey的代码。myFunction的实现是否重要?它包含在
otherMain.cpp
中,您不妨向我们展示所有相关的运动部件。否则,我们该如何诊断呢?如果
othermain.hpp
的代码不太大,请将其包含在问题中。
libMyLibrary.dylib
由g++编写?我不认为GO可以用C++包裹的函数来工作,至少我不能做到。@ BuZZ是用G++编译的…不过,我觉得CGO会同时使用C和C++。
#include <stdio.h>
#include <string.h>
#include <memory.h>

#include <Carbon/Carbon.h>

#define MAX_NUM_MEASUREMENTS 100

#include "<a header file in include>.h"

int main(int argc, char* argv[]);
gtype_real64 myFunction();