Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unresolved Symbols linking w/ Boost Serialization under Ubuntu 12.10

Tags:

c++

linux

linker

ld

I'll start by stating I'm feeling like a moron tonight. I'm trying to minimally reproduce a work issue I have under RHEL5.6, gcc 4.1.2, boost 1.44.0, with Boost Serialization.

The environment I'm having this issue with is Ubuntu Server (with dev packages installed), gcc 4.7.2, and a build of boost 1.44.0 (against the system compiler, packages, etc).

My code compiles cleanly, but I'm getting a myriad of undefined symbols related to various boost::archive types. Running strace on my make, I see it picking up the expected boost_serialization library:

668 43569 stat("/usr/local/boost/1.44.0/lib/libboost_serialization.so", {st_mode=S_IFREG|0755, st_size=700481, ...}) = 0
669 43569 open("/usr/local/boost/1.44.0/lib/libboost_serialization.so", O_RDONLY) = 8

My makefile is:

default: test-app
all: test-app

BOOST := /usr/local/boost/1.44.0

CPPFLAGS := -fPIC -Wall -Wextra -Werror
INCDIRS := -isystem$(BOOST)/include
.LIBDIRS. := $(BOOST)/lib
.LIBS. :=boost_serialization
LIBS := $(foreach lib,$(.LIBS.),-l$(lib))
LIBDIRS := $(foreach dir,$(.LIBDIRS.),-L$(dir))
CPPFLAGS += $(INCDIRS)

base.o : base.cpp base.hpp
        g++ $(CPPFLAGS) --compile $< -o $@ -g

derived.o : derived.cpp base.hpp derived.hpp
        g++ $(CPPFLAGS) --compile $< -o $@ -g

main.o: main.cpp derived.hpp
        g++ $(CPPFLAGS) --compile $< -o $@ -g

test-app: main.o derived.o base.o
        g++ -o $@ $(LIBDIRS) $(LIBS) $^

clean:
        rm -f *.o test

A (very) small sample of the linker errors I'm getting are like:

base.o: In function void boost::archive::basic_text_oprimitive<std::ostream>::save<boost::archive::class_id_reference_type>(boost::archive::class_id_reference_type const&)': /usr/local/boost/1.44.0/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::exception_code, char const*, char const*)' /usr/local/boost/1.44.0/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to boost::archive::archive_exception::~archive_exception()' /usr/local/boost/1.44.0/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to boost::archive::archive_exception::~archive_exception()' base.o: In function void boost::archive::basic_text_oprimitive<std::ostream>::save<boost::archive::tracking_type>(boost::archive::tracking_type const&)': /usr/local/boost/1.44.0/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::exception_code, char const*, char const*)' /usr/local/boost/1.44.0/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to boost::archive::archive_exception::~archive_exception()' /usr/local/boost/1.44.0/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to boost::archive::archive_exception::~archive_exception()' base.o: In function void boost::archive::basic_text_oprimitive<std::ostream>::save<unsigned int>(unsigned int const&)': /usr/local/boost/1.44.0/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::exception_code, char const*, char const*)' /usr/local/boost/1.44.0/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to boost::archive::archive_exception::~archive_exception()' /usr/local/boost/1.44.0/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to boost::archive::archive_exception::~archive_exception()'

Likewise, if I do a symbol dump on the referenced .so's, I see the required symbols:

objdump -t /usr/local/boost/1.44.0/lib/libboost_serialization.so | c++filt | grep "boost::archive::archive_exception::~archive_exception()" 000000000004e670 g F .text 0000000000000065
boost::archive::archive_exception::~archive_exception() 000000000004e6e0 g F .text 0000000000000009 virtual thunk to boost::archive::archive_exception::~archive_exception() 000000000004e6f0 g F .text 0000000000000012
boost::archive::archive_exception::~archive_exception() 000000000004ed60 g F .text 000000000000005c
boost::archive::archive_exception::~archive_exception() 000000000004e710 g F .text 0000000000000009 virtual thunk to boost::archive::archive_exception::~archive_exception()

I've been banging my head against the table for a while now...hoping someone can help. I don't think the specific source matters, but if requested, I can post it.

Additional environmental details:

g++ --version g++ (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2 Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

ld --version
GNU ld (GNU Binutils for Ubuntu) 2.22.90.20120924
Copyright 2012 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.

Additionally, this is on a VM running under Hyper-V on Windows 8, although, I don't think that matters here.

Complete link line: g++ -L/usr/local/boost/1.44.0/lib -lboost_serialization -o test-app main.o derived.o base.o

like image 906
Nathan Ernst Avatar asked Feb 27 '13 03:02

Nathan Ernst


1 Answers

I've had the same problem, putting -lboost_serialization at the end like

g++ -L/usr/local/boost/1.44.0/lib -o test-app main.o derived.o base.o -lboost_serialization

should solve it

like image 61
grizzancs Avatar answered Nov 15 '22 19:11

grizzancs