I've been trying tu run this code but I'm keep getting this long error message. I think the code is okay, because it's working on my Windows computer, so I think it's a problem with my compiler. I am using VisualStudioCode on macOS Catalina 10.15.7 and clang 12.0.0.
#include<iostream>
#include <memory>
#include "Wezel.h"
using namespace std;
int main(){
for (int i = 0; i < 10; i++) {
unique_ptr<Wezel>(new Wezel());
}
return 0;
}
#include "Wezel.h"
#include <iostream>
using namespace std;
Wezel::~Wezel() {
cout << "Destruct" << endl;
}
#ifndef WEZEL_H
#define WEZEL_H
class Wezel
{
public:
~Wezel();
};
#endif
majkel@mbp-micha RecyclingCpp % cd "/Users/majkel/Documents/Obiektowe/RecyclingCpp/" && g++ tempCodeRunnerFile.cpp -o tempCodeRunnerFile && "/Users/majkel/Documents/Obiektowe/RecyclingCpp/"tempCodeRunnerFile
Undefined symbols for architecture x86_64:
"Wezel::~Wezel()", referenced from:
std::__1::default_delete<Wezel>::operator()(Wezel*) const in tempCodeRunnerFile-40bbc5.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
You didn't tell the compiler that Wezel.cpp
was part of the thing you are trying to build, so it doesn't know where to find Wezel::~Wezel()
.
Try like this:
g++ main.cpp Wezel.cpp
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.