[英]Qt Creator on Mac and boost libraries
I am running QtCreator on Mac... I want to start working on boost libraries ... So, I installed boost libraries using 我在Mac上运行QtCreator ...我想开始使用Boost库...因此,我使用
brew install boost
After that I created a small boost hallo world program and made the changes in .pro file as follows 之后,我创建了一个小的Boost Hallo World程序,并按如下所示对.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
I am still unable to build... What could be the reason? 我仍然无法建造……可能是什么原因? Please suggest me what could be the possible mistake...
请建议我可能是什么错误...
The errors are 错误是
library not found for -lboost_data_time
linker command failed with exit code 1 (use -v to see invocation)
This is taking a bit from Uflex's answer, as he missed something. 由于Uflex错过了一些内容,因此需要一些答案。 So keep the same code:
因此,请保持相同的代码:
//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;
}
But lets change his .pro a bit: 但是让我们稍微改变一下他的.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
}
The only thing I have added to this was the boost system( -lboost_system ) That should solve the issue with his original version causing the undefined symbols, and allow you to add your other libraries. 我添加到此的唯一内容是boost系统(-lboost_system),该系统可以解决其原始版本导致未定义符号的问题,并允许您添加其他库。
Such as -lboost_date_time, which for me worked perfectly with the brew install. 例如-lboost_date_time,对我而言,它与brew安装非常完美。
Granted, my path is actually: /usr/local/Cellar/boost/1.55.0_2 当然,我的路径实际上是:/usr/local/Cellar/boost/1.55.0_2
Boost libraries are modularized, you just need to link against the libraries that you are using. Boost库是模块化的,您只需要链接到正在使用的库即可。 Some libraries are header only , so you don't need to do anything, having boost reachable in your path is enough.
有些库仅是标头 ,因此您无需执行任何操作,只需在路径中达到boost就足够了。
You can try to compile this: 您可以尝试编译以下代码:
//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;
}
And in the .pro file: 并在.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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.