简体   繁体   中英

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.

In the .cpp file, I have this code:

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:

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.

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

This question is about FreeBSD Makefiles infrastructure. 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 . I'd suggest using modern build system for this task, like CMake.

However, if you really required to use plain BSD Makefiles, you should define LDFLAGS variable and pass -lboost_thread there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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