【发布时间】:2016-08-22 15:55:36
【问题描述】:
我使用 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,但目前我只使用QuickStart 教程来获得一个无需启用 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 OS,但您链接的文档是针对 mbed Classic 的,这不是一回事。 I don't see any
init()member here(不在超类中)。 -
@Notlikethat,有什么区别?在问题末尾的最后一个
find命令中,有两个结果:libraries中的第一个是与文档here 对应的源,而features中的后者与您链接的源相同在您的评论中。如果我在源代码中包含“EthernetInterface.h”,它似乎包含后者而不是前者(它具有更多功能,如init等)。 -
“本文档涵盖了可用于 mbed 2 的网络库。对于 mbed 5,网络库已经过修订,以更好地支持额外的网络堆栈和线程安全here。” - 据我了解,mbed Classic(第 2 版)基本上只是一组 HAL 库,而 mbed OS(第 5 版)是一个成熟的以连接为中心的 RTOS,两者之间存在显着的源级不兼容.不过,我不能说我自己曾经真正使用过。
-
@Notlikethat,感谢您的链接!鉴于此,我想要做的是链接到 mbed 5 而不是 mbed 2 的 EthernetInterface.cpp 源。由于某种原因,后者似乎是默认情况。
标签: c++ gcc compilation arm mbed