2012-01-19 4 views
1

저는 Stanford CS106B 온라인 코스를 다룰 것이며, 코스의 헤더 파일을 넣을 폴더 인/usr/local을 만들었습니다. 그러나 헤더 파일을 호출 할 때마다 문제가 발생합니다. 이것을 예로 들어 보겠습니다. 컴파일하려고하면 오류가 발생하지만 RandomChance (double n)는 헤더 파일 random.h의 함수입니다. 도움! 건축 x86_64에 대한Xcode 4에 헤더 파일 포함

정의되지 않은 심볼 : main.o를 LD에 flipCoin() : "(큰) RandomChance가"에서 참조 기호가 건축 x86_64의 그 소리 찾을 수 없습니다 : 오류 : 링커 명령이 실패했습니다 종료 코드 1

프로그램을 (호출을 볼 수 -v 사용)은 다음과 같습니다 :

#include <iostream> 
#include <string> 
#include "/usr/local/random.h" 

using namespace std; 

string flipCoin(); 

string flipCoin() { 
    if (RandomChance(0.50)) { 
     return "heads"; 
    } else { 
     return "tails"; 
    } 
} 

int main (int argc, const char * argv[]) 
{ 

    cout << "Enter number of votes" << endl; 
    cout << "Enter percentage spread between candidates" << endl; 
    cout << "Enter voting error percentage" << endl; 
    return 0; 
} 

이 random.h입니다

/* 
* Function: Randomize 
* Usage: Randomize(); 
* ------------------- 
* This function sets the random seed so that the random sequence 
* is unpredictable. If this function is not called, the other 
* functions will return the same values on each run. During the 
* debugging phase, it is best not to call this function, so that 
* program behavior is repeatable. 
*/ 
void Randomize(); 

/* 
* Function: RandomInteger 
* Usage: n = RandomInteger(low, high); 
* ------------------------------------ 
* This function returns a random integer in the range low to high, 
* inclusive. 
*/ 
int RandomInteger(int low, int high); 

/* 
* Function: RandomReal 
* Usage: d = RandomReal(low, high); 
* --------------------------------- 
* This function returns a random real number in the half-open 
* interval [low .. high), meaning that the result is always 
* greater than or equal to low but strictly less than high. 
*/ 
double RandomReal(double low, double high); 

/* 
* Function: RandomChance 
* Usage: if (RandomChance(p)) . . . 
* --------------------------------- 
* The RandomChance function returns true with the probability 
* indicated by p, which should be a floating-point number between 
* 0 (meaning never) and 1 (meaning always). For example, calling 
* RandomChance(.30) returns true 30 percent of the time. 
*/ 
bool RandomChance(double p); 

#endif /*RANDOM_H_*/ 

업데이트 : 그래서 효과가 있었고 #include simpio.h을 수행하여 다른 라이브러리를 추가했는데 모든 것이 엉망이되었습니다. 다음과 같은 38 개의 오류가 나타났습니다.

Ld /Users/alexandermoreno/Library/Developer/Xcode/DerivedData/voting-ccwjagcijcytcigfgxvxyiaplsxm/Build/Products/Debug/voting normal i386 
    cd "/Users/alexandermoreno/Documents/Paradigms/assignment 1/voting" 
    setenv MACOSX_DEPLOYMENT_TARGET 10.7 
    /Developer/usr/bin/clang++ -arch i386 -isysroot /Developer/SDKs/MacOSX10.7.sdk -L/Users/alexandermoreno/Library/Developer/Xcode/DerivedData/voting-ccwjagcijcytcigfgxvxyiaplsxm/Build/Products/Debug -F/Users/alexandermoreno/Library/Developer/Xcode/DerivedData/voting-ccwjagcijcytcigfgxvxyiaplsxm/Build/Products/Debug -filelist /Users/alexandermoreno/Library/Developer/Xcode/DerivedData/voting-ccwjagcijcytcigfgxvxyiaplsxm/Build/Intermediates/voting.build/Debug/voting.build/Objects-normal/i386/voting.LinkFileList -mmacosx-version-min=10.7 -lcs106 -o /Users/alexandermoreno/Library/Developer/Xcode/DerivedData/voting-ccwjagcijcytcigfgxvxyiaplsxm/Build/Products/Debug/voting 

