clang: error: linker command failed with exit code 1 (use -v to see invocation)

I'm having a ton of trouble ever since updating to MacOS Ventura on my M1 Pro Macbook.

I've tried everything but I have identified when the errors are actually occurring. When I call a function. I've written a very basic "Welcome" program below.

The main.cpp file is as follows

// C++
#include <iostream>
#include "declareFuncs.h"

int main() {

 welcome();

}

and the "declareFuncs.h" is as follows

// C++
#ifndef UNTITLED_DECLAREFUNCS_H
#define UNTITLED_DECLAREFUNCS_H

void welcome();

#endif //UNTITLED_DECLAREFUNCS_H

and the function is defined in the following source file.

// C++
#include <iostream>

void welcome(){
    std::cout << "Welcome!";
}

As you can see, it's a very basic program and should compile fine. But when I go to compile it, the compiler spits this back at me and I cannot for the life of me find a solution. I'm tempted to go buy an external drive and rollback this update.

Undefined symbols for architecture arm64:
  "welcome()", referenced from:
      _main in main-199bfc.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

What's going wrong here? how can I fix this? It's beyond frustrating at this point.

I have the same issue after updating to macOS Ventura on my M2 Pro Macbook.

This is working for me:

% cat declareFuncs.h 
// C++
#ifndef UNTITLED_DECLAREFUNCS_H
#define UNTITLED_DECLAREFUNCS_H

void welcome();

#endif //UNTITLED_DECLAREFUNCS_H
% cat declareFuncs.cpp
// C++
#include <iostream>

void welcome(){
    std::cout << "Welcome!";
}
% cat main.cpp         
// C++
#include <iostream>
#include "declareFuncs.h"

int main() {

 welcome();

}
% clang DeclareFuncs.cpp main.cpp -l c++
% ./a.out
Welcome!

This is on a MacBook Air (M1, 2020) running macOS 13.0.1 with Xcode 14.1 selected using xcode-select. [I need to update that machine to the latest, but I don’t think that’ll make a significant difference.]

Please repeat the above and, if you still have problems, post a Terminal transcript of exactly what you did.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

For me just using g++ instead of clang / gcc does it just finee

clang: error: linker command failed with exit code 1 (use -v to see invocation)
 
 
Q