无法让我的c++使用编译器将文件放入库中

发布于 2025-01-04 01:16:20 字数 1087 浏览 0 评论 0原文

我正在尝试将源代码编译到库中,但出现此错误

findingjimoh$ ar rcs libHeatingUnit.a HeatingUnit.o
/usr/bin/ranlib: warning for library: libHeatingUnit.a the table of contents is empty (no object file members in the library define global symbols)

The .a file is made 但随后我尝试将其与可执行文件链接,但出现此错误

findingjimoh$ g++ -o TemperatureControl BangBangControl.cpp -L. libBangBangControl.a libHeatingUnit.a 
ld: warning: ignoring file libHeatingUnit.a, file was built for archive which is not the architecture being linked (x86_64)

这是我的源代码

 // Jimoh Ovbiagele (JAO945)

 #include <stdio.h>
 #include <stdbool.h>

 class HeatingUnit {
   private:
bool isOn;
int temp;

   public:
/* Sets the unit's status and initial temp */
HeatingUnit(bool isOn, int temp){
  this -> isOn = isOn;
  this -> temp = temp;
}

HeatingUnit(){

}

/* Turns unit on */
void turnOn(){
  isOn = true;
}

/* Turns unit off */
void turnOff(){
  isOn = false;
}

int tick(){
  if(isOn) temp++;
  else temp--;      
  return temp;
}
};

I am trying to compile my source code into a library but i get this error

findingjimoh$ ar rcs libHeatingUnit.a HeatingUnit.o
/usr/bin/ranlib: warning for library: libHeatingUnit.a the table of contents is empty (no object file members in the library define global symbols)

The .a file is made but then i try to link it with an executable file and i get this error

findingjimoh$ g++ -o TemperatureControl BangBangControl.cpp -L. libBangBangControl.a libHeatingUnit.a 
ld: warning: ignoring file libHeatingUnit.a, file was built for archive which is not the architecture being linked (x86_64)

Here is my source

 // Jimoh Ovbiagele (JAO945)

 #include <stdio.h>
 #include <stdbool.h>

 class HeatingUnit {
   private:
bool isOn;
int temp;

   public:
/* Sets the unit's status and initial temp */
HeatingUnit(bool isOn, int temp){
  this -> isOn = isOn;
  this -> temp = temp;
}

HeatingUnit(){

}

/* Turns unit on */
void turnOn(){
  isOn = true;
}

/* Turns unit off */
void turnOff(){
  isOn = false;
}

int tick(){
  if(isOn) temp++;
  else temp--;      
  return temp;
}
};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

廻憶裏菂餘溫 2025-01-11 01:16:20

文件是为存档而构建的,不是正在链接的架构(x86_64)

您应该使用用于编译目标文件的相同工具链来创建库,例如,如果您使用arm-none-eabi-gcc< /em> 进行编译,使用 arm-none-eabi-ar 进行存档。

file was built for archive which is not the architecture being linked (x86_64)

You should use the same toolchain you used to compile the object file to create the library, for example, if you used arm-none-eabi-gcc to compile use arm-none-eabi-ar to archive.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文