Undefined symbols for architecture i386: 
    "___CFConstantStringClassReference", referenced from: 
     CFString in libcs106.a(mainwrapper.o) 
     CFString in libcs106.a(mainwrapper.o) 
     CFString in libcs106.a(mainwrapper.o) 
     CFString in libcs106.a(mainwrapper.o) 
     CFString in libcs106.a(mainwrapper.o) 
     CFString in libcs106.a(mainwrapper.o) 
     CFString in libcs106.a(mainwrapper.o) 
     ... 
    "_NSApp", referenced from: 
     +[Glue showAbout:] in libcs106.a(mainwrapper.o) 
     TerminateApp() in libcs106.a(mainwrapper.o) 
     +[NSBundleWithoutSpuriousErrorLog aloadNibNamed:owner:] in libcs106.a(mainwrapper.o) 
     _main in libcs106.a(mainwrapper.o) 
     -[ConsoleTextView keyDown:] in libcs106.a(ConsoleTextView.o) 
     +[Glue showAbout:] in libcs106.a(mainwrapper.o) 
     TerminateApp() in libcs106.a(mainwrapper.o) 
     +[NSBundleWithoutSpuriousErrorLog aloadNibNamed:owner:] in libcs106.a(mainwrapper.o) 
     _main in libcs106.a(mainwrapper.o) 
     -[ConsoleTextView keyDown:] in libcs106.a(ConsoleTextView.o) 
    "_objc_msgSendSuper", referenced from: 
     +[NSBundleWithoutSpuriousErrorLog aloadNibNamed:owner:] in libcs106.a(mainwrapper.o) 
     -[ConsoleTextView initWithFrame:] in libcs106.a(ConsoleTextView.o) 
     -[ConsoleTextView setFont:] in libcs106.a(ConsoleTextView.o) 
     -[ConsoleTextView dealloc] in libcs106.a(ConsoleTextView.o) 
     -[ConsoleTextView keyDown:] in libcs106.a(ConsoleTextView.o) 
     -[ConsoleTextView rangeForUserTextChange] in libcs106.a(ConsoleTextView.o) 
    "_CFBundleGetInfoDictionary", referenced from: 
     _main in libcs106.a(mainwrapper.o) 
    "_CFBundleCopyBundleURL", referenced from: 
     _main in libcs106.a(mainwrapper.o) 
    "_objc_msgSend", referenced from: 
     +[Glue applicationDidFinishLaunching:] in libcs106.a(mainwrapper.o) 
     +[Glue showAbout:] in libcs106.a(mainwrapper.o) 
     CocoaConsoleResize(int, int, int, int) in libcs106.a(mainwrapper.o) 
     TerminateApp() in libcs106.a(mainwrapper.o) 
     SetConsoleSize(int, int, int, bool) in libcs106.a(mainwrapper.o) 
     patched_read(void*, char*, int) in libcs106.a(mainwrapper.o) 
     CreateMenuWithItems(NSString*, menuitem*, int) in libcs106.a(mainwrapper.o) 
     ... 
    "_CFURLCreateCopyDeletingLastPathComponent", referenced from: 
     _main in libcs106.a(mainwrapper.o) 
    "_CFURLGetFileSystemRepresentation", referenced from: 
     _main in libcs106.a(mainwrapper.o) 
    "_CFBundleGetMainBundle", referenced from: 
     _main in libcs106.a(mainwrapper.o) 
    "Main()", referenced from: 
     +[Glue studentMain] in libcs106.a(mainwrapper.o) 
    "_CFRelease", referenced from: 
     _main in libcs106.a(mainwrapper.o) 
    "_NSFileHandleDataAvailableNotification", referenced from: 
     -[ConsoleTextView registerForNotifications] in libcs106.a(ConsoleTextView.o) 
    "_NSForegroundColorAttributeName", referenced from: 
     -[ConsoleTextView setFont:] in libcs106.a(ConsoleTextView.o) 
    "_NSFontAttributeName", referenced from: 
     -[ConsoleTextView setFont:] in libcs106.a(ConsoleTextView.o) 
     +[ConsoleTextView contentSizeForPointSize:numRows:numCols:] in libcs106.a(ConsoleTextView.o) 
    "_NSBeep", referenced from: 
     -[ConsoleTextView keyDown:] in libcs106.a(ConsoleTextView.o) 
    "_objc_msgSend_fpret", referenced from: 
     +[ConsoleTextView contentSizeForPointSize:numRows:numCols:] in libcs106.a(ConsoleTextView.o) 
    "_objc_msgSend_stret", referenced from: 
     -[ConsoleTextView setPointSize:numRows:numCols:center:] in libcs106.a(ConsoleTextView.o) 
     +[ConsoleTextView contentSizeForPointSize:numRows:numCols:] in libcs106.a(ConsoleTextView.o) 
     +[ConsoleTextView createConsoleInWindow] in libcs106.a(ConsoleTextView.o) 
    ".objc_class_name_NSThread", referenced from: 
     pointer-to-literal-objc-class-name in libcs106.a(mainwrapper.o) 
    ".objc_class_name_NSAutoreleasePool", referenced from: 
     pointer-to-literal-objc-class-name in libcs106.a(mainwrapper.o) 
    ".objc_class_name_NSDictionary", referenced from: 
     pointer-to-literal-objc-class-name in libcs106.a(mainwrapper.o) 
    ".objc_class_name_NSString", referenced from: 
     pointer-to-literal-objc-class-name in libcs106.a(mainwrapper.o) 
     pointer-to-literal-objc-class-name in libcs106.a(ConsoleTextView.o) 
    ".objc_class_name_NSMenu", referenced from: 
     pointer-to-literal-objc-class-name in libcs106.a(mainwrapper.o) 
    ".objc_class_name_NSMenuItem", referenced from: 
     pointer-to-literal-objc-class-name in libcs106.a(mainwrapper.o) 
    ".objc_class_name_NSBundle", referenced from: 
     pointer-to-literal-objc-class-name in libcs106.a(mainwrapper.o) 
     .objc_class_name_NSBundleWithoutSpuriousErrorLog in libcs106.a(mainwrapper.o) 
    (maybe you meant: .objc_class_name_NSBundleWithoutSpuriousErrorLog) 
    ".objc_class_name_NSApplication", referenced from: 
     pointer-to-literal-objc-class-name in libcs106.a(mainwrapper.o) 
    ".objc_class_name_NSObject", referenced from: 
     .objc_class_name_Glue in libcs106.a(mainwrapper.o) 
    ".objc_class_name_NSAttributedString", referenced from: 
     pointer-to-literal-objc-class-name in libcs106.a(ConsoleTextView.o) 
    ".objc_class_name_NSMutableDictionary", referenced from: 
     pointer-to-literal-objc-class-name in libcs106.a(ConsoleTextView.o) 
    ".objc_class_name_NSFont", referenced from: 
     pointer-to-literal-objc-class-name in libcs106.a(ConsoleTextView.o) 
    ".objc_class_name_NSScroller", referenced from: 
     pointer-to-literal-objc-class-name in libcs106.a(ConsoleTextView.o) 
    ".objc_class_name_NSScreen", referenced from: 
     pointer-to-literal-objc-class-name in libcs106.a(ConsoleTextView.o) 
    ".objc_class_name_NSWindow", referenced from: 
     pointer-to-literal-objc-class-name in libcs106.a(ConsoleTextView.o) 
    ".objc_class_name_NSScrollView", referenced from: 
     pointer-to-literal-objc-class-name in libcs106.a(ConsoleTextView.o) 
    ".objc_class_name_NSColor", referenced from: 
     pointer-to-literal-objc-class-name in libcs106.a(ConsoleTextView.o) 
    ".objc_class_name_NSNotificationCenter", referenced from: 
     pointer-to-literal-objc-class-name in libcs106.a(ConsoleTextView.o) 
    ".objc_class_name_NSFileHandle", referenced from: 
     pointer-to-literal-objc-class-name in libcs106.a(ConsoleTextView.o) 
    ".objc_class_name_NSData", referenced from: 
     pointer-to-literal-objc-class-name in libcs106.a(ConsoleTextView.o) 
    ".objc_class_name_NSTextView", referenced from: 
     .objc_class_name_ConsoleTextView in libcs106.a(ConsoleTextView.o) 
