I have a very simple program that I am attempting to run with vs code using the c++ extension with clang++ on mac m1 chip.
I’ve done a decently exhaustive search on this issue, and haven’t figured out the root cause. This seems to be a common early mistake to new c++ users, so any solution I will try my best to communicate along. Here are my files.
add.hpp:
int add(int x, int y);
main.cpp:
#include "add.hpp"
#include <iostream>
int main()
{
std::cout << "The sum of 3 and 4 is " << add(3, 4) << 'n';
return 0;
}
task.json:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-fcolor-diagnostics",
"-fansi-escape-codes",
"-g",
"-O2",
"-DNDEBUG",
"-ggdb",
"-pedantic-errors",
"-Wall",
"-Weffc++",
"-Wextra",
"-Wconversion",
"-Wsign-conversion",
"-std=c++17",
"${fileDirname}/**.cpp",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
I receive the following error:
Starting build...
/usr/bin/clang++ -fcolor-diagnostics -fansi-escape-codes -g -O2 -DNDEBUG -ggdb -pedantic-errors -Wall -Weffc++ -Wextra -Wconversion -Wsign-conversion -std=c++17 /Users/kendallreid/cpp_bug/**.cpp -o /Users/kendallreid/cpp_bug/main
Undefined symbols for architecture arm64:
"add(int, int)", referenced from:
_main in main-11e098.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Build finished with error(s).