我有一个库和一个为它构建的 C 接口。我的程序编译得很好,versionString()
但不能用loadConfig()
. 这怎么可能?
步行者.h:
#ifndef WFE_C_H
#define WFE_C_H
#ifdef __cplusplus
extern "C" {
#endif
const char* versionString();
void* loadConfig(const char *filePath, char* errorMessageBuffer, int bufferLen);
#ifdef __cplusplus
}
#endif
#endif
工作版本:
package main
/*
#cgo CFLAGS: -Isrc/walker
#cgo LDFLAGS: -L${SRCDIR}/lib -lwalker
#include "walker.h"
*/
import (
"C"
)
func main() {
p := C.versionString()
version := C.GoString(p)
fmt.Println(version)
}
// output: v1.94
不工作版本:
package main
/*
#cgo CFLAGS: -Isrc/walker
#cgo LDFLAGS: -L${SRCDIR}/lib -lwalker
#include "walker.h"
*/
import (
"C"
)
func main() {
errorMessageBuffer := C.CString("")
pathPtr := C.CString("/src/vali/config")
bufferLen := C.int(len(4000))
C.loadConfig(pathPtr, errorMessageBuffer, bufferLen)
}
追溯:
/tmp/go-build056292810/github.com/testong/vali/_obj/main.cgo2.o: In
function `_cgo_b2bd1c9e3dda_Cfunc_loadConfig':
/tmp/go-build/github.com/testong/vali/_obj/cgo-gcc-prolog:43: undefined
reference to `loadConfig'
collect2: error: ld returned 1 exit status