我一直recieving一个collect2:错误:LD返回1退出状态 [英] I keep recieving a collect2: error: ld returned 1 exit status

查看:2249
本文介绍了我一直recieving一个collect2:错误:LD返回1退出状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有点问题。我不断收到collect2:错误:LD返回1退出状态每次我试图编译我的程序的时间。我GOOGLE了这一点,看着例子,看到当一个头文件不正确地使用它通常发生;不过,所以我不知道为什么它是这样做的,我没有使用头文件在我的code。我认为这将是为别人谁得到这个错误,不明白为什么有帮助。我知道有很多我的code错误的,但我试图去那里我可以编译它,并制定出所有的缺陷。多谢!

 的#include<&stdio.h中GT;
#包括LT&;&stdlib.h中GT;结构node_t {
    双X;
    结构node_t *接下来的;
};结构node_t * create_node(双N);
无效print_node(结构node_t *节点);
无效print_list(结构node_t *头);
结构node_t * insert_head(结构node_t *头,结构node_t *节点);
结构node_t * insert_tail(结构node_t *头,结构node_t *节点);
结构node_t * insert_middle(结构node_t *头,结构node_t *节点,INT POS)
诠释count_nodes(结构node_t *头);
结构node_t * delete_node(结构node_t *头,双N);
无效delete_list(结构node_t *头);INT主要(无效)
{    双N;
    INT POS;
/ **询问他们想要做什么用户。 * /    的printf(请选择一个选项:);
    的printf(1输入一个数字);
    的printf(2删除一个数字);
    的printf(3打印所有数字。);
    的printf(4告诉列表中的多少项目);
    输出(5结束程序。);
    的printf(请输入您的选择(1,2,3,4,5):);
    而((TMP =的getchar())!='\\ n')
        在TMP =; / **指示编译器使用把在使用的数目。* /    切换(在){
    案1:{/ **如果用户选择输入号码,通过这个过程。 * /
        的printf(1在列表头输入项目);
        的printf(2列表的中间输入项目);
        的printf(3在列表的尾部输入项目);
        的printf(请输入您的选择(1,2,3):);
        而((TMP =的getchar())!='\\ n')
            在TMP =;        切换(在){
        情况1':{
            的printf(请输入数字是在头进:);            与fgets(S,1024,标准输入);            结构node_t * create_node(双N);
            结构node_t * insert_head(结构node_t *头,结构node_t *节点);            打破;
            }        案2:{
            的printf(输入号码将在中输入:);            与fgets(S,1024,标准输入);            结构node_t * create_node(双N);
            结构node_t * insert_middle(结构node_t *头,结构node_t *节点,INT POS)
            打破;
            }        案3:{
            的printf(请输入数字是在进入尾:);            与fgets(S,1024,标准输入);            结构node_t * create_node(双N);
            结构node_t * insert_tail(结构node_t *尾,结构node_t *节点);            打破;
            }
        打破;
            }
        }    案2:{/ **如果选择的用户删除某个号码,通过这个过程。 * /        的printf(输入需要被删除的节点:);        与fgets(S,1024,标准输入);        结构node_t * delete_node(结构node_t *头,双N);        打破;        }    案3:{/ **如果用户选择打印所有号码,通过这个过程。 * /        //无效print_list(结构node_t *头)        打破;        }    案4:{/ **如果选择的用户告诉多少项目在列表中,经历这个过程。 * /
        诠释count_nodes(结构node_t *头);        打破;
        }    案5:{/ **如果用户选择结束程序,通过这个程序。 * /        返回1;        打破;
        }    }    返回0;}/ **创建一个新的节点
 * @参数双N,n个
 * @返回指针
 * /结构node_t * create_node(双N)
{
    结构node_t * P =的malloc(大小(结构node_t))
    对 - > X = N;
    对 - >接下来= NULL; / *初始化指针NULL * /
    回磷;
}
/ **打印节点
 * @参数结构node_t *节点
 * /
//无效print_node(结构node_t *节点)
// {
//打印出节点和节点的地址
//打印(*节点和放大器;节点)
//}
/ **打印清单
 * @参数结构node_t *头
 * /
//无效print_list(结构node_t *头)
// {
//列表的打印内容。无论是双打和地址。
//而(指针指向的东西,保持在列表中去。)
//打印(在列表中的节点,节点的地址)
//}
/ **在头部插入一个节点
 * @参数结构node_t *头,这里头的结构。
 * @参数结构node_t *节点,该结构,其中节点。
 * @返回头。
 * /