ld: symbol(s) not found for architecture i386 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

이는 #의 simpio.h 파일

#ifndef SIMPIO_H_ 
#define SIMPIO_H_ 
/* 
* File: simpio.h 
* Version: 1.0CPP 
* Last modified on Wed Sep 18 13:34:29 PDT 2002 by jzelenski 
* ---------------------------------------------------------- 
* This interface provides access to a simple package of 
* functions that simplify the reading of console input. 
*/ 

#include "genlib.h" 

/* 
* Function: GetInteger 
* Usage: n = GetInteger(); 
* ------------------------ 
* GetInteger reads a line of text from standard input and scans 
* it as an integer. The integer value is returned. If an 
* integer cannot be scanned or if more characters follow the 
* number, the user is given a chance to retry. 
*/ 

int GetInteger(); 


/* 
* Function: GetLong 
* Usage: n = GetLong(); 
* --------------------- 
* GetLong reads a line of text from standard input and scans 
* it into a long integer. The long is returned. If the 
* number cannot be scanned or if extra characters follow it, 
* the user is given a chance to retry. 
*/ 

long GetLong(); 

/* 
* Function: GetReal 
* Usage: x = GetReal(); 
* --------------------- 
* GetReal reads a line of text from standard input and scans 
* it as a double. If the number cannot be scanned or if extra 
* characters follow after the number ends, the user is given 
* a chance to reenter the value. 
*/ 

