C++ Make 文件 - 不能包含 Thrift 库

发布于 2025-01-17 05:02:52 字数 1537 浏览 3 评论 0原文

我正在尝试编译我的示例 Thrift(客户端-服务器)程序。我已将 Thrift 安装在路径 $HOME/thrift/lib 中,但我无法解决编译器给出错误的原因,即无法包含 thrift 包含内容。我的 make 文件如下所示:

all: client server

# Generate source files from Thrift IDL
gen-cpp/Example.cpp: Example.thrift
    thrift --gen cpp Example.thrift

# Compile server from main source and generated sources
server: server.cpp gen-cpp/Example.cpp
    g++ --std=c++17 -L$HOME/thrift/lib -Igen-cpp:$HOME/thrift/include/thrift -o server server.cpp gen-cpp/Example.cpp -lthrift

# Compile client from main source and generated sources
client: client.cpp gen-cpp/Example.cpp
    g++ --std=c++17 -L$HOME/thrift/lib -Igen-cpp:$HOME/thrift/include/thrift -o client client.cpp gen-cpp/Example.cpp -lthrift

clean:
    rm -f client
    rm -f server
    rm -rf gen-cpp


.PHONY: all clean

运行 make 命令后,我得到如下结果:

g++ --std=c++17 -LOME/thrift/lib -Igen-cpp:OME/thrift/include/thrift -o client client.cpp gen-cpp/Example.cpp -lthrift
client.cpp:7:10: fatal error: thrift/protocol/TProtocol.h: No such file or directory
    7 | #include <thrift/protocol/TProtocol.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
In file included from gen-cpp/Example.cpp:7:
gen-cpp/Example.h:10:10: fatal error: thrift/TDispatchProcessor.h: No such file or directory
   10 | #include <thrift/TDispatchProcessor.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:13: client] Error 1

你看到我遗漏了什么或我做错了吗?感谢您的所有回复。

I am trying to compile my example Thrift (client-server) program. I've got Thrift installed in the path $HOME/thrift/lib, but I cannot resolve why the compiler is giving me errors, that cannot include thrift includes. My make file looks like this:

all: client server

# Generate source files from Thrift IDL
gen-cpp/Example.cpp: Example.thrift
    thrift --gen cpp Example.thrift

# Compile server from main source and generated sources
server: server.cpp gen-cpp/Example.cpp
    g++ --std=c++17 -L$HOME/thrift/lib -Igen-cpp:$HOME/thrift/include/thrift -o server server.cpp gen-cpp/Example.cpp -lthrift

# Compile client from main source and generated sources
client: client.cpp gen-cpp/Example.cpp
    g++ --std=c++17 -L$HOME/thrift/lib -Igen-cpp:$HOME/thrift/include/thrift -o client client.cpp gen-cpp/Example.cpp -lthrift

clean:
    rm -f client
    rm -f server
    rm -rf gen-cpp


.PHONY: all clean

After I run the make command I get results like this:

g++ --std=c++17 -LOME/thrift/lib -Igen-cpp:OME/thrift/include/thrift -o client client.cpp gen-cpp/Example.cpp -lthrift
client.cpp:7:10: fatal error: thrift/protocol/TProtocol.h: No such file or directory
    7 | #include <thrift/protocol/TProtocol.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
In file included from gen-cpp/Example.cpp:7:
gen-cpp/Example.h:10:10: fatal error: thrift/TDispatchProcessor.h: No such file or directory
   10 | #include <thrift/TDispatchProcessor.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:13: client] Error 1

Do you see something I'm missing or I'm doing wrong? Thank you for all your responses.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最终幸福 2025-01-24 05:02:52

如果您查看 make 在打印命令行时打印的输出,很明显有问题:

g++ --std=c++17 -LOME/thrift/lib -Igen-cpp:OME/thrift/include/thrift ...

What is -LOME/thrift/lib-Igen-cpp:OME/thrift /包括/节俭?这些不可能是正确的:这些目录不存在。所以,显然你的 makefile 和你正在使用的配方有问题:

g++ --std=c++17 -L$HOME/thrift/lib -Igen-cpp:$HOME/thrift/include/thrift ...

事实上,确实有问题。 $ 对于 make 来说是特殊的:它引入了 make 变量。如果您想使用 $ 以便将其传递到配方中的 shell,则必须通过加倍它来转义它:$$

如果您像这样重写您的配方:

g++ --std=c++17 -L$HOME/thrift/lib -Igen-cpp:$HOME/thrift/include/thrift ...

那么您将看到 make 将使用单个未转义的 $: 调用该命令,

g++ --std=c++17 -L$HOME/thrift/lib -Igen-cpp:$HOME/thrift/include/thrift ...

并且它将起作用。或者,您可以在此处使用 make 变量,但必须将其括在 (){} 中(它们是相同的):

g++ --std=c++17 -L$(HOME)/thrift/lib -Igen-cpp:$(HOME)/thrift/include/thrift ...

If you look at the output that make prints when it prints the command line, it's quite obvious there's something wrong:

g++ --std=c++17 -LOME/thrift/lib -Igen-cpp:OME/thrift/include/thrift ...

What is -LOME/thrift/lib and -Igen-cpp:OME/thrift/include/thrift? Those can't possibly be right: those directories don't exist. So, clearly there's something wrong in your makefile, with the recipe you're using:

g++ --std=c++17 -L$HOME/thrift/lib -Igen-cpp:$HOME/thrift/include/thrift ...

And indeed, there is. The $ is special to make: it introduces make variables. If you want to use $ so it's passed to the shell in your recipes, you have to escape it by doubling it: $$.

If you rewrite your recipe like this:

g++ --std=c++17 -L$HOME/thrift/lib -Igen-cpp:$HOME/thrift/include/thrift ...

then you'll see that make will invoke the command with the single unescaped $:

g++ --std=c++17 -L$HOME/thrift/lib -Igen-cpp:$HOME/thrift/include/thrift ...

and it will work. Alternatively, you could use the make variable here, but then you have to enclose it in () or {} (they are the same):

g++ --std=c++17 -L$(HOME)/thrift/lib -Igen-cpp:$(HOME)/thrift/include/thrift ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文