如何为架构x86_64错误修复g ++未定义符号?

 帅气zxc_925 发布于 2023-01-16 14:50

首先,我已经在Stackoverflow上阅读了有关此问题的相关内容,但我仍然无法解决它.我尽可能简化了我的代码.

我只有一个带.h和.cpp文件的自定义类,但是在尝试从main.cpp创建此类的实例时出错.

main.cpp中

#include "Customer.h"
using namespace std;

int main() {
    Customer a("string");

    return 0;
}

Customer.h

using namespace std;

class Customer {
public:
    Customer(string input);
};

为customer.cpp

#include "Customer.h"
using namespace std;

Customer::Customer(string input) {
}

我得到的错误信息如下?

  gcc *.cpp -o k


  Undefined symbols for architecture x86_64:
    "std::__1::basic_string, std::__1::allocator >::__init(char const*, unsigned long)", referenced from:
        _main in main-40340f.o
    "std::__1::basic_string, std::__1::allocator >::basic_string(std::__1::basic_string, std::__1::allocator > const&)", referenced from:
        _main in main-40340f.o
    "std::__1::basic_string, std::__1::allocator >::~basic_string()", referenced from:
        _main in main-40340f.o
    "std::terminate()", referenced from:
        ___clang_call_terminate in main-40340f.o
    "___cxa_begin_catch", referenced from:
        ___clang_call_terminate in main-40340f.o
    "___gxx_personality_v0", referenced from:
        _main in main-40340f.o
        Dwarf Exception Unwind Info (__eh_frame) in main-40340f.o
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)

clang: error: linker command failed with exit code 1 (use -v to see invocation)

我运行Mac OS X 10.9和Sublime Text 3. gcc -v给出以下内容:

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix

当我编写空构造函数而不是这些时,它编译没有问题.

什么可能导致这个问题?

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有