最近、ファイルSerial.c
をSerial.h
Xcode プロジェクトに追加しました。
のコードSerial.c
は次のとおりです。
#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);
}
serial.h
ファイル、
NSInteger openPort();
iPhone からのシリアル RX データ ストリームの出力を NSLog ステートメントに取得しようとしています。
ファイルOpenPort
内の関数を呼び出しますViewControllerSerialConsole.m
- (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
}
このプログラムは、iPhone シミュレーターでは正常にコンパイルされますが、iPhone ではコンパイルされません。
次のエラー メッセージが表示されます。
アーキテクチャ armv7 の未定義シンボル: "_openPort"、参照元: -[ViewControllerSerialConsole viewDidLoad] in ViewControllerSerialConsole.o ld: アーキテクチャ armv7 のシンボルが見つかりません。clang: エラー: リンカー コマンドが終了コード 1 で失敗しました (-v を使用して確認します呼び出し)
ld: アーキテクチャー armv7 のシンボルが見つかりません
この問題のトラブルシューティングに関するヘルプをいただければ幸いです。