C
C
Chemodan2282020-02-14 21:25:32
C++ / C#
Chemodan228, 2020-02-14 21:25:32

The user library does not work correctly. What should I do?

library.h:

#ifndef INC_2SEM_LIBRARY_H
#define INC_2SEM_LIBRARY_H
#include <stdio.h>
#include <malloc.h>
typedef struct
{
    int quantity;
    int *val;
} stack;
void push(stack *s, int x);
int pop(stack *s);
#endif //INC_2SEM_LIBRARY_H

library.c:
#include "library.h"
void push(stack *s, int x)
{
    if (!s->quantity){
        s->val=realloc(s->val,1);
        s->val[s->quantity++] = x;
    }
    else {
        s->val[s->quantity++] = x;
        s->val = realloc(s->val, s->quantity);
    }
}
int pop(stack *s)
{    if (!s->quantity)
        return s->val[--s->quantity];
}

main.c:
#include <stdio.h>
#include "library.h"
int main() {
    stack q;
    push(&q,12);
    //printf("%i",pop(&q));
    return 0;
}

errors:

CMakeFiles/2sem_main.dir/main.c.o: In function `main':
/home/ivan/CLionProjects/2sem_main/main.c:5: undefined reference to `push'
collect2: error: ld returned 1 exit status
CMakeFiles/2sem_main.dir/build.make:83: recipe for target '2sem_main' failed
make[3]: *** [2sem_main] Error 1
CMakeFiles/Makefile2:75: recipe for target 'CMakeFiles/2sem_main.dir/all' failed
make[2]: *** [CMakeFiles/2sem_main.dir/all] Error 2
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/2sem_main.dir/rule' failed
make[1]: *** [CMakeFiles/2sem_main.dir/rule] Error 2
Makefile:118: recipe for target '2sem_main' failed
make: *** [2sem_main] Error 2

Errors are similar because I brought the files into a new project.
The user library does not work correctly. Errors pop up. Tell me what to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2020-02-14
@TopToster

main.c:5: undefined reference to `push'

It looks like the library is not being linked. Is there a project build command line?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question