Thread: Placing structs on header file

  1. #1
    Registered User
    Join Date
    Dec 2014
    Location
    Philippines
    Posts
    20

    Post Placing structs on header file

    Hello! I'm trying to put a struct on a header file. Here is the code:

    Code:
    #ifndef _STRUCTS_H_
    #define _STRUCTS_H_
    #define MAX_SIZE 1000
    
    
    typedef struct {
        
        char Name [MAX_SIZE];
        char Gender [2];
        int Age;
        
    } pData;
    
    
    #endif //_STRUCTS_H_
    But whenever I compile the header file itself, I got an error:

    Code:
    C:\Program Files (x86)\Dev-Cpp\MinGW32\lib\libmingw32.a(main.o)    In function `main':91        e:\p\giaw\src\pkg\mingwrt-4.0.3-1-mingw32-src\mingwrt-4.0.3-1-mingw32-src\src\libcrt\crt\main.c    undefined reference to `WinMain@16'
    C:\Users\USER\Desktop\PROG\C\Data Collector\collect2.exe    [Error] ld returned 1 exit status
    What is "undefined reference to `WinMain@16'"?
    And how can I successfully put my structs in a header file?

    Thanks in advance!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,667
    > What is "undefined reference to `WinMain@16'"?
    It means you need to change your project type from "windows gui" to "console".

    > And how can I successfully put my structs in a header file?
    You already have managed that, otherwise the compiler would be complaining about things like not being able to find your header file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User clarasoft's Avatar
    Join Date
    Feb 2015
    Posts
    2
    You are trying to compile and link your code into a Windows executable. The compiler complains that it cannot find your WinMain function, which is the entry point to a Win32 (Windows) program. An executable program needs an entry point (WinMain for Windows apps and main for console applications). Your header file only contains definitions and needs not be compiled on its own. It would typically be included into your executable source (which would normally define the WinMain or main function) and the the preprocessor would copy its content at compilation time to produce a final executable object.

    To fix your problem, create a c source (.c), include your header file and define either main or WinMain (depending on your target executable).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 11-12-2008, 11:00 AM
  2. Replies: 30
    Last Post: 06-19-2006, 12:35 AM
  3. Placing #'s from a file into an array
    By Cornot2C in forum C Programming
    Replies: 5
    Last Post: 03-18-2006, 12:29 AM
  4. Replies: 4
    Last Post: 12-14-2005, 02:21 PM
  5. Replies: 1
    Last Post: 12-14-2002, 01:51 AM