简体   繁体   English

C链接器:多个定义

[英]C Linker: Multiple Definitions

I am writing a linked list implementation for a networking project I'm working on. 我正在为我正在从事的网络项目编写链表实现。 It is split into two files: llist.h and llist.c. 它分为两个文件:llist.h和llist.c。 I include llist.h in several of the project files, and when compiling I link to library that I compiled which includes llist.c. 我在几个项目文件中包含llist.h,在编译时,我链接到我编译的包含llist.c的库。 Unfortunately I get a "multiple definitions" error for every method header in llist.h. 不幸的是,对于llist.h中的每个方法标头,我都会收到“多个定义”错误。 ie: 即:

../util//libdutil.a(llist.o): In function `LListContains':
llist.c:(.text+0x0): multiple definition of `LListContains'
../util//libdutil.a(llist.o):llist.c:(.text+0x0): first defined here

I'm not quite sure why I'm getting this error. 我不太确定为什么会收到此错误。 It used to be fine, but this has started happening since I added one more method. 过去很好,但是自从我添加了另一种方法以来,这种情况就开始发生了。 Here is the entire h file: 这是整个h文件:

#ifndef _LLIST_H_
#define _LLIST_H_

typedef struct _LinkedList
{
    int length;
    void* data;
    struct _LinkedList* head;
    struct _LinkedList* tail;
}* LinkedList;

LinkedList LListContains(LinkedList list, void* data, int (*cmp)(const void *, const void *));

void* getDataLList(LinkedList list);

LinkedList createLList(void* data);

void* getFromHeadLList(LinkedList list, int pos);

void* popHeadLList(LinkedList list);

void* popTailLList(LinkedList list);

LinkedList getNextLList(LinkedList current);

LinkedList getPrevLList(LinkedList current);

void addHeadLList(LinkedList list, void* data);

void addTailLList(LinkedList list, void* data);

void FreeLList(LinkedList list);

#endif

Thanks! 谢谢!

UPDATE: Okay, the problem seems to come from the following code snippet in one of the project files: 更新:好的,问题似乎来自项目文件之一中的以下代码片段:

OPP_DIRECTION(getDirToXYPOS((XYPOS*)getFromHeadLList(memories[avID], 0), &curPos)))

Note that getFromHeadLList is the method that I added to llist.h and defined in llist.c. 请注意,getFromHeadLList是我添加到llist.h并在llist.c中定义的方法。 By simply commenting out that part and adding in a dummy parameter, ie: 通过简单地注释掉该部分并添加一个虚拟参数,即:

OPP_DIRECTION(getDirToXYPOS(&curPos, &curPos)))

It compiles fine. 它编译良好。

您很可能已经将llist.c编译到项目以及静态库中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM