如何在 arduino ide 中修复 "undefined reference to:",尝试使用 googletest
How to fix "undefined reference to:" in arduino ide, trying to use googletest
我正在尝试使用 googletest 库来测试 arduino ide 中的代码,但我不断收到诸如
之类的错误
In function __static_initialization_and_destruction_0' undefined
reference to `std::ios_base::Init::Init()'
这个错误还有50行,包括
undefined reference to testing::Test::SetUp()' undefined reference to
testing::Test::TearDown()
因为连基本的测试功能都失败了,我假设我在放库文件的地方犯了错误,或者我可能只是没有包含正确的文件。
目前我只包含 gtest/gtest.h
,因为这是我在其他示例中看到的所有代码才能正常工作。
我已经使用 cmake 和 make 构建了 googletest 库,并将其包含在项目中。
有没有人ide知道我可以做些什么来解决这个问题?
Google test has been used on a variety of platforms:
- Linux
- Mac OS X
- Windows
- Cygwin
- MinGW
- Windows Mobile
- Symbian
- PlatformIO
没有 Arduino,没有微控制器
您无法在 Arduino IDE 中编译 googletest。主要是因为 Arduino IDE 使用的编译器旨在生成(对于普通 arduino)AVR
二进制文件而不是 x86
/x86-64
二进制文件。这些 AVR
个二进制文件不能在普通 PC 上 运行,只能在嵌入式平台上 运行。因为在嵌入式平台上,普通的标准文本 IO 流不可用,所以 arduino IDE 不包括普通 PC 上用于终端使用的标准 IO。 (在 unix 上也称为管道 0 1 2)。
I have built the googletest library using cmake and make, and included it within the project.
这是行不通的,这是正确的。如果您使用 cmake/make 编译 googletest,您可能正在构建一个 x86
或 x86-64
二进制文件,然后将其包含在 arduino IDE 中。然后 arduino IDE 编译器将尝试 link 一个 AVR
二进制文件到 x86
/x86-64
库。这是行不通的。
如果你确实想用 googletest 测试你的 Arduino 代码,我建议你设计你的软件,从你的业务逻辑中删除依赖于硬件的逻辑。然后可以通过使用测试代码编译 ('normal') x86
或 x86-64
二进制文件来对业务逻辑进行单元测试,在普通 pc 上可以是 运行。这将涉及模拟代码中使用的硬件接口。这个构建基础设施可以很容易地在你的 arduino 项目的相同结构中设置,测试将只涉及构建一个测试二进制文件和 运行 那。
我正在尝试使用 googletest 库来测试 arduino ide 中的代码,但我不断收到诸如
之类的错误In function __static_initialization_and_destruction_0' undefined reference to `std::ios_base::Init::Init()'
这个错误还有50行,包括
undefined reference to testing::Test::SetUp()' undefined reference to testing::Test::TearDown()
因为连基本的测试功能都失败了,我假设我在放库文件的地方犯了错误,或者我可能只是没有包含正确的文件。
目前我只包含 gtest/gtest.h
,因为这是我在其他示例中看到的所有代码才能正常工作。
我已经使用 cmake 和 make 构建了 googletest 库,并将其包含在项目中。
有没有人ide知道我可以做些什么来解决这个问题?
Google test has been used on a variety of platforms:
- Linux
- Mac OS X
- Windows
- Cygwin
- MinGW
- Windows Mobile
- Symbian
- PlatformIO
没有 Arduino,没有微控制器
您无法在 Arduino IDE 中编译 googletest。主要是因为 Arduino IDE 使用的编译器旨在生成(对于普通 arduino)AVR
二进制文件而不是 x86
/x86-64
二进制文件。这些 AVR
个二进制文件不能在普通 PC 上 运行,只能在嵌入式平台上 运行。因为在嵌入式平台上,普通的标准文本 IO 流不可用,所以 arduino IDE 不包括普通 PC 上用于终端使用的标准 IO。 (在 unix 上也称为管道 0 1 2)。
I have built the googletest library using cmake and make, and included it within the project.
这是行不通的,这是正确的。如果您使用 cmake/make 编译 googletest,您可能正在构建一个 x86
或 x86-64
二进制文件,然后将其包含在 arduino IDE 中。然后 arduino IDE 编译器将尝试 link 一个 AVR
二进制文件到 x86
/x86-64
库。这是行不通的。
如果你确实想用 googletest 测试你的 Arduino 代码,我建议你设计你的软件,从你的业务逻辑中删除依赖于硬件的逻辑。然后可以通过使用测试代码编译 ('normal') x86
或 x86-64
二进制文件来对业务逻辑进行单元测试,在普通 pc 上可以是 运行。这将涉及模拟代码中使用的硬件接口。这个构建基础设施可以很容易地在你的 arduino 项目的相同结构中设置,测试将只涉及构建一个测试二进制文件和 运行 那。