gpt4 book ai didi

c++ - 无法使用编译器将我的 C++ 文件制作成库

转载 作者:搜寻专家 更新时间:2023-10-31 01:54:46 25 4
gpt4 key购买 nike

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

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)

创建了 .a 文件,但随后我尝试将其与可执行文件链接,但出现此错误

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

最佳答案

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

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

关于c++ - 无法使用编译器将我的 C++ 文件制作成库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9205851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com