体系结构x86_64的未定义符号

Undefined Symbol(s) for architecture x86_64

本文关键字:未定义 符号 x86 体系结构      更新时间:2023-10-16

所以我已经浏览了一段时间来弄清楚这是怎么回事,但很多时候是因为程序缺少main或其他东西,但我的程序有所有需要的方法。

#include <iostream>
#include <string>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
typedef mp::cpp_int my_int;
bool isPalimdrome(int);
bool isBinaryPalimdrom(std::string);
std::string base10To2(int);
std::string reverse(std::string);
int main() {
    int num = 0;
    int sum = 0;
    while (num < 1000000) {
        std::string num_bin = base10To2(num);
        if (isPalimdrome(num) && isBinaryPalimdrom(num_bin) ){
            sum += num;     
        }
        num++;
    }
    return 0;
}

bool isPalimdrome(int x) {
    std::ostringstream strs;
    strs << x;
    const std::string ori = strs.str();
    const std::string rev = reverse(ori);
    if (rev.compare(ori) == 0) return true;
    return false;
}
bool isBinaryPalimdrome(std::string s) {
    const std::string ori = s;
    const std::string rev = reverse(ori);
    if (rev.compare(ori) == 0) return true;
    return false;
}
std::string base10To2(int x) {
    std::string out = "";
    while (x != 0) {
        if (x % 2 == 0) 
            out += "0";
        else
            out += "1";
        x /= 2;
    }
    return out;
}
std::string reverse(std::string s) {
    std::string result = "";
    for (const char& x : s) {
        result = x + result;
    }
    //std::cout << "This is the original " <<
    //  s << std::endl;
    //std::cout << "This is the reversed " << 
    //  result << std::endl;    
    return result;
}

我发布了完整的代码以防万一,但我相信它与我的isBinaryPalimdrome()函数有关,这是我得到的错误:

Undefined symbols for architecture x86_64:
  "isBinaryPalimdrom(std::string)", referenced from:
      _main in Problem36-cae975.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Problem36] Error 1

我在Mac上编程,如果有关系的话。

我猜是打字错误造成了疼痛:你宣称:

bool isBinaryPalimdrom(std::string);

但是你定义了

bool isBinaryPalimdrome(std::string s) 
//                    ^