ithewei / libhv

🔥 比libevent/libuv/asio更易用的网络库。A c/c++ network library for developing TCP/UDP/SSL/HTTP/WebSocket/MQTT client/server.

Home Page:https://github.com/ithewei/libhv/wiki

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to #include "TcpClient.h" in my project with bazel?

hlqqlm opened this issue · comments

My project use libhv with bazel. #include "hloop.h" is ok, but #include "TcpClient.h" failed, I also tried #include "evpp/TcpClient.h".

My prject bazel scripts are:

  1. WORKSPACE:
git_repository(
        name = "libhv",
        commit = "a4e51af3ca94eebb311dca2a03514e191d2ca318",
        remote = "https://gitee.com/libhv/libhv",
        )
  1. src/BUILD:
cc_binary(
        name = "my_project",
        srcs = glob(["*.cc", "*.h"]),
        includes = ["./"],
        deps = [
                "@libhv//:hv",
                ],
        )
  1. main.cc:
#include "hloop.h"			<--- ok
#include "hsocket.h"		<--- ok
...
#include "TcpClient.h"		<--- failed
#include "evpp/TcpClient.h"	<--- failed

bazel我不熟悉,@Edward-Elric233 cc

Sorry for the late reply, I didn't see the notification over the weekend.
To use TcpClient.h in Bazel, you don't need the evpp prefix. The reason it couldn't find the corresponding header file is because the corresponding option is not set. You need to enable the with_evpp option to compile the evpp related source code.

For simplicity, you can refer to the .bazelrc in a demo project I wrote (https://github.com/Edward-Elric233/libhv-bazel-test), add this .bazelrc to the project root directory, and compile again, which should solve the problem.

As I understand it, Bazel seems to be unable to use the .bazelrc file of an external project in order to avoid configuration pollution.

If you have any other questions, feel free to discuss with me.

Thanks! Add .bazelrc to my project root directory, everything goes ok.