Having a serious problem with my C code, I just don’t seem to be able to get it to compile and I really can’t figure out why.
I have tried researching online and can’t find a solution to the problem, do you have any idea?
Thanks for your time!
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
Snippits from 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;
}
And the .h file that it appears to be complaining about
#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);
You can compile, but you cannot link.
part1.ois using the functions you defined in your last.hfile and the implementations cannot be found. When you link your program, you need to make sure you’re linking in the object file(s) (or libraries) that contain the implementations of those functions. You’ve likely done something like:gcc part1.c -o myappand so the linker doesn’t have all the pieces to the puzzle.
If you want to compile in parts, you need to:
Here, all the
.cfiles are compiled into object (.o) files separately, and then linked together into an executable. Or you could do everything at once:If the implementations are in a library (
libimplementations.a):