gpt4 book ai didi

C 无法编译 - 找不到体系结构 x86_64 的符号

转载 作者:太空狗 更新时间:2023-10-29 16:37:40 26 4
gpt4 key购买 nike

我的 C 代码有一个严重的问题,我似乎无法编译它,我真的不明白为什么。

我试过在线研究,找不到解决问题的办法,你有什么想法吗?

感谢您的宝贵时间!

Undefined symbols for architecture x86_64:
"_Insert", referenced from:
_InsertNode in part1.o
(maybe you meant: _InsertNode)
"_Create", referenced from:
_findShortestPaths in part1.o
"_DeleteMin", referenced from:
_findShortestPaths in part1.o
"_decreaseKey", referenced from:
_findShortestPaths in part1.o
"_GetMin", referenced from:
_findShortestPaths in part1.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [part1] Error 1

part1.c 的片段

#include "limits.h"
#include "pegBinaryHeap.h"

void InsertNode(int distance, Node* node, PriorityQueue PQ) {
...
Insert(*item, PQ);
}

...

int* findShortestPaths(Graph *graph, int start) {
...

//Priority queue ordered by distance
PriorityQueue pq = Create(graph->MaxSize);
for(int i = 0; i < graph->MaxSize; i++) {
...
}

//While the queue isn't empty:
while((currentPqItem=GetMin(pq)) != NULL) {
...
DeleteMin(pq);

//for each node accesable from currentNode
List *currentNeighbour = currentNode.outlist;

while(currentNeighbour!=NULL) {
...
decreaseKey(currentNode.id, newDistance, pq);
} // end for
}// end while
}

int main(int argc,char *argv[])
{
Graph mygraph;
return 0;
}

还有它似乎在提示的 .h 文件

#include "graph.h"

struct HeapStruct;
typedef struct HeapStruct *PriorityQueue;

typedef struct {
int distance;
Node *node;
} QueueType;

PriorityQueue Create( int MaxSize );
void Destroy( PriorityQueue H );
int Insert( QueueType Item, PriorityQueue H );
QueueType DeleteMin( PriorityQueue H );
QueueType* GetMin( PriorityQueue H );
void decreaseKey(int nodeId, int value, PriorityQueue H);

最佳答案

您可以编译,但不能链接

part1.o 正在使用您在上一个 .h 文件中定义的函数,但找不到实现。链接程序时,需要确保链接的目标文件(或库)包含这些函数的实现。您可能做过类似的事情:

gcc part1.c -o myapp

因此链接器并没有拼图的所有部分。

如果你想分段编译,你需要:

gcc -c part1.c -o part1.o
gcc -c implementations.c -o implementations.o
gcc implementations.o part1.o -o myapp

这里,所有的.c文件分别编译成目标文件(.o),然后一起链接成一个可执行文件。或者您可以一次完成所有操作:

gcc part1.c implementations.c -o myapp

如果实现在库中(libimplementations.a):

gcc part1.c -Lpath/to/libs -limplementations -o myapp

关于C 无法编译 - 找不到体系结构 x86_64 的符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10143784/

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