ld: symbol(s) not found for architecture x86_64問題解決
一 寫在前面的話:
音訊演算法模擬過程中,本來是一個跑的好好地程式,突然間在mac下就報錯了,出現的錯誤是:
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
神馬錯誤?執行程式很多年,還是第一次見這種錯誤啊。到底是什麼問題呢?
二 解決思路:
針對這種不是一下看出問題的地方,我就使用了簡化法,看看到底是什麼鬼。精簡了很多程式碼,發現不是程式碼出了問題,而是編譯器這塊出了問題,外事不懂問谷歌,搜一下吧,也許能給你靈感了。
果真如此,在一個小角落裡,我發現了這段話:
I had a similar warning/error/failure when I was simply trying to make an executable from two different object files (main.o and add.o). I was using the command:
gcc -o exec main.o add.o
But my program is a C++ program. Using theg++
compiler solved my issue:
g++ -o exec main.o add.o
I was always under the impression thatgcc
could figure these things out on its own. Apparently not. I hope this helps someone else searching for this error.
三 解決方法:
檢視自己的Makefile檔案,才發現這個是使用的g++,改一下試一下,把它改成gcc之後,馬上好了。哈哈,看來是編譯器搗的鬼啊。
四 反思:
這種問題,暴露了自身的基礎知識還不夠紮實啊,看來還要多多學習,多多學習。