簡體   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