Hi everyone I'm trying to compile a simple class example in C++
I've a MacBook Pro with Apple Silicon M1 Pro with MacOS Monterey 12.6.1.
I use Visual Studio Code as IDE. And I can't compile my code (simple) because this error I throw:
ld: symbol(s) not found for architecture arm64
I'm running the compilation using the "play" button on VSC, and it uses clang++ under the hood (as you can see later in the error). I already tried changing the compiler to gcc and g++ but the problem is still the same.
Follows more details...
main.cpp
#include "TalkToSPI.hpp"
#define sd_cspin 10
#define eth_cspin 12
int main(int argc, char const *argv[])
{
TalkToSPI t;
}
TalkToSPI.hpp
#ifndef TALKTOSPI_HPP
#define TALKTOSPI_HPP
#include "vector"
#include <string>
#include <iostream>
class TalkToSPI {
private:
struct Device {
uint16_t Id;
uint8_t CS_Pin;
};
std::vector<Device> devices;
public:
TalkToSPI();
void addDevice(uint8_t cs_pin, uint16_t device_id = 0);
bool removeDevice(uint16_t device_id);
void talkTo(uint16_t device_id);
void showDevices();
};
#endif
TalkToSPI.cpp
#include "TalkToSPI.hpp"
TalkToSPI::TalkToSPI(){}
void TalkToSPI::addDevice(uint8_t cs_pin, uint16_t device_id) {
Device d;
d.Id = device_id;
d.CS_Pin = cs_pin;
TalkToSPI::devices.push_back(d);
}
bool TalkToSPI::removeDevice(uint16_t device_id) {
uint8_t tmp = 0;
bool res = false;
for (size_t i = 0; i < devices.size()-1; i++)
{
if (devices[i].Id == device_id) {
tmp = i;
res = true;
break;
}
}
if (res) devices.erase(devices.begin() + tmp);
return res;
}
void TalkToSPI::talkTo(uint16_t device_id) {
}
void TalkToSPI::showDevices() {
for (const auto &d : devices) {
std::cout << d.Id << std::endl;
std::cout << d.CS_Pin << std::endl << std::endl << std::endl;
}
}
I looked at the code for a long time (it's a easy easy easy code)... but I still get this error that I don't understand... (P.S. I already tried to remove all spaces in path names... same)
/usr/bin/clang++ -fcolor-diagnostics -fansi-escape-codes -g /Users/antonellobarbone/Documents/GitHub/Inspector/Board_Firmware/TalkToSPI/TalkToSPI/main.cpp -o /Users/antonellobarbone/Documents/GitHub/Inspector/Board_Firmware/TalkToSPI/TalkToSPI/main
Undefined symbols for architecture arm64:
"TalkToSPI::TalkToSPI()", referenced from:
_main in main-e2a4e6.o
ld: symbol(s) not found for architecture arm64
If I run the same code on Xcode it works... but my goal is to get working the compiling from Visual Studio Code, not from Xcode or the CLI.