Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

rain

macrumors newbie
Original poster
Oct 17, 2004
2
0
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;
}
 

Sayer

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.