Can't make my c++ file into a library with compiler

风格不统一 提交于 2021-01-27 23:35:44

问题


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;
}
};

回答1:


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.



来源:https://stackoverflow.com/questions/9205851/cant-make-my-c-file-into-a-library-with-compiler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!