C++ cpp的编译器标志/参数未知
我正在完成的教程。要编译一个示例,我应该使用以下行:C++ cpp的编译器标志/参数未知,c++,gcc,compiler-flags,C++,Gcc,Compiler Flags,我正在完成的教程。要编译一个示例,我应该使用以下行: c++ -O3 -shared -std=c++11 -I <path-to-pybind11>/include `python-config --cflags --ldflags` example.cpp -o example.so 它主要不是关于它的内容,而是关于:它在compile命令中有什么意义?它是否属于-I标志?那些“`”是什么意思 我查看了c++/cpp手册,但没有找到任何反引号 当在shell命令中看到反引号``
c++ -O3 -shared -std=c++11 -I <path-to-pybind11>/include `python-config --cflags --ldflags` example.cpp -o example.so
它主要不是关于它的内容,而是关于:它在compile命令中有什么意义?它是否属于-I
标志?那些“`”是什么意思
我查看了c++/cpp手册,但没有找到任何反引号
当在shell命令中看到反引号``之间的内容时,这意味着它是在主命令之前运行的一个单独的命令,它写入标准输出的任何内容都将在主命令中使用
例如:
rm `cat file_to_delete.txt`
考虑文件\u以\u delete.txt
包含“香肠.png”
首先运行cat文件\u to_delete.txt
部分并输出“香肠.png”
然后将其插入到主命令中,如下所示:
rm sausage.png
你的例子是什么
因此,在您的示例中,python config--cflags--ldflags
是一个独立于c++
的命令,它输出的任何内容都将替换为原始命令。如果它输出-Wall-Wextra-lmath
您的c++
命令将以如下方式结束:
c++ -O3 -shared -std=c++11 -I <path-to-pybind11>/include -Wall -Wextra -lmath example.cpp -o example.so
c++-O3-shared-std=c++11-I/include-Wall-Wextra-lmath example.cpp-o example.so
结论
>代码> Python配置文件< /C>命令,因此提供标志>代码> GCC < /C>(<代码> C++ > /COD>实际使用<代码> GCC < /C> >将需要用Python代码运行C++代码。
< P>什么 `python-config --cflags --ldflags`
执行命令“python config--cflags--ldflags”并替换输出(即编译命令的额外参数)
程序python config
为代码提供了必要的构建选项。
从python配置
文档:
python配置-python C/C的输出构建选项++
扩展还是嵌入
--cflags
打印C编译器标志
--ldflags
打印应传递给链接器的标志
提供这样的工具是一种常见的方法,这样可以自动找到特定is系统上必要的构建选项,否则需要用户自己确定
在我的Ubuntu 16.04系统上,python config--cflags--ldflag
生成:
-I/usr/include/python2.7-I/usr/include/x86_64-linux-gnu/python2.7-fno严格别名-Wdate time-D_FORTIFY_SOURCE=2-g-fstack protector strong-Wformat-Werror=格式安全性-DNDEBUG-g-fwrapv-O2-Wall-Wstrict原型
-L/usr/lib/python2.7/config-x86_64-linux-gnu-L/usr/lib-lpython2.7-lpthread-ldl-lutil-lm-Xlinker-export dynamic-Wl,-O1-Wl,-b符号函数
所以,这相当于我自己做这件事:
c++-O3-shared-std=c++11-I/include
-I/usr/include/python2.7-I/usr/include/x86_64-linux-gnu/python2.7-fno严格别名-Wdate time-D_FORTIFY_SOURCE=2-g-fstack protector strong-Wformat-Werror=格式安全性-DNDEBUG-g-fwrapv-O2-Wall-Wstrict原型
-L/usr/lib/python2.7/config-x86_64-linux-gnu-L/usr/lib-lpython2.7-lpthread-ldl-lutil-lm-Xlinker-export dynamic-Wl,-O1-Wl,-Bsymbolic functions example.cpp-o example.so
现在您可以了解为什么helper程序很方便(它可以找出需要哪些库以及它们位于何处等)
另一方面,我更喜欢
$(python-config--cflags--ldflags)
,而不是`python-config--cflags--ldflags`,因为POSIX建议使用$(..)
。您可以在此处的“命令替换”部分中看到
`python-config --cflags --ldflags`