iT邦幫忙

0

Mac 上執行 visual studio code 的c++ 標頭檔連結問題。

  • 分享至 

  • xImage

在mac terminal 執行 gcc Source.cpp 出現以下回報
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

目前資料夾中有三個file, 分別都有引用到。 不知道是什麼問題。

  1. Source.cpp
    2. {#include
    #include
    #include "Rectangle.h"}

  2. Rectangle.h
    3. {#ifndef RECTANGLE_H
    #define RECTANGLE_H
    class Rectangle..
    #endif}

  3. Rectangle.cpp
    4. {#include "Rectangle.h"}

感謝查看!!!

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1
海綿寶寶
iT邦大神 1 級 ‧ 2021-02-09 08:56:09
最佳解答

試試看一次 gcc 兩個檔案
gcc Source.cpp Rectangle.cpp

mac$ gcc Source.cpp
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
mac$ gcc Source.cpp Rectangle.cpp
mac$ ls -al a.*
-rwxr-xr-x  1 mac  staff  16536  2  9 08:53 a.out
mac$ 
hsushihli iT邦新手 5 級 ‧ 2021-02-09 18:01:03 檢舉

目前狀況是,若直接由vscode 上面執行
會出現以下feedback。
Undefined symbols for architecture x86_64:
"Rectangle::getPerimeter()", referenced from:
_main in Source-673073.o
"Rectangle::getArea()", referenced from:
_main in Source-673073.o
"Rectangle::Rectangle(double, double)", referenced from:
_main in Source-673073.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
但若是由cmd 執行 gcc Source.cpp Rectangle.cpp
會出現以下feedback.
Undefined symbols for architecture x86_64:
"std::__1::locale::use_facet(std::__1::locale::id&) const", referenced from:
std::__1::ctype const& std::__1::use_facet<std::__1::ctype >(std::__1::locale const&) in Source-9206a8.o
"std::__1::ios_base::getloc() const", referenced from:
std::__1::basic_ios<char, std::__1::char_traits >::widen(char) const in Source-9206a8.o
.....
Dwarf Exception Unwind Info (__eh_frame) in Source-9206a8.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
太長就貼了一部分而已。

非常感謝你的回答與時間!!!

我模擬不出跟你一樣的錯誤訊息
幫不上忙
/images/emoticon/emoticon25.gif

hsushihli iT邦新手 5 級 ‧ 2021-02-13 22:17:32 檢舉

沒事~謝謝你的幫忙!!!

我要發表回答

立即登入回答