baseroglu
baseroglu

Reputation: 11

undefined reference to WinMain c programming language in vscode

Altough I save my project, I get these errors

When I run parametric_stack_arr.c I got this error

D:/Qt/Tools/mingw810_64/bin/../lib/gcc/x86_64- 
w64-mingw32/8.1.0/../../../../x86_64-w64- mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a 
-crt0_c.o):crt0_c.c:(.text.startup+0x2e): 
undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status

When I run main.c I got this error

C:\Users\xxx\AppData\Local\Temp\ccq0uYEM.o:main.c:(.text+0x6b): undefined reference to `push'
C:\Users\xxx\AppData\Local\Temp\ccq0uYEM.o:main.c:(.text+0x81): undefined reference to `print'
C:\Users\xxx\AppData\Local\Temp\ccq0uYEM.o:main.c:(.text+0x96): undefined reference to `pop'
C:\Users\xxx\AppData\Local\Temp\ccq0uYEM.o:main.c:(.text+0xa4): undefined reference to `push'
C:\Users\xxx\AppData\Local\Temp\ccq0uYEM.o:main.c:(.text+0xba): undefined reference to `print'
collect2.exe: error: ld returned 1 exit status

This is my code

I import parametric_stack_arr.h to main.c

main.c:

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

int main(int argc, char *argv[])
{

    printf("hello");
    stack s1;
    stack s2;  
    s1.size = 2;
    s1.arr = NULL;
    s1.top =0;

    s2.size = 2;
    s2.arr = NULL;
    s2.top =0;
    
    int i;
    for(i=1; i<=5; i++)
    {   
        push(i*10, &s1);
    }

    print(&s1);

    int j;
    for(j=1; j<=10; j++)
    {   
        push(pop(&s1), &s2);
    }
   
    print(&s2);


    return 0;
}

I import parametric_stack_arr.h to parametric_stack_arr.c

parametric_stack_arr.c:

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




int pop(stack *s)
{
    if(s->arr = NULL){
        printf("error");
        return -1;
    }

    if(s->top <= s->size/4)
    {
        int *arr2 = (int *)malloc(sizeof(int)*(s->size)/2);
        int j;
        for(j =0; j<(s->size); j++)
        {
            arr2[j]=s->arr[j];
        }
        free(s->arr);
        s->arr = arr2;
        s->size /= 2;
    }
    return s->arr[--s->top];
}

void push(int x, stack *s)
{
    if(s->arr = NULL)
    {
        s->arr = (int*) malloc(sizeof(int)*2);
    }
    if(s->top >= s->size)
    {
        int *arr2 = (int *)malloc(sizeof(int)*(s->size)*2);
        int j;
        for(j =0; j<s->size; j++)
        {
            arr2[j]=s->arr[j];
        }
        free(s->arr);
        s->arr = arr2;
        s->size *= 2;
    }
    s->arr[s->top++] = x;
}

void print(stack *s)
{
    printf("\nsize : %d\n", s->size);
    int i;
    for(i=0; i<s->top;i++)
    {
        printf("%d ", s->arr[i]);
    }
}

I add my function prototypes to parametric_stack_arr.h

#ifndef __PARAMETRIC_STACK_ARR_H
#define __PARAMETRIC_STACK_ARR_H

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



typedef struct
{
    int size;
    int top;
    int *arr;

}stack;

int pop(stack *s);
void push(int x, stack *s);
void print(stack *s);

#endif

Upvotes: 0

Views: 487

Answers (0)

Related Questions