gpt4 book ai didi

go - cgo undefined reference

转载 作者:行者123 更新时间:2023-12-01 22:26:46 26 4
gpt4 key购买 nike

去项目结构

src
test.go
testc/collection/linkedlist.h
testc/collection/linkedlist.c

test.go
package main

// #cgo CFLAGS: -g -Wall
// #include <stdlib.h>
// #include "testc/collection/linkedlist.h"
import "C"

func main() {
C.insertFirst(1,10);
C.insertFirst(2,20);
C.insertFirst(3,30);
C.insertFirst(4,1);
C.insertFirst(5,40);
C.insertFirst(6,56);
C.printList();
}

链表
#include <stdbool.h>

#ifndef TEST_LINKEDLIST_H
#define TEST_LINKEDLIST_H
struct node {
int data;
int key;
struct node *next;
};

struct node * getHeader();
void printList();
void insertFirst(int key, int data);
struct node* deleteFirst();
bool isEmpty();
int length();
struct node* find(int key);
struct node* delete(int key);
void sort();
void reverse(struct node** head_ref);
//void testList();
#endif //TEST_LINKEDLIST_H

错误
# command-line-arguments
d:/gcc-9.2.0-no-debug/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: $WORK\b001\_x002.o: in function `_cgo_8b2a34aa27ef_Cfunc_insertFirst':
/tmp/go-build/cgo-gcc-prolog:62: undefined reference to `insertFirst'
d:/gcc-9.2.0-no-debug/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: $WORK\b001\_x002.o: in function `_cgo_8b2a34aa27ef_Cfunc_printList':
/tmp/go-build/cgo-gcc-prolog:74: undefined reference to `printList'
collect2.exe: error: ld returned 1 exit status
# command-line-arguments
cgo-gcc-prolog: In function '_cgo_8b2a34aa27ef_Cfunc_printList':
cgo-gcc-prolog:72:49: warning: unused variable '_cgo_a' [-Wunused-variable]

最佳答案

您必须省略testc文件夹,因为它们在导入中位于相同路径中。
所以这个导入:

// #include "testc/collection/linkedlist.h"

将会:

// #include "collection/linkedlist.h"

关于go - cgo undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59507513/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com