I recently added the file Serial.c and Serial.h to my Xcode project.
The code for Serial.c is as follows,
#include <stdio.h> /* Standard input/output definitions */
#include <stdlib.h>
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
/*
* 'open_port()' - Open serial port on dock connector pins 13RX / 12TX
*
* Returns the file descriptor on success or -1 on error.
*/
int open_port(void)
{
int fd = -1; /* File descriptor for the port */
struct termios options;
fd = open("/dev/tty.iap", O_RDWR | O_NOCTTY | O_NDELAY); // O_NOCTTY - don't be controlling terminal, O_NODELAY don't care about DCD signal state
if ( fd == -1)
{
// couldn't open the port
perror("open_port: Unable to open /dev/tty.iap - ");
}
else
fcntl(fd, F_SETFL, 0);
tcgetattr(fd, &options); // get current options for the port
// set the baud rate
cfsetispeed(&options, B2400);
cfsetospeed(&options, B2400);
// enable the receiver and set local mode
options.c_cflag |= (CLOCAL | CREAD);
// set the new options for the port
tcsetattr(fd, TCSANOW, &options);
return (fd);
}
The serial.h file,
NSInteger openPort();
I am trying to get the output of the Serial RX data stream from the iPhone into a NSLog statement.
I call the OpenPort function in the ViewControllerSerialConsole.m file
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
#if !TARGET_IPHONE_SIMULATOR
NSInteger serial = openPort();
NSLog(@"The serial data is %d",serial);
//_serialView.text = serial;
#endif
}
The program compiles fine on the iPhone Simulator but doesn’t compile on an iPhone.
I get the following error messages,
Undefined symbols for architecture armv7:
“_openPort”, referenced from:
-[ViewControllerSerialConsole viewDidLoad] in ViewControllerSerialConsole.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ld: symbol(s) not found for architecture armv7
Any help on troubleshooting this problem would be appreciated.
Your app compiles fine for the simulator because you’re not referring to the missing “
open_port” or “openPort” symbol**.In your Xcode project, select your “
Serial.m” file in the list of files (along the left edge of the workspace) and look at the File Inspector for that file.Make sure the checkbox is ON for your project in the “Target Membership” setting.
** while we are on the subject, is your function named correctly between your Serial.m & Serial.h file? I see “
open_port” in one and “openPort” in the other.