文件是为不受支持的文件格式构建的?

2024-04-28

我在 OS X 上,当我尝试在终端中执行此命令时出现编译错误

g++ -Wall -o test_E test_E.cppdynamic_array.cpp oracle.o

我的其他 C++ 文件,例如test_A.cpp and test_B.cpp在相同的命令上运行良好,但没有最后一部分,例如

g++ -Wall -o test_A test_A.cpp 动态_array.cpp

我也尝试运行命令而不oracle.o它给出了相同的错误,但没有不支持的文件格式

我该如何解决这个问题?

ld: warning: ignoring file oracle.o, file was built for unsupported file 
format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
0x00 0x00 ) which is not the architecture being linked (x86_64): oracle.o
Undefined symbols for architecture x86_64:
"oracle::insert(int, int)", referenced from:
  generate_oracle(oracle&, int, int, int) in test_E-2b7bb8.o
  run_tests(dynamic_array&, oracle&) in test_E-2b7bb8.o
 "oracle::operator[](unsigned int)", referenced from:
  print_state(dynamic_array&, oracle&) in test_E-2b7bb8.o
  compare_content(dynamic_array&, oracle&) in test_E-2b7bb8.o
"oracle::get_allocated_size() const", referenced from:
  print_state(dynamic_array&, oracle&) in test_E-2b7bb8.o
  compare_content(dynamic_array&, oracle&) in test_E-2b7bb8.o
 "oracle::get_size() const", referenced from:
  print_state(dynamic_array&, oracle&) in test_E-2b7bb8.o
  compare_exceptions(dynamic_array&, oracle&) in test_E-2b7bb8.o
  compare_content(dynamic_array&, oracle&) in test_E-2b7bb8.o
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)

这是test_E.cpp

 #include <iostream>

 #include "dynamic_array.h"
 #include "oracle.h"

 using namespace std;

void generate_cut(dynamic_array &cut, int start, int delta, int count) {
 for (int i = 0; i < count; i++) {
    cut.insert(start, i);
    start += delta;
   }
}

void generate_oracle(oracle &orc, int start, int delta, int count) {
  for (int i = 0; i < count; i++) {
    orc.insert(start, i);
    start += delta;
     }
  }

void print_state(dynamic_array &cut, oracle &orc) {
 cout << "***** cut" << endl;
 cout << "size: " << cut.get_size() << endl;
 cout << "allocated size: " << cut.get_allocated_size() << endl;
 for (int i = 0; i < cut.get_size(); i++) {
    cout << cut[i] << " ";
    if (i > 50) { // avoid lengthy output
        cout << " ...";
        break;
    }
  }
 cout << endl;

 cout << "***** oracle" << endl;
 cout << "size: " << orc.get_size() << endl;
 cout << "allocated size: " << orc.get_allocated_size() << endl;
 for (int i = 0; i < orc.get_size(); i++) {
    cout << orc[i] << " ";
    if (i > 50) { // avoid lengthy output
        cout << " ...";
        break;
    }
 }
 cout << endl;
 }

int const_f(const dynamic_array &cut, int i) {
  return cut[i];
 }

