天天看點

Mac下Clion編譯錯誤:Undefined symbols for architecture x86_64

在使用CLion做LeetCode題編譯時,突然出現了一下的情況:

Undefined symbols for architecture x86_64:
  "Solution::isCommonPrefix(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&, int)", referenced from:
      Solution::longestCommonPrefix(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&) in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)           

首先在網上查詢錯誤原因,大概有兩點:

1、編譯lib沒有找到,可能相應的編譯環境不正确,缺少某樣東西。

2、自己寫的代碼問題,最有可能的原因就是所用的控制符與系統符号相沖突或者其他情況。

在網上查了一大堆修改編譯選項的都沒有什麼用

最後無奈仔細檢查了一下程式,好吧,發現問題了:

有一個函數定義和聲明沒有嚴格對應,于是導緻編譯器在編譯的時候産生的符号表無法與實際程式中的函數對應,是以導緻了該錯誤。

是以總結如下:不管怎麼說先排查自己的程式到底有沒有問題,沒有問題在考慮其他!

繼續閱讀