尝试在 Win7 64 位上的 Qt Creator 中运行以下代码。
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
int main() {
using namespace boost::posix_time;
ptime t = microsec_clock::universal_time();
std::cout << to_iso_extended_string(t) << "Z\n";
}
这是我的 *.pro 文件:
INCLUDEPATH += "C:\Program Files (x86)\boost\boost_1_47"
CONFIG += boost
LIBS += -L"C:\Program Files (x86)\boost\boost_1_47\lib"
LIBS += -lboost_date_time-vc71-mt-1_47
我收到以下错误:
c:\Program Files (x86)\boost\boost_1_47\boost\date_time\date_formatting.hpp:49: error: undefined reference to `boost::gregorian::greg_month::as_long_string() const'
c:\Program Files (x86)\boost\boost_1_47\boost\date_time\date_formatting.hpp:44: error: undefined reference to `boost::gregorian::greg_month::as_short_string() const'
我怎样才能让它发挥作用?我读到我需要构建日期时间库,但我不确定如何做到这一点。
最佳答案
这些 boost 库二进制文件是使用 Visual C++ 编译器编译的(您可以通过文件名中的“vc71”来猜测),但是您将 QtCreator 与 MinGW 编译器一起使用,并且不能混合使用以下编译器编译的 C++ 库不同的编译器(只有库的 C 部分可用)。
您可以继续使用 MinGW 并自行重新编译 boost *,或者在项目配置中更改 QtCreator 使用的编译器(假设您已安装任何版本的 Visual C++ 以及该编译器的 Qt 二进制文件)。
* :由于 MinGW 可以配置许多不同的不兼容选项,因此重新编译 boost 比使用预编译的二进制文件更安全,除非您确定它们是使用 Qt SDK 中包含的相同 MinGW 构建的。
关于Qt 创建者 : undefined reference to `boost::gregorian::greg_month::as_short_string() const' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9558972/