int compare_exceptions(dynamic_array &cut, oracle &orc) {
{
// ********** operator[]
int indexes[] = {orc.get_size(), orc.get_size()+1000};
int N = sizeof(indexes)/sizeof(int);
for (int i = 0; i < N; i++) {
    int caught = 0;
    try {
        cut[indexes[i]];
    } catch (dynamic_array::exception) {
        caught = 1;
    }
    if (!caught) {
        cout << "operator[]: uncaught index range exception at: ";
        cout << indexes[i] << endl;
        return 0;
    }
   }
  }

  {
   // ********** operator[] const
  int indexes[] = {orc.get_size(), orc.get_size()+1000};
  int N = sizeof(indexes)/sizeof(int);
  for (int i = 0; i < N; i++) {
    int caught = 0;
    try {
        cut[indexes[i]];
    } catch (dynamic_array::exception) {
        caught = 1;
    }
    if (!caught) {
        cout << "operator[] const: uncaught index range exception at: ";
        cout << indexes[i] << endl;
        return 0;
    }
   }
  }

 {
  // ********** insert(int,int)
 int indexes[] = {-1000, -1, orc.get_size()+1, orc.get_size()+1000};
 int N = sizeof(indexes)/sizeof(int);
 for (int i = 0; i < N; i++) {
    int caught = 0;
    try {
        cut.insert(0, indexes[i]);
    } catch (dynamic_array::exception) {
        caught = 1;
    }
    if (!caught) {
        cout << "insert(int,int): uncaught index range exception at: ";
        cout << indexes[i] << endl;
        return 0;
    }
   }
  }

 {
  // ********** insert(dynamic_array&,int)
  int indexes[] = {-1000, -1, orc.get_size()+1, orc.get_size()+1000};
  int N = sizeof(indexes)/sizeof(int);
  dynamic_array a;
  for (int i = 0; i < N; i++) {
    int caught = 0;
    try {
        cut.insert(a, indexes[i]);
    } catch (dynamic_array::exception) {
        caught = 1;
    }
    if (!caught) {
        cout << "insert(dynamic_array&,int): uncaught index range exception  at: ";
        cout << indexes[i] << endl;
        return 0;
    }
   }
  }

 {
  // ********** remove(int)
  int indexes[] = {-1000, -1, orc.get_size(), orc.get_size()+1000};
  int N = sizeof(indexes)/sizeof(int);
  for (int i = 0; i < N; i++) {
    int caught = 0;
    try {
        cut.remove(indexes[i]);
    } catch (dynamic_array::exception) {
        caught = 1;
    }
    if (!caught) {
        cout << "remove(int): uncaught index range exception at: ";
        cout << indexes[i] << endl;
        return 0;
    }
   }
  }

 {
  // ********** remove(int,int)
  // start out of range
  int start_indexes[] = {-1000, -1, orc.get_size()+1, orc.get_size()+1000};
  int N = sizeof(start_indexes)/sizeof(int);
  for (int i = 0; i < N; i++) {
    int caught = 0;
    try {
        cut.remove(start_indexes[i], orc.get_size());
    } catch (dynamic_array::exception) {
        caught = 1;
    }
    if (!caught) {
        cout << "remove(int,int): uncaught index range exception at: ";
        cout << start_indexes[i] << "," << orc.get_size() << endl;
        return 0;
    }
   }

   // end out of range
   int end_indexes[] = {orc.get_size()+1, orc.get_size()+1000};
   N = sizeof(end_indexes)/sizeof(int);
   for (int i = 0; i < N; i++) {
    int caught = 0;
    try {
        cut.remove(0, end_indexes[i]);
    } catch (dynamic_array::exception) {
        caught = 1;
    }
    if (!caught) {
        cout << "remove(int,int): uncaught index range exception at: ";
        cout << end_indexes[i] << "," << orc.get_size() << endl;
        return 0;
    }
   }

   // special case: 0 <= end < start < size
   int caught = 0;
   try {
    cut.remove(1, 0);
   } catch (dynamic_array::exception) {
    caught = 1;
   }
   if (!caught) {
    cout << "remove(int,int): uncaught index range exception at: 1,0" << endl;
    return 0;
  }
  }

  return 1; // no failures detected
  }

   int compare_content(dynamic_array &cut, oracle &orc) {
  // check size
  if (cut.get_size() != orc.get_size()) {
    cout << "ERROR. ";
    cout << "size. cut: " << cut.get_size();
    cout << " orc:" << orc.get_size() << endl;

    print_state(cut, orc);
    return 0;
   }

   // check get_allocated_size
   if (cut.get_allocated_size() != orc.get_allocated_size()) {
    cout << "ERROR. ";
    cout << "allocated_size. cut:" << cut.get_allocated_size();
    cout << " orc:" << orc.get_allocated_size() << endl;

    print_state(cut, orc);
    return 0;
   }

  // check operator[] and operator[] const
  for (int i = 0; i < orc.get_size(); i++) {
    if (cut[i] != orc[i]) {
        cout << "ERROR. ";
        cout << "cut[" << i << "]:" << cut[i];
        cout << " orc[" << i << "]:" << orc[i] << endl;

        print_state(cut, orc);
        return 0;
    }

    int x = const_f(cut, i);
    if (x != orc[i]) {
        cout << "ERROR. ";
        cout << "cut[" << i << "]:" << cut[i];
        cout << " orc[" << i << "]:" << x << endl;

        print_state(cut, orc);
        return 0;
    }
   }

  return 1;
   }

void run_tests(dynamic_array &cut, oracle &orc) {
compare_content(cut, orc);
compare_exceptions(cut, orc);

cut.insert(1, 0);
orc.insert(1, 0);

compare_content(cut, orc);
compare_exceptions(cut, orc);

 }

int main() {
 dynamic_array cut;
 generate_cut(cut, 0, 2, 5);

 oracle orc;
 generate_oracle(orc, 0, 2, 5);

 run_tests(cut, orc);
 }

在这种情况下,您的问题是您正在尝试链接 Linux ELF 二进制文件,如其输出的标头的十六进制转储所证明的那样(0x45 0x4C 0x46 = ELF).

根据您可用的资源,可能的解决方案:

  1. 使用与编译目标文件相同的平台(在本例中为您的解决方案)。
  2. 获取适合您平台的目标文件(对于 OS X,您需要一个与您的架构相匹配的 Mach-O,在您的情况下为 x86_64)。
  3. 获取目标文件的源代码,并针对您的平台进行编译。
  4. 反汇编,根据需要转换汇编,然后汇编一个新的二进制文件(可能不可行,除非它非常小并且实现未知)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

