저는 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_*/
방금 헤더를 복사하고 있습니다. 구현 파일은 어떻습니까? 당신이 얻는 것은 링커 오류입니다. random.cpp의 오브젝트 파일이 링커가 찾고있는 기본 경로에 있는지 확인하십시오. – Mahesh
미안하지만, 나는 멍청한 사람이야. 무작위가 없습니다.cpp 파일을 사용하고 있으며 링커가 무엇인지 모릅니다. – mlstudent
모든 헤더 파일과 함께 cs106lib.a 파일이 있습니다. 그 파일로 무언가를해야하는지 확실하지 않습니다. – mlstudent