C++ Make 文件 - 不能包含 Thrift 库
我正在尝试编译我的示例 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您查看 make 在打印命令行时打印的输出,很明显有问题:
What is
-LOME/thrift/lib
和-Igen-cpp:OME/thrift /包括/节俭?这些不可能是正确的:这些目录不存在。所以,显然你的 makefile 和你正在使用的配方有问题:
事实上,确实有问题。
$
对于 make 来说是特殊的:它引入了 make 变量。如果您想使用$
以便将其传递到配方中的 shell,则必须通过加倍它来转义它:$$
。如果您像这样重写您的配方:
那么您将看到 make 将使用单个未转义的
$
: 调用该命令,并且它将起作用。或者,您可以在此处使用 make 变量,但必须将其括在
()
或{}
中(它们是相同的):If you look at the output that make prints when it prints the command line, it's quite obvious there's something wrong:
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: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:
then you'll see that make will invoke the command with the single unescaped
$
: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):