结构node_t * insert_head(结构node_t *头,结构node_t *节点)
{
     - 于节点GT;接下来=头;
    头=节点;
    返回头;
}
/ **插入在尾部的一个节点。
 * @参数结构node_t *尾,结构,其中尾巴。
 * @参数结构node_t *节点,该结构,其中节点。
 * @返回头。
 * /
结构node_t * insert_tail(结构node_t *尾,结构node_t *节点)
{    结构node_t * P =头;
    如果(头== NULL)
        头=节点;
        返回头;
    而(对GT;!下次= NULL)
        P = P->下一个;
        P->接下来=节点;
        返回头;
}
/ **插入在中部的一个节点。
 * @参数结构node_t *头,这里头的结构。
 * @参数结构node_t *节点,该结构,其中节点。
 * @参数INT POS,当前节点的位置。
 * @返回头。
 * /
结构node_t * insert_middle(结构node_t *头,结构node_t *节点,INT POS)
{    INT POS = 1;
    结构node_t * P =头;
    *头= POS机,POS = 1;
    如果(POS> SIZE)
        P->接下来=节点;
    否则,如果(POS&L​​T; 1)
        的printf(错误\\ n);
    返回头;
}
/ **计数节点的数目
 * @参数结构node_t *头,这里头的结构。
 * @返回计数。
 * /
诠释count_nodes(结构node_t *头);
{    结构node_t * P =头;
    而(对GT;!下次= NULL)
        返回计数;
    如果(头== NULL)
        计数= 0;
    返回计数;
}/ **删除节点
 * @参数结构node_t *头,这里头的结构。
 * @参数双N,n个。
 * @返回头。
 * /
结构node_t * delete_node(结构node_t *头,双N);
{    如果(节点==头)
        无头;
        P->接下来=头; //头部现在指向那是被删除的节点后,下一个指针    否则,如果(节点==中)
        免费节点;
        P = P->节点之前下一//指针现在已被删除指向被删除节点之后的节点    否则,如果(节点==尾)
        自由p值=对 - >接着=节点; //自由保存数据的最后一个节点。之前它指向空节点
        对 - >接着= NULL;    其他的printf(错误。\\ n)
    返回头;
}
/ **删除列表
 * @参数结构node_t *头,这里头的结构。
 * @返回头。
 * /
