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

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(使用前将#替换为@)

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

  • 没有强命名的代码签名是否会让您的应用程序容易被滥用?

    尝试了解authenticode代码签名和强命名 我是否正确地认为 如果我对引用一些 dll 非强命名 的 exe 进行代码签名 恶意用户就可以替换我的 DLL 并以看似由我签名但正在运行的方式分发应用程序他们的代码 假设这是真的 那么您似
  • 我如何才能等待多个事情

    我正在使用 C 11 和 stl 线程编写一个线程安全队列 WaitAndPop 方法当前如下所示 我希望能够将一些内容传递给 WaitAndPop 来指示调用线程是否已被要求停止 如果 WaitAndPop 等待并返回队列的元素 则应返回
  • 为什么 C# Array.BinarySearch 这么快?

    我已经实施了一个很简单用于在整数数组中查找整数的 C 中的 binarySearch 实现 二分查找 static int binarySearch int arr int i int low 0 high arr Length 1 mid
  • WCF RIA 服务 - 加载多个实体

    我正在寻找一种模式来解决以下问题 我认为这很常见 我正在使用 WCF RIA 服务在初始加载时将多个实体返回给客户端 我希望两个实体异步加载 以免锁定 UI 并且我想利用 RIA 服务来执行此操作 我的解决方案如下 似乎有效 这种方法会遇到
  • ASP.NET MVC:这个业务逻辑应该放在哪里?

    我正在开发我的第一个真正的 MVC 应用程序 并尝试遵循一般的 OOP 最佳实践 我正在将控制器中的一些简单业务逻辑重构到我的域模型中 我最近一直在阅读一些内容 很明显我应该将逻辑放在域模型实体类中的某个位置 以避免出现 贫血域模型 反模式
  • 查找c中结构元素的偏移量

    struct a struct b int i float j x struct c int k float l y z 谁能解释一下如何找到偏移量int k这样我们就可以找到地址int i Use offsetof 找到从开始处的偏移量z
  • C#中如何移动PictureBox?

    我已经使用此代码来移动图片框pictureBox MouseMove event pictureBox Location new System Drawing Point e Location 但是当我尝试执行时 图片框闪烁并且无法识别确切
  • 带动态元素的 WPF 启动屏幕。如何?

    我是 WPF 新手 我需要一些帮助 我有一个加载缓慢的 WPF 应用程序 因此我显示启动屏幕作为权宜之计 但是 我希望能够在每次运行时更改屏幕 并在文本区域中显示不同的引言 这是一个生产力应用程序 所以我将使用非愚蠢但激励性的引言 当然 如
  • WCF 中 SOAP 消息的数字签名

    我在 4 0 中有一个 WCF 服务 我需要向 SOAP 响应添加数字签名 我不太确定实际上应该如何完成 我相信响应应该类似于下面的链接中显示的内容 https spaces internet2 edu display ISWG Signe
  • 显示UnityWebRequest的进度

    我正在尝试使用下载 assetbundle统一网络请求 https docs unity3d com ScriptReference Networking UnityWebRequest GetAssetBundle html并显示进度 根
  • 如何序列化/反序列化自定义数据集

    我有一个 winforms 应用程序 它使用强类型的自定义数据集来保存数据进行处理 它由数据库中的数据填充 我有一个用户控件 它接受任何自定义数据集并在数据网格中显示内容 这用于测试和调试 为了使控件可重用 我将自定义数据集视为普通的 Sy
  • 如何使用 C# / .Net 将文件列表从 AWS S3 下载到我的设备?

    我希望下载存储在 S3 中的多个图像 但目前如果我只能下载一个就足够了 我有对象路径的信息 当我运行以下代码时 出现此错误 遇到错误 消息 读取对象时 访问被拒绝 我首先做一个亚马逊S3客户端基于我的密钥和访问配置的对象连接到服务器 然后创
  • 对现有视频添加水印

    我正在寻找一种用 C 在视频上加水印的方法 就像在上面写文字一样 图片或文字标签 我该怎么做 谢谢 您可以使用 Nreco 视频转换器 代码看起来像 NReco VideoConverter FFMpegConverter wrap new
  • 为什么编译时浮点计算可能不会得到与运行时计算相同的结果?

    In the speaker mentioned Compile time floating point calculations might not have the same results as runtime calculation
  • 如何将带有 IP 地址的连接字符串放入 web.config 文件中?

    我们当前在 web config 文件中使用以下连接字符串 add name DBConnectionString connectionString Data Source ourServer Initial Catalog ourDB P
  • C# 成员变量继承

    我对 C 有点陌生 但我在编程方面有相当广泛的背景 我想做的事情 为游戏定义不同的 MapTiles 我已经像这样定义了 MapTile 基类 public class MapTile public Texture2D texture pu
  • 是否可以在 .NET Core 中将 gRPC 与 HTTP/1.1 结合使用?

    我有两个网络服务 gRPC 客户端和 gRPC 服务器 服务器是用 NET Core编写的 然而 客户端是托管在 IIS 8 5 上的 NET Framework 4 7 2 Web 应用程序 所以它只支持HTTP 1 1 https le
  • 哪种 C 数据类型可以表示 40 位二进制数?

    我需要表示一个40位的二进制数 应该使用哪种 C 数据类型来处理这个问题 如果您使用的是 C99 或 C11 兼容编译器 则使用int least64 t以获得最大的兼容性 或者 如果您想要无符号类型 uint least64 t 这些都定
  • Windows 和 Linux 上的线程

    我在互联网上看到过在 Windows 上使用 C 制作多线程应用程序的教程 以及在 Linux 上执行相同操作的其他教程 但不能同时用于两者 是否存在即使在 Linux 或 Windows 上编译也能工作的函数 您需要使用一个包含两者的实现
  • 如何在文本框中插入图像

    有没有办法在文本框中插入图像 我正在开发一个聊天应用程序 我想用图标图像更改值 等 但我找不到如何在文本框中插入图像 Thanks 如果您使用 RichTextBox 进行聊天 请查看Paste http msdn microsoft co

随机推荐