文件是为不受支持的文件格式构建的? 的相关文章

  • 中间件 API 的最佳实践是什么? [关闭]

    Closed 此问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我们正在开发一个中间件 SDK 采用 C 和 Java 语言 供游戏开发人员 动画软件开发人员 阿凡达开
  • AspNet vNext 上的 Kestrel 不提供 / 下的索引页面

    我需要能够在默认网址下提供我的 index html 使用 Kestrel Web 服务器 现在我只能使用完整路径访问我的静态文件 即 index html 同样 这在 VisualStudio 上完美运行 上下文是带有 Kestrel 的
  • C++ 模板中的名称查找

    我有一些 C 代码 如果没有 fpermissive 选项 就无法再编译 这是我无法分享的专有代码 但我认为我已经能够提取一个简单的测试用例来演示该问题 这是 g 的输出 template eg cpp In instantiation o
  • 基于 MS Bot Framework 中的响应分支对话框/表单

    我们正在尝试使用 MS Bot Framework 但尚未完全弄清楚如何实现此场景 我们有一个 LUIS 对话框 类型 它工作正常并且经过适当的培训 以常见的三明治为例 LUIS 意图寻找的基本内容是用户询问订单状态 如果问题中提供了订单号
  • Swift 5 MacOS 图像调整大小内存问题

    我是使用 Swift 进行 Mac OS 应用程序开发的新手 但我尝试制作简单的 ImageResizer 应用程序 我必须调整 50k 图像的大小 10个小时后 内存已增加到近120GB 我以为 Swift 也有垃圾收集器 为什么它可以增
  • 将列表(对象)转换为列表(字符串)

    有没有办法转换List of Object to a List of String 在 c 或 vb net 中而不迭代所有项目 幕后迭代很好 我只想要简洁的代码 Update 最好的方法可能就是进行新的选择 myList Select f
  • 返回指向 std::vector 中的对象的 a

    我有一个关于返回对向量元素的引用的非常基本的问题 有一个向量vec存储类的实例Foo 我想访问这个向量中的一个元素 不想使用向量索引 我应该如何编码该方法getFoo here include
  • C++ 私有静态成员变量

    此 C 代码在编译时产生链接器错误 A h class A public static void f private static std vector
  • C++ 中的 Java ArrayList [重复]

    这个问题在这里已经有答案了 在Java中我可以做 List
  • 如何防止字符串被截留

    我的理解 可能是错误的 是 在 C 中 当你创建一个字符串时 它会被实习到 实习生池 中 这保留了对字符串的引用 以便多个相同的字符串可以共享操作内存 但是 我正在处理很多很可能是唯一的字符串 一旦完成每个字符串 我需要将它们从操作内存中完
  • 获取给定EntityType的导航属性

    我在用VS2010 EF4 0 需要如下功能 private string GetNaviProps Type entityType eg typeof Employee NorthwindEntities en new Northwind
  • 简单的文档管理系统和API [关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • 为什么C++变量是指针时不需要正确定义?

    我对 C 语言完全陌生 特别是指针 经验主要是 PHP 并且希望对以下内容进行一些解释 我已经尝试寻找答案 这两行代码如何能够在我的程序中完成完全相同的工作 第二行似乎违背了我迄今为止所学到和理解的关于指针的一切 char disk 3 D
  • System.diagnostics.process 进程在托管后无法在 IIS 上运行?

    我正在尝试从网络应用程序安装 exe 当我在本地运行应用程序 从 asp 开发服务器 时 它安装正确 但当我托管在 IIS 上时 它不起作用 我在asp net页面的Page load方法上编写了这段代码 想要在客户端计算机上安装Test
  • 如何使用 libpq 获取双精度值?

    The examples http www postgresql org docs 9 3 interactive libpq example htmllibpq 文档中展示了如何通过将整数值转换为主机字节序表示来获取整数值 我很好奇必须做
  • C 中的 N 依赖注入 - 比链接器定义的数组更好的方法?

    Given a 库模块 在下文中称为Runner 它作为可重复使用的组件 无需重新编译 即静态链接库 中应用程序分区架构的 而不是主分区 请注意 它仅包含main 出于演示目的 Given a set 顺序无关 调用的其他模块 对象Call
  • win32 API 和 .NET 框架之间的选择

    我必须开发一个适用于 Windows 的应用程序 该应用程序将能够通过网络摄像头识别手势来控制鼠标 我将使用 vc 2008 进行开发 但我很困惑是使用 NET 框架还是核心 win32 API 性能对于我的应用程序非常重要 根据 Ivor
  • double 类型的静态类成员的常量表达式初始值设定项

    在 C 11 和 C 14 中 为什么我需要constexpr在下面的代码片段中 class Foo static constexpr double X 0 75 而这会产生编译器错误 class Foo static const doub
  • 如何向 ItemsControl 中的 WPF 按钮添加相同的命令

    如何将命令添加到 wpf 按钮 该按钮是ItemsControl并正在修改ItemsSource itself 这是我的 XAML
  • 什么时候使用静态库需要头文件?

    如果我在 Linux 中用 C 创建一个静态库并生成 a 文件 我 或其他人 如何使用该库 例如 我的库定义了一个类 我认为仅仅提供 a 文件是不够的 还需要提供头文件 我如何知道 a 文件必须提供哪些头文件 例如 我是否需要提供我的库代码

随机推荐