一 寫在前面的話:
音頻算法仿真過程中,本來是一個跑的好好地程序,突然間在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 the g++
compiler solved my issue:
g++ -o exec main.o add.o
I was always under the impression that gcc
could figure these things out on its own. Apparently not. I hope this helps someone else searching for this error.
三 解決方法:
查看自己的Makefile文件,才發現這個是使用的g++,改一下試一下,把它改成gcc之后,馬上好了。哈哈,看來是編譯器搗的鬼啊。
四 反思:
這種問題,暴露了自身的基礎知識還不夠扎實啊,看來還要多多學習,多多學習。