首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用mbed中的可用库?

如何使用mbed中的可用库?
EN

Stack Overflow用户
提问于 2016-08-22 15:55:36
回答 1查看 1.7K关注 0票数 1

我已经使用mbed工具下载了一份新的mbed副本。

代码语言:javascript
复制
$ 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"

最终,我的工作是在我的NXPFRDM-K64F设备上启用uVisor,但目前我只使用QuickStart教程来获得一个简单的示例,而不启用uVisor。

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

代码语言:javascript
复制
$ mkdir mbed-os-test/mbed-os/source

我复制基本的main.cpp并编译。它起作用了。但是,当我尝试使用一些库例程--特别是EthernetInterface --来创建一个问题时。

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

代码语言:javascript
复制
#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类没有我试图调用的成员。

代码语言:javascript
复制
../../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/

代码语言:javascript
复制
[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中,我只是不确定如何实际使用它们。

代码语言:javascript
复制
$ find . -name EthernetInterface.cpp
./libraries/net/eth/EthernetInterface/EthernetInterface.cpp
./features/net/FEATURE_IPV4/lwip-interface/EthernetInterface.cpp

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

EN

回答 1

Stack Overflow用户

发布于 2016-08-23 14:35:48

我想知道你在做什么,我错过了,因为这对我有用:

代码语言:javascript
复制
$ mbed new ethernet-test
$ cd ethernet-test
$ mbed target K64F
$ mbed toolchain GCC_ARM

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

代码语言:javascript
复制
#include "mbed.h"
#include "EthernetInterface.h"

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

然后:

代码语言:javascript
复制
$ mbed compile
...
Total Flash memory (text + data + misc): 108092 bytes
Image: ./.build/K64F/GCC_ARM/ethernet-test.bin
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39083899

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档