2016-08-13 103 views
0

我正在嘗試關注http://gnuu.org/2009/09/18/writing-your-own-toy-compiler教程。我收到以下錯誤。ld:未找到架構x86_64錯誤的符號

我錯過了什麼?

Invoking: GCC C++ Compiler 
g++ -std=c++0x -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -I/usr/local/opt/llvm/include -O0 -g3 -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -std=c++11 -fPIC -MMD -MP -MF"src/main.d" -MT"src/main.o" -o "src/main.o" "../src/main.cpp" 
In file included from ../src/main.cpp:2: 
../src/node.h:17:61: warning: control reaches end of non-void function [-Wreturn-type] 
    virtual llvm::Value* codeGen(CodeGenContext& context) { } 
                  ^
../src/node.h:63:19: warning: field 'rhs' will be initialized after field 'op' [-Wreorder] 
     lhs(lhs), rhs(rhs), op(op) { } 
       ^
2 warnings generated. 
Undefined symbols for architecture x86_64: 
    "yyparse()", referenced from: 
     _main in main-974049.o 
    "_programBlock", referenced from: 
     _main in main-974049.o 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 
make: *** [src/main.o] Error 1 
+0

請張貼您的代碼。 – SurvivalMachine

+0

「我錯過了什麼?」看起來像一個'return'語句。 – user4581301

+0

在較少的狙擊手陣線上,無論您如何訂購成員初始值設定項列表,都會按聲明順序初始化成員。這可能是也可能不是問題,但是如果你有'memberB(42),memberA(memberB.stuff)'和'memberA'是在類中聲明的,'memberA'將會初始化爲未初始化的'MemberB'。不好的東西。 – user4581301

回答

3

你錯過了幾件事情。

  1. 您錯過了編譯器的第一條警告消息通知您代碼中存在明顯錯誤的事實。你需要解決這個問題。

  2. 編譯器的第二條警告消息告訴你代碼中可能存在的另一個錯誤。

  3. 最後,您錯過了-c選項到g++,導致編譯器嘗試鏈接不完整的程序,而不是生成目標模塊。

+0

'-c'標誌修復了很多問題。問題似乎是空的{}塊。我正在修復它們。 – turhanco

相關問題