简体   繁体   English

如何在arduino ide中修复“未定义的引用:”,尝试使用googletest

[英]How to fix “undefined reference to:” in arduino ide, trying to use googletest

I am trying to use the googletest library to test code in the arduino ide, and I keep getting errors such as 我正在尝试使用googletest库在arduino ide中测试代码,并且不断出现诸如以下的错误

In function __static_initialization_and_destruction_0' undefined reference to `std::ios_base::Init::Init()' 在函数__static_initialization_and_destruction_0'中,未定义对`std :: ios_base :: Init :: Init()'的引用

There are 50 more lines of this error, including 此错误还有50行,包括

undefined reference to testing::Test::SetUp()' undefined reference to testing::Test::TearDown() 未定义对test :: Test :: SetUp()的引用未定义对test :: Test :: TearDown()的引用

Since even the basic test functions are failing, I assume I made a mistake in where I put my library files, or perhaps I'm simply not including the correct files. 由于甚至基本的测试功能都失败了,因此我认为我在放置库文件的位置上犯了一个错误,或者也许我只是没有包含正确的文件。

Currently I am only including gtest/gtest.h , as that is all I have seen in other examples in order for the code to work. 目前,我仅包含gtest/gtest.h ,这是我在其他示例中看到的所有内容,以便代码可以正常工作。

I have built the googletest library using cmake and make, and included it within the project. 我已经使用cmake和make构建了googletest库,并将其包含在项目中。

Does anyone have an idea of what I can do to fix this? 有谁知道我该怎么做才能解决这个问题?

Google test has been used on a variety of platforms: Google测试已在多种平台上使用:

  • Linux 的Linux
  • Mac OS X Mac OS X
  • Windows 视窗
  • Cygwin 西格温
  • MinGW 最小GW
  • Windows Mobile Windows Mobile
  • Symbian 塞班
  • PlatformIO PlatformIO

No Arduino, no Microcontroller 没有Arduino,没有微控制器

You can't compile googletest in the Arduino IDE. 您无法在Arduino IDE中编译googletest。 Primarily because the compiler used by the Arduino IDE is meant to generate (for normal arduinos) AVR binaries not x86 / x86-64 ones. 主要是因为Arduino IDE使用的编译器旨在生成(对于普通arduinos) AVR二进制文件,而不是x86 / x86-64二进制文件。 These AVR binaries can't be ran on a normal PC and are only meant to be ran on the embedded platform. 这些AVR二进制文件不能在普通PC上运行,而只能在嵌入式平台上运行。 Because on the embedded platform the normal standard text IO streams are not available the arduino IDE doesn't include the standard IO used on normal PC's for terminal use. 因为在嵌入式平台上无法使用常规的标准文本IO流,所以arduino IDE不包括在普通PC上用于终端使用的标准IO。 (aka pipes 0 1 2 on unix). (也就是Unix上的管道0 1 2)。

I have built the googletest library using cmake and make, and included it within the project. 我已经使用cmake和make构建了googletest库,并将其包含在项目中。

It is correct that this isn't going to work. 没错,这是正确的。 If you compile googletest with cmake/make you are probably building a x86 or x86-64 binary which you are then including in the arduino IDE. 如果使用cmake / make编译googletest,则可能是在构建x86x86-64二进制文件,然后将其包含在arduino IDE中。 The arduino IDE compiler is then going to try to link an AVR binary to a x86 / x86-64 library. 然后,arduino IDE编译器将尝试将AVR二进制文件链接到x86 / x86-64库。 This is not going to work. 这是行不通的。

I would recommend you design your software in such a way that the hardware dependent logic is removed from your business logic if you do want to test your Arduino code with googletest. 如果您要使用googletest测试Arduino代码,我建议您以一种将与硬件相关的逻辑从业务逻辑中删除的方式设计软件。 The business logic can then be unit tested by compiling a ('normal') x86 or x86-64 binary with the test code which can be ran on a normal pc. 然后,可以通过使用可以在普通PC上运行的测试代码编译(“普通”) x86x86-64二进制文件来对业务逻辑进行单元测试。 This will involve mocking up the hardware interfaces used in your code. 这将涉及模拟代码中使用的硬件接口。 This build infrastructure can easily be set up inside the same structure of your arduino project and testing will only involve building a test binary and running that. 可以轻松地在arduino项目的相同结构内建立此构建基础结构,而测试仅涉及构建测试二进制文件并运行它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM