Qt Creator在Mac上和提升库

时间:2014-04-17 13:47:46

标签: c++ qt boost qt-creator

我在Mac上运行QtCreator ...我想开始使用boost库...所以,我使用

安装了boost库
brew install boost

之后我创建了一个小型的提升世界程序并在.pro文件中进行了如下更改

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

unix:INCLUDEPATH += "/usr/local/Cellar/boost/1.55.0_1/include/"
unix:LIBPATH += "-L/usr/local/Cellar/boost/1.55.0_1/lib/"

SOURCES += main.cpp

LIBS += \
-lboost_date_time \
-lboost_filesystem \
-lboost_program_options \
-lboost_regex \
-lboost_signals \
-lboost_system

我仍无法建造......可能是什么原因?请建议我可能出现的错误......

错误是

library not found for -lboost_data_time
linker command failed with exit code 1 (use -v to see invocation)

2 个答案:

答案 0 :(得分:5)

这是Uflex的回答,因为他错过了一些东西。 所以保持相同的代码:

//make sure that there is a boost folder in your boost include directory
#include <boost/chrono.hpp>
#include <cmath>

int main()
{
auto start = boost::chrono::system_clock::now();

    for ( long i = 0; i < 10000000; ++i )
        std::sqrt( 123.456L ); // burn some time

    auto sec = boost::chrono::system_clock::now() - start;
    std::cout << "took " << sec.count() << " seconds" << std::endl;

    return 0;
}

但是让我们改变他的.pro:

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp

macx {
    QMAKE_CXXFLAGS += -std=c++11

    _BOOST_PATH = /usr/local/Cellar/boost/1.55.0_1
    INCLUDEPATH += "$${_BOOST_PATH}/include/"
    LIBS += -L$${_BOOST_PATH}/lib
    ## Use only one of these:
    LIBS += -lboost_chrono-mt -lboost_system # using dynamic lib (not sure if you need that "-mt" at the end or not)
    #LIBS += $${_BOOST_PATH}/lib/libboost_chrono-mt.a # using static lib
}

我唯一补充的是增强系统(-lboost_system) 这应该解决他的原始版本导致未定义的符号的问题,并允许您添加其他库。

例如-lboost_date_time,这对我来说与brew安装完美配合。

当然,我的路径实际上是:/usr/local/Cellar/boost/1.55​​.0_2

答案 1 :(得分:0)

Boost库是模块化的,您只需要链接到您正在使用的库。有些库是header only,因此您无需执行任何操作,只需在路径中获得提升即可。

您可以尝试编译:

//make sure that there is a boost folder in your boost include directory
#include <boost/chrono.hpp>
#include <cmath>

int main()
{
    auto start = boost::chrono::system_clock::now();

    for ( long i = 0; i < 10000000; ++i )
        std::sqrt( 123.456L ); // burn some time

    auto sec = boost::chrono::system_clock::now() - start;
    std::cout << "took " << sec.count() << " seconds" << std::endl;

    return 0;
}

在.pro文件中:

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp

macx {
    QMAKE_CXXFLAGS += -std=c++11

    _BOOST_PATH = /usr/local/Cellar/boost/1.55.0_1
    INCLUDEPATH += "$${_BOOST_PATH}/include/"
    LIBS += -L$${_BOOST_PATH}/lib
    ## Use only one of these:
    LIBS += -lboost_chrono-mt # using dynamic lib (not sure if you need that "-mt" at the end or not)
    #LIBS += $${_BOOST_PATH}/lib/libboost_chrono-mt.a # using static lib
}