繁体   English   中英

如何在mbed-os中使用可用的库?

[英]How to use available libraries from within mbed-os?

我已经使用mbed-cli工具拉下了mbed-os的新副本。

$ mbed new mbed-os-test
[mbed] Creating new program "mbed-os-test" (git)
[mbed] Adding library "mbed-os" from "https://github.com/ARMmbed/mbed-os" at latest revision in the current branch
[mbed] Updating reference "mbed-os" -> "https://github.com/ARMmbed/mbed-os/#dda7f7d77abd4330b05e686ce3bbe58230eb7876"

最终,我正在努力在NXP FRDM-K64F设备上启用uVisor,但是目前,我仅使用快速入门教程来获得一个简单的示例,而无需启用uVisor。

因此,如上面的链接所示,我在新创建的mbed-os克隆中创建了一个source目录:

$ mkdir mbed-os-test/mbed-os/source

我复制基本的main.cpp并进行编译。 有用。 但是,当我尝试使用某些库例程(特别是EthernetInterface)创建问题时。

将uVisor示例中的简单main.cpp替换为以上链接中的更复杂的示例(使用EthernetInterface):

#include "mbed.h"
#include "EthernetInterface.h"

int main() {
    EthernetInterface eth;
    eth.init(); //Use DHCP
    eth.connect();
    printf("IP Address is %s\n", eth.getIPAddress());

    TCPSocketConnection sock;
    sock.connect("mbed.org", 80);

    char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
    sock.send_all(http_cmd, sizeof(http_cmd)-1);

    char buffer[300];
    int ret;
    while (true) {
        ret = sock.receive(buffer, sizeof(buffer)-1);
        if (ret <= 0)
            break;
        buffer[ret] = '\0';
        printf("Received %d chars from server:\n%s\n", ret, buffer);
    }

    sock.close();

    eth.disconnect();

    while(1) {}
}

编译:

mbed compile -m K64F -t GCC_ARM

我遇到编译错误,指出EthernetInterface类没有我要调用的成员。

../../mbed-os/source/main.cpp: In function 'int main()':
../../mbed-os/source/main.cpp:34:9: error: 'class EthernetInterface' has no member named 'init'
     eth.init(); //Use DHCP
         ^
../../mbed-os/source/main.cpp:36:38: error: 'class EthernetInterface' has no member named 'getIPAddress'
     printf("IP Address is %s\n", eth.getIPAddress());
                                      ^
../../mbed-os/source/main.cpp:38:5: error: 'TCPSocketConnection' was not declared in this scope
     TCPSocketConnection sock;
     ^
../../mbed-os/source/main.cpp:39:5: error: 'sock' was not declared in this scope
     sock.connect("mbed.org", 80);
     ^

当然,当EthernetInterface类确实具有这样的成员时。 我认为问题与mbed实用程序未针对正确的源代码进行编译有关,因为它似乎找到了标头。 如果在mbed编译中添加--source=选项,则会遇到有关EthernetInterface.cpp所包含内容的其他错误。

mbed compile -m K64F -t GCC_ARM --source=../libraries/net/eth/EthernetInterface/

[ERROR] In file included from ../libraries/net/eth/EthernetInterface/EthernetInterface.cpp:19:0:
../libraries/net/eth/EthernetInterface/EthernetInterface.h:27:18: fatal error: rtos.h: No such file or directory

这些文件肯定包含在mbed-os中,我只是不确定如何实际使用它们。

$ find . -name EthernetInterface.cpp
./libraries/net/eth/EthernetInterface/EthernetInterface.cpp
./features/net/FEATURE_IPV4/lwip-interface/EthernetInterface.cpp

tl; dr-如何链接到libraries/给出的库代码? 我可以通过直接包含头文件来直接包含头文件,但是相应的源似乎是位于features/目录中的源文件,而不是位于libraries/

我想知道您在做什么,我想念的,因为这对我有用:

$ mbed new ethernet-test
$ cd ethernet-test
$ mbed target K64F
$ mbed toolchain GCC_ARM

打开ethernet-test/main.cpp并放入:

#include "mbed.h"
#include "EthernetInterface.h"

int main(int, char**) {
  EthernetInterface eth;
  eth.connect();
}

然后:

$ mbed compile
...
Total Flash memory (text + data + misc): 108092 bytes
Image: ./.build/K64F/GCC_ARM/ethernet-test.bin

暂无
暂无

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

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