问题
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