无效delete_list(结构node_t *头);
{
    而((对GT;!下次= NULL)
        无头; //这将失去头后,所有的记忆。
        头== NULL;
    如果(头== NULL)
        返回0;
    返回0;
}


解决方案

当链接失败时为。

可能是你有你的文件的顶部和下方的实现向前声明的签名之间的不匹配。链接器无法找到的功能之一。

I am having a bit of a problem. I keep receiving a "collect2: error: ld returned 1 exit status" every time I try to compile my program. I googled this, looked at examples, and saw that it usually occurs when a header file is not used correctly; however, I did not use header files in my code so I am not sure why it is doing this. I think this would be helpful for others who get this error and don't understand why. I do know that there are a lot of errors in my code, but I am trying to get to where I can compile it and work out all the kinks. Thanks a bunch!!

#include <stdio.h>
#include <stdlib.h>

struct node_t {
    double x;
    struct node_t *next;
};

struct node_t *create_node(double n);
void print_node (struct node_t * node ); 
void print_list (struct node_t * head );
struct node_t * insert_head (struct node_t *head , struct node_t * node );
struct node_t * insert_tail (struct node_t *head , struct node_t * node );
struct node_t * insert_middle (struct node_t *head , struct node_t *node , int pos );
int count_nodes (struct node_t * head );
struct node_t * delete_node (struct node_t *head , double n);
void delete_list (struct node_t * head ); 

int main (void) 
{

    double n;
    int pos;


/** Asks the user what they would like to do. */

    printf("Please select an option: ");
    printf("1. Enter a number ");
    printf("2. Delete a number ");
    printf("3. Print all numbers ");
    printf("4. Tell how many items in the list ");
    printf("5. End program ");
    printf("Please enter your choice (1, 2, 3, 4, 5): ");
    while ((tmp = getchar()) != '\n')
        in = tmp; /** Tells the compiler to use the number that the use put in. */

    switch (in){
    case '1': {/** If the user chooses Enter a Number, go through this process. */
        printf("1. Enter item at head of list ");
        printf("2. Enter item in middle of list ");
        printf("3. Enter item at tail of list ");
        printf("Please enter your choice (1,2,3): ");
        while ((tmp = getchar()) != '\n')
            in = tmp;

        switch (in) {
        case '1':{
            printf("Enter the number to be entered at head: ");

            fgets(s, 1024, stdin);

            struct node_t * create_node (double n);
            struct node_t *insert_head(struct node_t *head, struct node_t *node);

            break;
            }

        case '2':{
            printf("Enter the number to be entered in middle: ");

            fgets(s, 1024, stdin);

            struct node_t * create_node (double n);
            struct node_t * insert_middle (struct node_t *head , struct node_t *node , int pos);
            break;
            }

        case '3':{
            printf("Enter the number to be entered at tail: ");

            fgets(s, 1024, stdin);

            struct node_t * create_node (double n);
            struct node_t *insert_tail(struct node_t *tail, struct node_t *node);

            break;
            }
        break;
            }
        }   

    case '2':{/** If the user selected Delete a Number, go through this process. */ 

        printf("Enter the node that needs to be deleted: ");

        fgets(s, 1024, stdin);

        struct node_t * delete_node (struct node_t *head , double n);

        break;

        }   

    case '3':{/** If the user selected Print All Numbers, go through this process. */

        //void print_list (struct node_t *head)

        break;

        }

    case '4':{ /** If the user selected Tell How Many Items in the List, go through this process. */
        int count_nodes (struct node_t * head );        

        break;
        }

    case '5':{ /** If the user selected End Program, go through this process. */

        return 1;       

        break;
        }

    }       

    return 0;

}







/** Creates a new node
 *  @param double n, a number n
 *  @return pointer
 */

struct node_t * create_node (double n)
{


    struct node_t *p = malloc (size of (struct node_t))
    p -> x = n;
    p -> next = NULL; /*initializes pointer to null*/
    return p;
}


/** Prints the nodes
 *  @param struct node_t *node
 */
//void print_node (struct node_t *node )
//{
//  prints out the node and the address of the node
//  print(*node, &node)
//}


/** Prints list
 *  @param struct node_t *head
 */
//void print_list (struct node_t *head)
//{
//  print contents of list. both the doubles and the address.
//  while (pointer is pointing to something, keep going through the list. )
//  print(nodes in list, address of nodes )
//}


/** Inserts a node at the head
 *  @param struct node_t *head, the structure where head is. 
 *  @param struct node_t *node, the structure where node is.
 *  @return head.
 */
struct node_t *insert_head(struct node_t *head, struct node_t *node)
{
    node-> next = head;
    head = node;
    return head;
}


/** Inserts a node at the tail.
 *  @param struct node_t *tail, the structure where tail is. 
 *  @param struct node_t *node, the structure where node is.
 *  @return head.
 */
struct node_t *insert_tail(struct node_t *tail, struct node_t *node)
{

    struct node_t *p = head;
    if (head == NULL)
        head = node;
        return head;
    while (p->next ! = NULL)
        p = p-> next;
        p-> next = node;
        return head;
}


/** Inserts a node at the middle.
 *  @param struct node_t *head, the structure where head is. 
 *  @param struct node_t *node, the structure where node is.
 *  @param int pos, the position of the current node.
 *  @return head.
 */
struct node_t * insert_middle (struct node_t *head , struct node_t *node , int pos);
{

    int pos = 1;
    struct node_t *p = head;
    *head = pos, pos = 1;
    if (pos > SIZE )
        p-> next = node;
    else if (pos < 1)
        printf("Error\n");
    return head;
}


/** Counts the number of nodes
 *  @param struct node_t *head, the structure where head is. 
 *  @return count.
 */
int count_nodes (struct node_t * head );
{

    struct node_t *p = head;
    while(p->next ! = NULL)
        return count;
    if (head == NULL)
        count = 0;
    return count;
}   

/** Deletes nodes
 *  @param struct node_t *head, the structure where head is. 
 *  @param double n, a number n.
 *  @return head.
 */ 
struct node_t * delete_node (struct node_t *head , double n);
{

    if (node == head)
        free head;
        p->next = head; //head now points to the pointer that was next after the node that was deleted

    else if (node == middle)
        free node;
        p = p->next //pointer before node that was deleted now points to node that was after deleted node

    else if (node == tail)
        free p = p->next = node; //free the last node that holds data. The node before it now points to NULL
        p->next = NULL;

    else printf("Error\n")
    return head;
}


/** Deletes list
 *  @param struct node_t *head, the structure where head is. 
 *  @return head.
 */ 
void delete_list (struct node_t * head ); 
{
    while((p->next ! = NULL)
        free head; //This will lose all memory after head.
        head == NULL;
    if (head == NULL) 
        return 0;
    return 0;
}

解决方案

That is when the linker fails.

Likely you have a mismatch between the signature of the forward declarations at the top of your file and the implementations below. The linker cannot find one of the functions.

这篇关于我一直recieving一个collect2:错误:LD返回1退出状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