PlatformIO:未定义的引用

时间:2019-05-07 16:37:03

标签: c++ arduino arduino-uno platformio

我不认为这个问题是重复的: What is an undefined reference/unresolved external symbol error and how do I fix it? 由于此链接器错误与该特定的PlatformIO环境高度相关。

在Visual代码中使用PlatformIO时出现链接器错误。

错误消息:

在函数中,全局构造函数的关键是65535_0_main.cpp.o.2139':

:(。text.startup + 0x92):undefined reference to VoltSensor::VoltSensor()

:(。text.startup + 0x9a):undefined reference to AmpSensor::AmpSensor()

这是我的main.cpp:

VoltSensor voltSensor_panel   = VoltSensor(voltSensor_panel_pin);
AmpSensor ampSensor_panel     = AmpSensor(ampSensor_panel_pin);

Rule_basic basic_rule = Rule_basic(voltSensor_panel, ampSensor_panel); // here I got undefined reference as linker errors

这是rule_basic.hpp的代码:

#ifndef RULE_BASIC_HPP
#define RULE_BASIC_HPP

#include <voltSensor.hpp>
#include <ampSensor.hpp>

class Rule_basic
{
private:
    VoltSensor voltSensor;
    AmpSensor ampSensor;

public:
    Rule_basic();
    Rule_basic(VoltSensor, AmpSensor);

    int run();

};

#endif

这是rule_basic.cpp的代码:

#include <rule_basic.hpp>
#include <voltSensor.hpp>
#include <ampSensor.hpp>

// Rule_basic constructor
Rule_basic::Rule_basic(VoltSensor _voltsensor, AmpSensor _ampSensor)
{
    voltSensor = _voltsensor;
    ampSensor = _ampSensor;
}


// Rule_basic member function
int Rule_basic::run()
{
    int t_currentVolt = voltSensor.getVolt();
    int t_currentAmp  = ampSensor.getAmp();    

    int power = t_currentVolt * t_currentAmp;

    return power;
}

这是platformio.ini:

[env:uno]
platform = atmelavr
board = uno
framework = arduino
lib_ldf_mode = deep+
build_flags = -std=c++11

我看到存在链接问题。 根据PlaformIO文档:

http://docs.platformio.org/en/latest/librarymanager/ldf.html#ldf

在这种情况下,如果我有一个依赖于另一个库的cpp文件: rule_basic.cpp取决于ampSensor.hpp和voltSensor.hpp

我将使用lib_ldf_mode = deep+ 那么ldf将自动满足依赖关系。

但是不知为什么,或者我在Rule_basic类的构造函数中犯了一个错误

我的文件夹结构遵循默认的platformIO结构: http://docs.platformio.org/en/latest/projectconf/section_platformio.html#projectconf-pio-src-dir

|--lib
|  |--sensors
|  |     |- voltSensor.cpp
|  |     |- voltSensor.hpp
|  |     |- ampSensor.cpp
|  |     |- ampSensor.hpp
|  |--rules
|  |  |- rule_basic.cpp
|  |  |- rule_basic.hpp
|- platformio.ini
|--src
   |- main.cpp

回购可以在这里找到: https://bitbucket.org/pei2bp/mppt/src/develop/

你能帮我吗?

0 个答案:

没有答案