无法让我的c++使用编译器将文件放入库中
我正在尝试将源代码编译到库中,但出现此错误
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用用于编译目标文件的相同工具链来创建库,例如,如果您使用arm-none-eabi-gcc< /em> 进行编译,使用 arm-none-eabi-ar 进行存档。
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.