0

最近、ファイルSerial.cSerial.hXcode プロジェクトに追加しました。

のコード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 のシンボルが見つかりません

この問題のトラブルシューティングに関するヘルプをいただければ幸いです。

4

1 に答える 1

5

欠落している「open_port」または「openPort」記号**を参照していないため、アプリはシミュレーター用に正常にコンパイルされます。

Xcodeプロジェクトで、Serial.m(ワークスペースの左端に沿って)ファイルのリストから ""ファイルを選択し、そのファイルのファイルインスペクターを確認します。

「ターゲットメンバーシップ」設定で、プロジェクトのチェックボックスがオンになっていることを確認します。

.mファイルにターゲットメンバーシップが選択されていることを確認してください

**この件については、Serial.mファイルとSerial.hファイルの間で関数の名前が正しく設定されていますか?open_port片方に「」、もう片方に「」が見えopenPortます。

于 2012-08-04T00:39:27.487 に答える