2012-08-04 35 views
0

我最近將文件Serial.cSerial.h添加到我的Xcode項目中。Xcode編譯錯誤 - 架構armv7找不到ld:symbol(s)

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();

我試圖讓串行RX數據流從iPhone輸出成NSLog語句。

我呼籲在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上沒有編譯OpenPort功能。

我得到以下的錯誤消息,

爲架構的ARMv7未定義符號: 「_openPort」,從引用: - [ViewControllerSerialConsole viewDidLoad中]在ViewControllerSerialConsole.o LD:符號(多個)未找到架構ARMv7的 鐺:錯誤:連接命令,退出代碼1失敗(使用-v看到調用)

LD:符號(S)未找到的ARMv7架構

上troubleshooti任何幫助這個問題將不勝感激。

+1

在上面的代碼中,您有一個名爲'open_port()'的函數,但在調用代碼中,您調用'openPort()'(注意缺少下劃線)。那是故意的嗎? – user1118321 2012-08-04 00:40:33

回答

5

你的應用程序編譯好的模擬器,因爲你不是指缺少的「open_port」或「openPort」符號**。

在您的Xcode項目中,在文件列表中(沿着工作區的左邊緣)選擇您的「Serial.m」文件,並查看該文件的文件檢查器。

確保複選框ON在「目標會員」的設置項目。

Make sure Target Membership is selected for your .m file

**,而我們關於這個問題,是你的函數你Serial.m & Serial.h文件之間的正確命名?我在其中一個看到「open_port」,而在另一個看到「openPort」。

+0

我將'openPort'改爲'open_Port',我仍然收到同樣的錯誤。 「串行」文件是「Serial.c」和「Serial.h」,它們應該沒有區別。 不知怎的,我想我得到這個錯誤,因爲我鏈接到'Serial.c'文件中沒有包含在項目中的庫,但我可能是錯的。 哦,複選框被檢查爲'Serial.c'文件,但沒有'.h'文件,我不認爲可以檢查'.h'文件。 – Chris 2012-08-04 01:04:56

+0

你是對的,這是一個開放式的錯字,它阻止了它的編譯,ty – Chris 2012-08-04 01:09:02

相關問題