gpt4 book ai didi

c++ - PIMPL 无法在 macOS 上编译

转载 作者:行者123 更新时间:2023-11-28 04:44:05 26 4
gpt4 key购买 nike

<分区>

我正在阅读 pimpl code from github ,并尝试在我的 macOS 笔记本电脑中编译如下:

文件:foo.cpp

#include "foo.h"
#include <memory>

class foo::impl
{
public:
void do_internal_work()
{
internal_data = 5;
}
private:
int internal_data = 0;
};
foo::foo()
: pimpl{std::make_unique<impl>()}
{
pimpl->do_internal_work();
}
foo::~foo() = default;
foo::foo(foo&&) = default;
foo& foo::operator=(foo&&) = default;

文件:foo.h

#include <memory>
class foo
{
public:
foo();
~foo();
foo(foo&&);
foo& operator=(foo&&);
private:
class impl;
std::unique_ptr<impl> pimpl;
};

文件 man.cpp

#include "foo.h"

#include <iostream>

int main() {
foo x;
}

我尝试使用clang++ -std=c++14 main.cc -o main 编译,但出现错误:

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com