我使用 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/
中的那个。
答案 0 :(得分:2)
我想知道你在做什么我错过了,因为这适合我:
$ 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