ld: Undefined symbols:_main

Discussion in 'Mac Programming' started by rain, Oct 23, 2004.

  1. macrumors newbie

    Joined:
    Oct 17, 2004
    #1
    Hi,

    I am a beginner with Mac Programming.
    I was trying to write a serial port library for MAC OS X, but when I try to compile the following code, I was getting the following error;
    ld: Undefined symbols:_main

    Does anyone know what is causing the problem?
    Please let me know if you find any other issues!
    Thanks in advance!


    #include <sys/stat.h>
    #include <string.h>
    #include <sys/file.h>

    #include <stdio.h>
    #include <fcntl.h>
    #include <sys/errno.h>
    #include <sys/termios.h>
    #include <sys/types.h>
    #include <sys/time.h>
    #include <unistd.h>

    #include <sys/filio.h>
    #include <sys/ioctl.h>
    #include <CoreFoundation/CoreFoundation.h>

    #include <IOKit/IOKitLib.h>
    #include <IOKit/serial/IOSerialKeys.h>
    #include <IOKit/IOBSD.h>

    //#include <pthread.h>

    #include "serialPort.h"

    #define DEVICENAME "/dev/tty.KeyUSA28Xport1"
    #define DEVICENAME1 "/dev/tty.KeyUSA28Xport2"


    static int open_port( char tty);

    serialPort *spOpen( char tty )
    {
    serialPort *sPort;


    if ( (sPort = (serialPort *) malloc( sizeof( serialPort ) ) ) == NULL )
    {
    perror( "malloc" );
    return NULL;
    }

    if ( ( sPort->spDescriptor = open_port( tty ) ) < 0 )
    {

    printf("already open\n");
    sPort->spDescriptor = 0;
    return NULL;
    }

    return sPort;
    }

    void spClose( serialPort * sPort )
    {
    close( sPort->spDescriptor );
    sPort->spDescriptor = 0;

    return;
    }

    int spRead( serialPort * sPort, unsigned char *input, int bytes )
    {
    return(read( sPort->spDescriptor, input, bytes ));
    }

    int open_port( char tty )
    {

    int spd;


    if (tty = 'g')
    {
    spd = open(DEVICENAME1, O_RDWR | O_NONBLOCK);
    }
    else
    {
    spd = open(DEVICENAME, O_RDWR | O_NONBLOCK);
    }


    return spd;
    }
     
  2. macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #2
    You must learn to walk before you can run.

    If you are making a library then you need to compile a little differently and make a library file with a tool called 'libtool'.

    The missing symbol for _main is the usual "main" entry point for executables, not libraries. Since your code doesn't have a main() function you get that error (and you want to make a library, not an executable).

    You can get all the info you need from this article:

    http://www.exittoshell.com/articles/content/mach-o-library.shtml
     

Share This Page