double GetReal(); 


/* 
* Function: GetLine 
* Usage: s = GetLine(); 
* --------------------- 
* GetLine reads a line of text from standard input and returns 
* the line as a string. The newline character that terminates 
* the input is not stored as part of the string that is returned. 
*/ 

string GetLine(); 

#endif /*SIMPIO_H_*/ 
+0

방금 ​​헤더를 복사하고 있습니다. 구현 파일은 어떻습니까? 당신이 얻는 것은 링커 오류입니다. random.cpp의 오브젝트 파일이 링커가 찾고있는 기본 경로에 있는지 확인하십시오. – Mahesh

+0

미안하지만, 나는 멍청한 사람이야. 무작위가 없습니다.cpp 파일을 사용하고 있으며 링커가 무엇인지 모릅니다. – mlstudent

+0

모든 헤더 파일과 함께 cs106lib.a 파일이 있습니다. 그 파일로 무언가를해야하는지 확실하지 않습니다. – mlstudent

답변

1

좋아, 그래서 이것이 인기있는 질문으로 표시되는 것을 알았습니다. 이 작업을 수행하는 모든 사용자에게 SEE 또는 iTunes의 psets가 아닌 cs106b의 최신 버전을 검색하고 다운로드 한 다음 필요한 경우 솔루션을 기다리는 것이 좋습니다. 많은 시간이 지나면 Xcode의 최신 버전과 함께 작동하도록 이미 설정 될 것입니다. 그렇지 않다면 잠재적으로 엉망이 될 것입니다. 또한 대부분의 CS106b 사이트에서 링커 오류가 발생할 경우 어떻게해야하는지 설명하는 문서가 있습니다.

0

헤더에 무엇입니까? 함수 또는 실제 선언에 대한 실제 정의가 있습니까?

또한 파일을 /usr/local/include에 넣으려고합니다. /usr/local이 (가) 헤더 검색 경로에있는 것으로 의심됩니다.

편집 :

라이브러리에는 헤더가 선언되어 있습니다. 검색된 라이브러리 경로 중 하나에 라이브러리를 넣으면 기회는 /usr/local/lib입니다.

편집 # 2 : 응답에서

에 : 라이브러리가 32 비트 아키텍처 용으로 컴파일 및 프로젝트의 아키텍처는 64 비트로 설정되어 있는지 가능성이 보인다

Hey, I did that and also used link binary with libraries to link the library. I then got this "ignoring file /Developer/SDKs/MacOSX10.7.sdk/usr/local/lib/libcs106.a, missing required architecture x86_64 in file." Could it be there is something wrong with the library for use in xcode 4? That's what another forum implied.

. 32 비트를 사용하도록 프로젝트 설정을 변경하면 라이브러리의 64 비트 버전을 사용할 수없는 경우 문제가 해결됩니다.

EDIT # 3 : 새 라이브러리가 objective-c 인 것처럼 보이거나 .m 파일 확장명을 사용하고 objective-c로 컴파일하는 것처럼 보입니다.

+0

헤더에는 RandomChance 함수에 대한 실제 정의가 있습니다. 나는 그것을 시도 할 것이다, 고마워. – mlstudent

+0

나는 이것을 수행하여'#include "/usr/local/include/random.h"'로 변경했지만 여전히 같은 오류가 발생한다. – mlstudent

+0

@ user1157605 "random.h"에 무엇이 있습니까? – Mahesh

관련 문제