1

fuchsia/examples/intl/tz_version_parrot/main.cc使用fxl::CommandLineFromArgcArgv()

#include "src/lib/fxl/command_line.h"
...
int main(int argc, const char** argv) {
  const auto command_line = fxl::CommandLineFromArgcArgv(argc, argv);

Fuchsia > Guides > fx 工作流程展示了使用fx set --with

$ fx set workstation.x64 --with //bundles:tests

我修改了 hello world 示例以使用fxl::CommandLineFromArgcArgv()

~/fuchsia$ cat examples/hello_world/cpp/hello_world.cc 
#include <iostream>
#include "src/lib/fxl/command_line.h"

int main(int argc_a, char** argv_a) {
    auto command_line = fxl::CommandLineFromArgcArgv(argc_a, argv_a);
    std::cout << "hello has_argv0():" << command_line.has_argv0() << "\n";
    return 0;
}
~/fuchsia$ fx set bringup.x64 --with //examples/hello_world
ERROR at //examples/hello_world/cpp/hello_world.cc:2:11: Include not allowed.
#include "src/lib/fxl/command_line.h"
          ^-------------------------
It is not in any dependency of                                                                                           
  //examples/hello_world/cpp:bin
The include file is in the target(s):
  //src/lib/fxl:fxl
which should somehow be reachable.

这会产生错误。原来的作品很好:

~/fuchsia$ cat examples/hello_world/cpp/hello_world.cc 
#include <iostream>
//#include "src/lib/fxl/command_line.h"

int main(int argc_a, char** argv_a) {
//    auto command_line = fxl::CommandLineFromArgcArgv(argc_a, argv_a);
//    std::cout << "hello has_argv0():" << command_line.has_argv0() << "\n";
    return 0;
}
~/fuchsia$ fx set bringup.x64 --with //examples/hello_world
Generating JSON projects took 3090ms
Generating compile_commands took 219ms
Done. Made 26946 targets from 2635 files in 16354ms

什么不见​​了?

4

1 回答 1

1

在中,使用依赖./examples/hello_world/cpp/BUILD.gn项扩展hello_world_cpp模块声明:fxl

executable("bin") {
  output_name = "hello_world_cpp"

  sources = [ "hello_world.cc" ]

  deps = [ "//src/lib/fxl" ] # Add this line
}
cd fuchsia
fx set bringup.x64 --with //examples/hello_world
fx build; fx qemu
...
hello_world_cpp
hello has_argv0():1

参考:在其他使用fxl链接)的 Fuchsia 组件中也是如此。

于 2020-04-19T14:16:41.383 回答