1

Built Boost 1.75.0 and cannot link my application. I used the same scenario/build and it works for Boost 1.67.0 . I have looked at many similar post but no luck with the answers.

main.o is before the libs and boost_system is last boost library in the boost list.

Any help appreciated.

CentOS 8, g++ (GCC) 8.3.1 20191121 (Red Hat 8.3.1-5)

My build was:

./bootstrap.sh
./b2 -a --threading=multi --link=static

link error:

g++ -DWINUX -pthread -g -O3 -Wall -DNDEBUG -o ../bin/TestApp main.o -L../lib - 
 L/usr/local/src/boost_1_75_0/stage/lib -Wl,-Bstatic -lboost_date_time -lboost_filesystem - 
 lboost_thread -lboost_system -Wl,-Bdynamic -lpthread

 main.o: In function `boost::asio::detail::scheduler::shutdown()':
 /usr/local/include/boost/system/error_code.hpp:461: undefined reference to 
  `boost::system::system_category()'

main.cpp:

#include <iostream>
#include <boost/shared_ptr.hpp>
#include <boost/asio.hpp>

typedef boost::shared_ptr<boost::asio::io_service> asioPtr_t;

int main(int argc, char* argv[])
{
  asioPtr_t io_ = asioPtr_t(new boost::asio::io_service());

  std::cout << "Test App: " << __DATE__ << std::endl;
}

Makefile:

ifeq ($(strip $(BOOST_HDRDIR)),)
  $(error PLEASE SET BOOST_HDRDIR)
endif

ifeq ($(strip $(BOOST_LIBDIR)),)
  $(error PLEASE SET BOOST_LIBDIR)
endif

APP = TestApp

SRCS = $(wildcard *.cpp)
OBJS = $(SRCS:.cpp=.o)

COMPILER = g++
CFLAGS = -DWINUX -pthread -g -O3 -Wall -DNDEBUG
COMPILE = $(COMPILER) $(CFLAGS)

INCLDIRS = -I../ -I$(BOOST_HDRDIR)

LIBDIRS = -L../lib -L$(BOOST_LIBDIR)

LIBS = -Wl,-Bstatic -lboost_date_time -lboost_filesystem \
       -lboost_thread -lboost_system \
       -Wl,-Bdynamic -lpthread

%.o: %.cpp
    $(COMPILE) -c $< $(INCLDIRS) -o $@

$(APP): $(OBJS)
    @echo "Linking $(APP)..."
    mkdir -p ../bin
    $(COMPILE) -o ../bin/$(APP) $(OBJS) $(LIBDIRS) $(LIBS)

test:
    $(MAKE) -C UnitTest test

clean:
    rm -f $(APP) $(OBJS)
1
  • The release notes: Changes in Boost 1.69 Boost.System is now header-only. A stub library is still built for compatibility, but linking to it is no longer necessary. Maybe a system lib is linked with older boost?
    – sfanjoy
    Commented Dec 19, 2020 at 21:16

1 Answer 1

1

I was able to solve my issues by adding -DBOOST_ERROR_CODE_HEADER_ONLY to my compile options (CFLAGS) in the Makefile. This stackoverflow question was helpful in finding my solution:

undefined reference to boost::system::system_category() when compiling.

However, the above solution masked the actual problem which cropped up later when using boost_filesystem. My environment variable BOOST_HDRDIR was set as follows:

BOOST_HDRDIR=/usr/local/src/boost_1_75_0/boost

when it actually should have been

BOOST_HDRDIR=/usr/local/src/boost_1_75_0

Not the answer you're looking for? Browse other questions tagged or ask your own question.