【发布时间】:2018-02-01 17:55:39
【问题描述】:
我有一个简单的 C++ 程序,我使用 Boost 库和 C++14 支持通过 clang 编译它。
我使用以下命令编译我的 sample.cpp 文件,它工作正常:
clang++ -g -std=c++1y -I$BOOST_ROOT sample.cpp -o sample
其中 $BOOST_ROOT 是我下载并解压 boost zip 文件的路径。
$BOOST_ROOT=/usr/local/boost_1_66_0/
当我尝试使用 makefile 编译相同的 sample.cpp 文件时,它不起作用。
这就是我的 makefile 的样子:
sample: sample.cpp
clang++ -g -std=c++1y -I$BOOST_ROOT sample.cpp -o sample
运行 make 命令,我得到错误:
Sample.cpp:9:10: fatal error: 'boost/format.hpp' file not found
#include <boost/format.hpp>
^~~~~~~~~~~~~~~~~~
1 error generated.
这里是sample.cpp
//
// sample.cpp
//
//
#include <iostream>
#include <boost/format.hpp>
using namespace std;
int main()
{
std::cout << "Enter your first name: " << std::endl;
std::string firstName;
std::cin >> firstName;
std::cout << "Enter your surname: " << std::endl;
std::string surname;
std::cin >> surname;
auto formattedName = str( boost::format("%1% %2%"s) % firstName % surname );
std::cout << "You said your name is: " << formattedName << std::endl;
return 0;
}
控制台输出
MacBook-Air:Listing_1_7 userd43f$ make
c++ sample.cpp -o sample
sample.cpp:9:10: fatal error: 'boost/format.hpp' file not found
#include <boost/format.hpp>
^~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [sample] Error 1
MacBook-Air:Listing_1_7 userd43f$ ls $BOOST_ROOT
INSTALL boost boost.png bootstrap.sh index.html rst.css
Jamroot boost-build.jam boostcpp.jam doc libs status
LICENSE_1_0.txt boost.css bootstrap.bat index.htm more tools
【问题讨论】:
-
make 中的变量是这样展开的
$(VARNAME). -
带或不带括号没有区别。我试过了,结果是一样的
-
为什么人们拒绝投票这个有效的问题?太荒谬了
-
因为你使用了'using namespace std'。有些人真的很挑剔,即使它根本不关心问题。
-
看起来它根本没有使用您的
sample规则,因为make输出中缺少-g -std=c++1y -I${BOOST_ROOT}选项。
标签: c++ boost makefile clang clang++