首页 > 解决方案 > 在 mac 上编译 c++ 程序时出现“clang 错误”

问题描述

我正在尝试在我的 Mac 上运行我的 C++ 程序,我尝试了 VS Code 和 Clion,不幸的是,在这两种情况下,我都得到了相同的错误代码。

我要做的就是从另一个文件中获取方法,并在编译时在我的主文件中使用它。

主要代码文件

#include "pch.h"
#include "GUI.h"

using namespace std;


int main() 
{
    GUI gui;

    gui.logoScreen();

}

图形用户界面文件

#include "pch.h"
#include "GUI.h"

using namespace std;

void GUI::logoScreen() {
    cout <<  "@@@@@@@   @@@@@@   @@@@@@@   @@@@@@@                     @@@@@@@@" << endl;
    cout << "@@@@@@@@  @@@@@@@@  @@@@@@@@  @@@@@@@@                   @@@@@@@@@" << endl;
    cout << "!@@       @@!  @@@  @@!  @@@  @@!  @@@                   !@@" << endl;        
    cout << "!@!       !@!  @!@  !@!  @!@  !@!  @!@                   !@!" << endl;        
    cout << "!@!       @!@!@!@!  @!@!!@!   @!@  !@!     @!@!@!@!@     !@! @!@!@" << endl;  
    cout << "!!!       !!!@!!!!  !!@!@!    !@!  !!!     !!!@!@!!!     !!! !!@!!" << endl;  
    cout << ":!!       !!:  !!!  !!: :!!   !!:  !!!                   :!!   !!:" << endl;  
    cout << ":!:       :!:  !:!  :!:  !:!  :!:  !:!                   :!:   !::" << endl;
    cout <<  "::: :::  ::   :::  ::   :::   :::: ::                    ::: ::::" << endl;  
    cout <<  ":: :: :   :   : :   :   : :  :: :  :                     :: :: :" << endl;

}

错误代码:

Undefined symbols for architecture x86_64:
  "GUI::logoScreen()", referenced from:
      _main 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)

标签: c++macoscompiler-errors

解决方案


推荐阅读