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;
}
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;
}