Qt 创建者 : undefined reference to `boost::gregorian::greg_month::as_short_string() const'

标签 qt boost

尝试在 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/

相关文章:

c++ - 来自 boost::asio::async_write 的 WriteHandler 在连接断开时无法正常工作(防火墙/手动断开网络连接)

c++ - 使用 boost::assign::list_of

C++/Qt - 析构函数中出现异常 -> 已调用中止

c++ - 我的数据结构的最佳序列化方法?

c++ - Qt 中的正则表达式

c++ - C++ 中线程计数的静态类变量

c++ - boost range for_each、bind、copy 和 back_inserter 的组合失败

java - 为什么在 JNI 中调用纤程会在 JVM 中引发 StackOverflow?

c++ - Qt 中信号槽的层次结构太深

c++ - 可变Qt Canvas 的最佳方式