简体   繁体   English

如何在Makefile中链接Boost库?

[英]How to link boost library in Makefile?

I'm new to the syntax of Makefiles and I'm not sure how can I properly link to boost library thread definitions. 我是Makefiles语法的新手,我不确定如何正确链接以增强Boost库线程定义。

In the .cpp file, I have this code: 在.cpp文件中,我有以下代码:

boost::thread(&MessageBus::readBus, this, _bus).detach();

I have included following: 我包括以下内容:

#include <boost/thread.hpp>

But while compiling I get the following error which seems to be because of linking issues: 但是在编译时出现以下错误,这似乎是由于链接问题造成的:

../../../../bsl1/boost/boost/thread/detail/thread.hpp:255: undefined reference to `boost::thread::detach()'
Consolidator.o: In function `~thread_data':
../../../../bsl1/boost/boost/thread/detail/thread.hpp:93: undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
../../../../bsl1/boost/boost/thread/detail/thread.hpp:93: undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
Consolidator.o: In function `thread_data_base':
../../../../bsl1/boost/boost/thread/pthread/thread_data.hpp:144: undefined reference to `vtable for boost::detail::thread_data_base'
Consolidator.o: In function `thread_data':
../../../../external/bsl1/boost/boost/thread/detail/thread.hpp:111: undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
Consolidator.o: In function `boost::thread::start_thread()':
../../../../bsl1/boost/boost/thread/detail/thread.hpp:180: undefined reference to `boost::thread::start_thread_noexcept()'

In Makefile, I have added boost lib in both CFLAGS and CXXFLAGS: 在Makefile中,我在CFLAGS和CXXFLAGS中都添加了boost lib:

PROG = msgbusd

NO_STRIP = yes

.PATH: \
    ${.CURDIR}/server \

SRCS += \
    main.cpp \
    oc.cpp \
    UdpReceiver.cpp \
    ${OTHER_SRCS} \
    ${LIB_PROTOS_SRCS} \


CXXFLAGS += \
    -fpermissive \
    -I${SRCTOP_EXTERNAL}/bsl1/boost


CFLAGS += \
    -DBOOST_SYSTEM_NO_DEPRECATED \
    -fno-inline \
    -I${.CURDIR}/server \
    -I${.CURDIR}/lib/h \
    -I. \
    -I${SRCTOP_EXTERNAL}/bsl1/boost

DPLIBS += \
    ${LIBXSLT} \
    ${LIBISC} \
    ${LIBBSDXML} \
    ${LIBXML2} \
    ${LIBEVENT} \
    ${LIBPTHREAD} \
    ${LIBZ}

.include <bsd.prog.mk>

I'm developing in FreeBSD 6 and has gcc 4.2. 我正在FreeBSD 6中进行开发,并具有gcc 4.2。

What other changes I need to do in order to be able to compile it successfully? 为了成功编译它,我还需要做哪些其他更改?

Already went through this thread, and didn't find anything specific to Makefile and Makefile syntax to include boost libraries 已经经历了这个线程,并且没有发现特定于Makefile和Makefile语法的任何东西来包含boost库

This question is about FreeBSD Makefiles infrastructure. 这个问题是关于FreeBSD Makefiles基础设施的。 If you aren't developing your project as part of FreeBSD (I doubt you do, since FreeBSD 6 is ancient), you don't really need to poke around bsd.prog.mk . 如果您不打算将项目作为FreeBSD的一部分进行开发(我怀疑您这样做,因为FreeBSD 6是古老的版本),那么您实际上并不需要戳bsd.prog.mk I'd suggest using modern build system for this task, like CMake. 我建议使用现代构建系统来完成此任务,例如CMake。

However, if you really required to use plain BSD Makefiles, you should define LDFLAGS variable and pass -lboost_thread there. 但是,如果确实需要使用普通的BSD Makefile,则应定义LDFLAGS变量并在其中传递-lboost_thread

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM