I am new to C++. I have a problem with including the header. I'm trying to compile my a.cpp file and get this error. I'm using Sublime Text as a text editor. Can anyone help me with this problem? Thank you in advance!
Undefined symbols for architecture arm64:
"print()", referenced from:
_main in a-3ccfb2.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Here are my file:
/* Filename: a.cpp */
#include <iostream>
#include "b.h"
using namespace std;
int main() {
print();
return 0;
}
/* Filename: b.h */
#ifndef _b_h
#define _b_h
void print();
#endif
/* Filename: b.cpp */
#include <iostream>
#include "b.h"
using namespace std;
void print() {
cout << "Hello, world!" << endl;
}
I compile my cpp with: (this works fine except when I try to include my header file - example: #include "b.h")
g++ -std=c++17 -Wall a.cpp -o a
g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: arm64-apple-darwin21.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin