Compilation error related to WinMain

Asked 2 years ago, Updated 2 years ago, 59 views

Compiling the code below with the visual studio code results in an error.

//////////// LinkedList.h ////////////
#pragma once

typedef struct LINKEDLIST {
    Node* head;
    Node* cur;
    Node* before;
    int numOfData;
    int(*comp)(LData d1, LData d2);
}LinkedList;

typedef LinkedList List;
void ListInit(List* plist);


//////////// //////////// LinkedList.c ////////////
#include <stdio.h>
#include "LinkedList.h"

void ListInit(List* plist) {
    plist->head = (Node*)malloc(sizeof(Node));
    plist->head->next = NULL;
    plist->comp = NULL;
    plist->numOfData = 0;
}


//////////// //////////// main.c /////////////
#include <stdio.h>
#include "LinkedList.h"

int main() {
    List list;
    ListInit(&list);
    return 0;
}

This compilation results in an error message undefined reference to 'ListInit'.

If you compile the LinkedList.c file separately, the following error appears:

c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status

It is said to be an error caused by building with a Windows application, not a console, so how do I solve this? The compilation environment is Visual Studio Code + GCC 6.3.

c c++ visual-studio-code

2022-09-21 14:18

1 Answers

The cause is WinMain, not main, for Windows programs (GUI).

Error caused by linker not finding WinMain.

I think you can change the visual studio code by looking for an option. If you are in a hurry to build, open the cmd window and go to the source storage directory and use the command below.

gcc -o main *.c 

But looking at the source, there is no structure node declaration and no LData type.


2022-09-21 14:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.