Related
I am trying to compile Boost 1.79.0 in a cluster using the GCC compiler version 12.1.0 that I have compiled manually since the GCC version of the cluster is very old.
After compiling GCC, I have exported the following paths in a shell script that I source every time in the terminal before installing or running a program. I have manually installed CMake and several programs.
However, I am still struggling with compiling Boost. It is complaining about undefined references in C++11 so I guess there is something that is linked wrongly.
Could anyone provide any suggestions to overcome this issue?
Here is my exports in the shell script:
export PATH=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/bin:$PATH
export CFLAGS="-I /lustre/home/ucemkmo/Softwares/gcc-12.1.0/include";
export LDFLAGS="-L /lustre/home/ucemkmo/Softwares/gcc-12.1.0/lib64";
export CPPFLAGS="-I /lustre/home/ucemkmo/Softwares/gcc-12.1.0/include";
export CXXFLAGS="-L /lustre/home/ucemkmo/Softwares/gcc-12.1.0/lib64";
export LD_LIBRARY_PATH=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/lib64:$LD_LIBRARY_PATH
export LD_RUN_PATH=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/lib64
export LD="/lustre/home/ucemkmo/Softwares/gcc-12.1.0/bin/g++"
export MANPATH=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/share/man:$MANPATH
export INFOPATH=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/share/info:$INFOPATH
export INFO_PATH=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/share/info:$INFO_PATH
export AR=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/bin/gcc-ar
export CC=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/bin/gcc
export CXX=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/bin/g++
export LD=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/bin/g++
export CXXCPP="/lustre/home/ucemkmo/Softwares/gcc-12.1.0/bin/g++ -E"
export FC=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/bin/gfortran
export F77=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/bin/gfortran
export F90=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/bin/gfortran
export COLLECT_GCC=gcc
export COLLECT_LTO_WRAPPER=/lustre/home/ucemkmo/Softwares/gcc-12.1.0/bin/../libexec/gcc/x86_64-unknown-linux-gnu/12.1.0/lto-wrapper
export PATH=/lustre/home/ucemkmo/Softwares/cmake-3.24.0/bin:$PATH
export PATH=/lustre/home/ucemkmo/Softwares/python-3.10.5/3.10.5/bin:$PATH
export PETSC_DIR=/lustre/home/ucemkmo/Softwares/petsc
export PETSC_ARCH=arch-linux-c-opt
Here are the error messages I am receiving during the compilation of Boost v1.79.0:
Building B2 engine..
###
###
### Using 'gcc' toolset.
###
###
g++ (GCC) 12.1.0
Copyright (C) 2022 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.
###
###
> g++ -x c++ -std=c++11 -O2 -s -DNDEBUG builtins.cpp class.cpp command.cpp compile.cpp constants.cpp cwd.cpp debug.cpp debugger.cpp execcmd.cpp execnt.cpp execunix.cpp filesys.cpp filent.cpp fileunix.cpp frames.cpp function.cpp glob.cpp hash.cpp hcache.cpp hdrmacro.cpp headers.cpp jam_strings.cpp jam.cpp jamgram.cpp lists.cpp make.cpp make1.cpp md5.cpp mem.cpp modules.cpp native.cpp object.cpp option.cpp output.cpp parse.cpp pathnt.cpp pathsys.cpp pathunix.cpp regexp.cpp rules.cpp scan.cpp search.cpp startup.cpp subst.cpp sysinfo.cpp timestamp.cpp variable.cpp w32_getreg.cpp modules/order.cpp modules/path.cpp modules/property-set.cpp modules/regex.cpp modules/sequence.cpp modules/set.cpp -o b2
/tmp/cc1S1rUW.o: In function `builtin_normalize_path(frame*, int)':
builtins.cpp:(.text+0x14ea): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
builtins.cpp:(.text+0x1510): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
/tmp/cc8w84jf.o: In function `debug_print_frame_info(_frame_info&)':
debugger.cpp:(.text+0x3d7): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::compare(char const*) const'
/tmp/cc8w84jf.o: In function `debug_frame_read(_IO_FILE*, _frame_info*)':
debugger.cpp:(.text+0x1707): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned long, unsigned long, char const*, unsigned long)'
/tmp/cceSnutQ.o: In function `var_parse_to_string(VAR_PARSE_GROUP*, bool)':
function.cpp:(.text+0x1683): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
function.cpp:(.text+0x16b5): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
function.cpp:(.text+0x171c): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
function.cpp:(.text+0x1770): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
function.cpp:(.text+0x17b3): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
/tmp/cceSnutQ.o:function.cpp:(.text+0x17d3): more undefined references to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)' follow
/tmp/cceSnutQ.o: In function `var_parse_to_string(VAR_PARSE_VAR const*, bool)':
function.cpp:(.text+0x193f): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned long, unsigned long, char const*, unsigned long)'
function.cpp:(.text+0x19b0): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
function.cpp:(.text+0x1a2e): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
function.cpp:(.text+0x1ae2): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
function.cpp:(.text+0x1b40): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned long, unsigned long, char const*, unsigned long)'
function.cpp:(.text+0x1bf3): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
function.cpp:(.text+0x1c3e): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
/tmp/ccwxFfFi.o: In function `errno_printf(char const*, ...)':
output.cpp:(.text+0x69d): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct(unsigned long, char)'
output.cpp:(.text+0x732): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned long, unsigned long, char const*, unsigned long)'
output.cpp:(.text+0x7a2): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
output.cpp:(.text+0x8bb): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
output.cpp:(.text+0x8f0): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
output.cpp:(.text+0x92a): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
output.cpp:(.text+0x953): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
output.cpp:(.text+0x9bd): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct(unsigned long, char)'
output.cpp:(.text+0xa81): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct(unsigned long, char)'
/tmp/cc7flVRU.o: In function `void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char const*>(char const*, char const*, std::forward_iterator_tag) [clone .isra.0]':
pathsys.cpp:(.text+0x68): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
/tmp/cc7flVRU.o: In function `b2::paths::normalize(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
pathsys.cpp:(.text+0x51d): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
pathsys.cpp:(.text+0x59d): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::rfind(char, unsigned long) const'
pathsys.cpp:(.text+0x5ee): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_erase(unsigned long, unsigned long)'
pathsys.cpp:(.text+0x62d): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned long, unsigned long, char const*, unsigned long)'
pathsys.cpp:(.text+0x6e7): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_erase(unsigned long, unsigned long)'
pathsys.cpp:(.text+0x711): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_erase(unsigned long, unsigned long)'
pathsys.cpp:(.text+0x761): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_erase(unsigned long, unsigned long)'
/tmp/ccR9xr0R.o: In function `void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char*>(char*, char*, std::forward_iterator_tag) [clone .isra.0]':
startup.cpp:(.text+0x68): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
/tmp/ccR9xr0R.o: In function `void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char const*>(char const*, char const*, std::forward_iterator_tag) [clone .isra.0]':
startup.cpp:(.text+0x108): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
/tmp/ccR9xr0R.o: In function `b2::startup::builtin_boost_build(frame*, int)':
startup.cpp:(.text+0x3d2): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
startup.cpp:(.text+0x459): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
startup.cpp:(.text+0x70a): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
startup.cpp:(.text+0x86f): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
startup.cpp:(.text+0x8d2): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
startup.cpp:(.text+0x986): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/tmp/ccR9xr0R.o: In function `b2::startup::bootstrap(frame*)':
startup.cpp:(.text+0x1045): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
startup.cpp:(.text+0x114d): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::rfind(char, unsigned long) const'
startup.cpp:(.text+0x14e5): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
startup.cpp:(.text+0x1517): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
startup.cpp:(.text+0x1658): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
startup.cpp:(.text+0x168a): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
startup.cpp:(.text+0x1852): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
/tmp/ccR9xr0R.o:startup.cpp:(.text+0x1884): more undefined references to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)' follow
/tmp/ccR9xr0R.o: In function `b2::startup::bootstrap(frame*)':
startup.cpp:(.text+0x1a46): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
startup.cpp:(.text+0x1ba6): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
startup.cpp:(.text+0x1c6e): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
startup.cpp:(.text+0x1c93): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
startup.cpp:(.text+0x1ceb): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
startup.cpp:(.text+0x1d3e): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/tmp/ccR9xr0R.o: In function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
startup.cpp:(.text._ZStplIcSt11char_traitsIcESaIcEENSt7__cxx1112basic_stringIT_T0_T1_EERKS8_SA_[_ZStplIcSt11char_traitsIcESaIcEENSt7__cxx1112basic_stringIT_T0_T1_EERKS8_SA_]+0x42): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)'
/tmp/cceOb6PB.o: In function `cwd_init()':
cwd.cpp:(.text+0x87): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned long, unsigned long, char const*, unsigned long)'
/tmp/cceOb6PB.o: In function `_GLOBAL__sub_I__Z8cwd_initv':
cwd.cpp:(.text.startup+0xb): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
collect2: error: ld returned 1 exit status
> cp b2 bjam
cp: cannot stat ‘b2’: No such file or directory
Failed to build B2 build engine
It seems that you are facing a problem regarding Dual ABIs:
If you get linker errors about undefined references to symbols that
involve types in the std::__cxx11 namespace or the tag [abi:cxx11]
then it probably indicates that you are trying to link together object
files that were compiled with different values for the
_GLIBCXX_USE_CXX11_ABI macro. This commonly happens when linking to a third-party library that was compiled with an older version of GCC. If
the third-party library cannot be rebuilt with the new ABI then you
will need to recompile your code with the old ABI.
In other words, some of the boost dependencies has been compiled using your old gcc. See the full page in gcc documentation, here.
I have a cephfs and i'm writing a client code in c language using libcephfs.h library for it.
Note: installed libcephfs-dev and libcephfs2, but did not work on any version(12.2.12 or 12.2.4) I am using ubuntu 18.04.3.
#include "/usr/include/cephfs/libcephfs.h"
#include <stdlib.h>
#include <stdio.h>
int main (int argc, const char* argv[]){
struct ceph_mount_info *cmount;
const char id[] = "client.admin";
int err = ceph_create(&cmount, id);
printf("%d", err);
return 0;
}
$ g++ -o example example.c -lcephfs
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `AdminSocket::unregister_command(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `ceph_clock_now()'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `AdminSocket::register_command(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, AdminSocketHook*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `PerfCountersBuilder::add_u64_counter(int, char const*, char const*, char const*, int)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `md_config_t::set_val(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*, bool, std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >*)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `CrushWrapper::get_full_location_ordered(int, std::vector<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `PerfCounters::tinc(int, utime_t, unsigned int)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `md_config_t::parse_env()'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `md_config_t::parse_argv(std::vector<char const*, std::allocator<char const*> >&)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `ceph::Formatter::create(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `PerfCounters::tinc(int, std::chrono::duration<unsigned long, std::ratio<1l, 1000000000l> >, unsigned int)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `FSMap::parse_role(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, mds_role_t*, std::ostream&) const'
collect2: error: ld returned 1 exit status
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
#define _FILE_OFFSET_BITS 64
#include <cephfs/libcephfs.h>
#include <stdlib.h>
#include <stdio.h>
int main (int argc, const char* argv[]){
struct ceph_mount_info *cmount;
const char id[] = "client.admin";
int err = ceph_create(&cmount, id);
printf("%d", err);
return 0;
}
This code compiles for me on Ubuntu 18.04 with the GCC 7 compiler.
The command I used to compile is :
g++ -o example example.c -lcephfs
In fact, even your source compiles on my system with the added #defines that I have used.
It worked ! Before upgrading my ubuntu version(from 16.04 to 18.04), i have installed librados. Now, i reinstall librados and libcephfs. It worked successfully.
Trying to compile this cfgparser example.
$ g++ example.cc -lcfgparser
: In function `main':
example.cc:(.text+0x6b): undefined reference to `ConfigParser_t::readFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
example.cc:(.text+0x160): undefined reference to `ConfigParser_t::getValue(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) const'
example.cc:(.text+0x2d9): undefined reference to `ConfigParser_t::getValue(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int*) const'
example.cc:(.text+0x43c): undefined reference to `ConfigParser_t::getValue(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, double*) const'
example.cc:(.text+0x5b1): undefined reference to `ConfigParser_t::getValue(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool*) const'
example.cc:(.text+0x78c): undefined reference to `ConfigParser_t::getValue(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >*) const'
example.cc:(.text+0xa15): undefined reference to `ConfigParser_t::getValue(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) const'
example.cc:(.text+0xba2): undefined reference to `ConfigParser_t::getValue(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) const'
example.cc:(.text+0xd15): undefined reference to `ConfigParser_t::getValue(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) const'
example.cc:(.text+0xe7f): undefined reference to `ConfigParser_t::getValue(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) const'
collect2: error: ld returned 1 exit statu
But clearly those symbols are there:
$ nm -gC /usr/lib/libcfgparser.so
000000000003710 T ConfigParser_t::readFile(std::string const&)
0000000000004880 T ConfigParser_t::ConfigParser_t(std::string const&)
00000000000024c0 T ConfigParser_t::ConfigParser_t()
0000000000004ad0 T ConfigParser_t::ConfigParser_t(std::string const&)
00000000000024a0 T ConfigParser_t::ConfigParser_t()
0000000000004d20 T ConfigParser_t::getOptions(std::string const&) const
00000000000028d0 T ConfigParser_t::getSections() const
0000000000002ff0 T ConfigParser_t::getValue(std::string, std::string, bool*) const
0000000000002de0 T ConfigParser_t::getValue(std::string, std::string, double*) const
0000000000002bd0 T ConfigParser_t::getValue(std::string, std::string, int*) const
00000000000027d0 T ConfigParser_t::getValue(std::string, std::string, std::string*) const
0000000000003500 T ConfigParser_t::getValue(std::string, std::string, std::vector<std::string, std::allocator<std::string> >*) const
Unlike other similar problems on SO, this is NOT about linking order, as there is only one object file being linked. Anything I'm missing??
But clearly those symbols are there:
Clearly, they're not. Take a closer look and you will see that
there are no matches between the signatures reported by your
linker as undefined and those reported from the library by
nm.
The Standard header <string> defines std::string as typedef for:
std::basic_string<char, std::char_traits<char>, std::allocator<char>>
The GCC implementation of <string>, as of the cxx11 ABI (GCC 4.7.0)
defines std::string as a typedef for:
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>
The std::__cxx11 name space encloses types whose binary implementations are
compliant with the cxx11 ABI.
That type definition means that C++ translation unit that includes the Standard header <string> won't
compile, with GCC >= 4.7, into object code containing a symbol that demangles as std::string.
If a binary - like your libcfgparser.so - contains a symbol that demangles as std::string, then
whatever that symbol might have referred to in the sources from which it was built, it does not refer to std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>,
and cannot be linked with other binaries that were compiled with that definition of std::string.
Your libcfgparser.so is the one installed by libcfgparser0_1.1.2_amd64.deb from the
cfgparser Sourceforce project
(which was last updated three years ago). I guess this from that the fact that I
get your linkage error with same example.cc program linked against the library that is installed by that package.
The explanation for the error is revealed by:
/usr/lib$ strings -a libcfgparser.so | grep "GCC: ("
GCC: (Debian 4.3.2-1.1) 4.3.2
...
which tells us that this library was built with GCC 4.3.2 - pre the cxx11 ABI.
The std::string that appears in your nm output is a pre-cxx11 demangling abbreviation
of std::basic_string<char, std::char_traits<char>, std::allocator<char>>.
This libcfgparser.so is ABI-incompatible with your current GCC, so you
can't link it with programs that you build with that compiler. What you can do is
build libcfgparser from the source package, libcfgparser-1.1.2.tar.bz2,
with your current compiler and then link your programs with the library you have
built yourself.
That works, but not effortlessly. First you'll need to fix the broken
and antiquated autotooling of the source package to create a working ./configure
script.
Which doesn't give a reassuring impression of the proficiency of the package maintainer.
Plus the source code of the package, copyright 2008, is of amateur quality. If
what you are after is a C++ parser for INI-style files, then boost::property_tree::ini_parser would be the
goto solution. See this answer
I have already configured and built Caffe from the ground up in CPU_ONLY and GPU_ONLY modes (with the respective samples and tools); and fairly satisfied with the out-of-the-box results.
However, I am starting my own project derived from the cpp_classification example, and having difficulties in building it independent of the overall Caffe build system. As such, I have gone back to the cpp_classification example and have been working to build that as a standalone (just to ensure that I am not leaving anything out) and encountering similar errors.
I sharing the contents of my build-errors output and the CMakeLists.txt with you in the hopes that someone else who has successfully hoisted the cpp_classification example can provide guidance.
I have narrowed down the build-errors I am getting to the following:
Scanning dependencies of target cpp_classification
[ 50%] Building CXX object CMakeFiles/cpp_classification.dir/classification.cpp.o
[100%] Linking CXX executable cpp_classification
CMakeFiles/cpp_classification.dir/classification.cpp.o: In function `Classifier::Classifier(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:62: undefined reference to `caffe::Net<float>::Net(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, caffe::Phase, int, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const*, caffe::Net<float> const*)'
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:63: undefined reference to `caffe::Net<float>::CopyTrainedLayersFrom(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
CMakeFiles/cpp_classification.dir/classification.cpp.o: In function `Classifier::SetMean(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:124: undefined reference to `caffe::BlobProto::BlobProto()'
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:129: undefined reference to `caffe::Blob<float>::FromProto(caffe::BlobProto const&, bool)'
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:135: undefined reference to `caffe::Blob<float>::mutable_cpu_data()'
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:124: undefined reference to `caffe::BlobProto::~BlobProto()'
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:124: undefined reference to `caffe::BlobProto::~BlobProto()'
CMakeFiles/cpp_classification.dir/classification.cpp.o: In function `Classifier::Predict(cv::Mat const&)':
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:156: undefined reference to `caffe::Blob<float>::Reshape(int, int, int, int)'
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:158: undefined reference to `caffe::Net<float>::Reshape()'
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:165: undefined reference to `caffe::Net<float>::Forward(float*)'
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:169: undefined reference to `caffe::Blob<float>::cpu_data() const'
CMakeFiles/cpp_classification.dir/classification.cpp.o: In function `Classifier::WrapInputLayer(std::vector<cv::Mat, std::allocator<cv::Mat> >*)':
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:184: undefined reference to `caffe::Blob<float>::mutable_cpu_data()'
CMakeFiles/cpp_classification.dir/classification.cpp.o: In function `Classifier::Preprocess(cv::Mat const&, std::vector<cv::Mat, std::allocator<cv::Mat> >*)':
/home/rudycazabon/caffe/examples/cpp_classification/classification.cpp:227: undefined reference to `caffe::Blob<float>::cpu_data() const'
CMakeFiles/cpp_classification.dir/classification.cpp.o: In function `caffe::Caffe::set_mode(caffe::Caffe::Brew)':
/home/rudycazabon/caffe/distribute/include/caffe/common.hpp:148: undefined reference to `caffe::Caffe::Get()'
CMakeFiles/cpp_classification.dir/classification.cpp.o: In function `caffe::ReadProtoFromBinaryFileOrDie(char const*, google::protobuf::Message*)':
/home/rudycazabon/caffe/distribute/include/caffe/util/io.hpp:78: undefined reference to `caffe::ReadProtoFromBinaryFile(char const*, google::protobuf::Message*)'
collect2
My corresponding CMakeList.txt is as follows:
cmake_minimum_required(VERSION 3.6)
project(cpp_classification)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(CAFFE_HOME ~/caffe/distribute)
find_package(OpenCV REQUIRED)
find_package(Caffe REQUIRED)
find_package(GTest REQUIRED)
find_package(glog REQUIRED)
find_package(Boost REQUIRED COMPONENTS system)
find_package(Protobuf REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES classification.cpp)
include_directories(${CAFFE_HOME}/include ${Boost_INCLUDE_DIRS} )
link_directories(${CAFFE_HOME}/lib ${Boost_LIBRARY_DIRS})
add_executable(cpp_classification
${SOURCE_FILES}
${GLOG_INCLUDE_DIR}
${Caffe_INCLUDE_DIR}
${Protobuf_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(cpp_classification
${OpenCV_LIBS}
${Boost_LIBRARIES}
${GLOG_LIBRARY}
${CAFFE_LIBRARY}
${Protobuf_LIBRARY})
try with
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0")
It tells gcc to use the old ABI for <string>.
My first attempt to build uhd was to use a script I had written that had worked in the past on two laptops running 14.04. After that, I went back here:
http://files.ettus.com/manual/page_build_guide.html#build_instructions_unix
After that, I went here:
https://kb.ettus.com/Building_and_Installing_the_USRP_Open-Source_Toolchain_(UHD_and_GNU_Radio)_on_Linux
I get the following compile errors. I'm at a loss, as I have install all of libboost, so I'm not sure what is missing. I'm building on the maint branch. I am on a new computer running 16.04.
[ 61%] Built target uhd
[ 61%] Linking CXX executable sync_to_gps
CMakeFiles/sync_to_gps.dir/sync_to_gps.cpp.o: In function `_main(int, char**)':
sync_to_gps.cpp:(.text+0x6de): undefined reference to `boost::program_options::options_description::options_description(std::string const&, unsigned int, unsigned int)'
CMakeFiles/sync_to_gps.dir/sync_to_gps.cpp.o: In function `boost::program_options::typed_value<std::string, char>::xparse(boost::any&, std::vector<std::string, std::allocator<std::string> > const&) const':
sync_to_gps.cpp:(.text._ZNK5boost15program_options11typed_valueISscE6xparseERNS_3anyERKSt6vectorISsSaISsEE[_ZNK5boost15program_options11typed_valueISscE6xparseERNS_3anyERKSt6vectorISsSaISsEE]+0x1f): undefined reference to `boost::program_options::validate(boost::any&, std::vector<std::string, std::allocator<std::string> > const&, std::string*, int)'
CMakeFiles/sync_to_gps.dir/sync_to_gps.cpp.o: In function `std::vector<std::string, std::allocator<std::string> > boost::program_options::to_internal<std::string>(std::vector<std::string, std::allocator<std::string> > const&)':
sync_to_gps.cpp:(.text._ZN5boost15program_options11to_internalISsEESt6vectorISsSaISsEERKS2_IT_SaIS5_EE[_ZN5boost15program_options11to_internalISsEESt6vectorISsSaISsEERKS2_IT_SaIS5_EE]+0x7d): undefined reference to `boost::program_options::to_internal(std::string const&)'
CMakeFiles/sync_to_gps.dir/sync_to_gps.cpp.o: In function `boost::program_options::basic_parsed_options<char> boost::program_options::parse_command_line<char>(int, char const* const*, boost::program_options::options_description const&, int, boost::function1<std::pair<std::string, std::string>, std::string const&>)':
sync_to_gps.cpp:(.text._ZN5boost15program_options18parse_command_lineIcEENS0_20basic_parsed_optionsIT_EEiPKPKS3_RKNS0_19options_descriptionEiNS_9function1ISt4pairISsSsERKSsEE[_ZN5boost15program_options18parse_command_lineIcEENS0_20basic_parsed_optionsIT_EEiPKPKS3_RKNS0_19options_descriptionEiNS_9function1ISt4pairISsSsERKSsEE]+0x15e): undefined reference to `boost::program_options::detail::cmdline::cmdline(std::vector<std::string, std::allocator<std::string> > const&)'
sync_to_gps.cpp:(.text._ZN5boost15program_options18parse_command_lineIcEENS0_20basic_parsed_optionsIT_EEiPKPKS3_RKNS0_19options_descriptionEiNS_9function1ISt4pairISsSsERKSsEE[_ZN5boost15program_options18parse_command_lineIcEENS0_20basic_parsed_optionsIT_EEiPKPKS3_RKNS0_19options_descriptionEiNS_9function1ISt4pairISsSsERKSsEE]+0x1ef): undefined reference to `boost::program_options::detail::cmdline::set_additional_parser(boost::function1<std::pair<std::string, std::string>, std::string const&>)'
CMakeFiles/sync_to_gps.dir/sync_to_gps.cpp.o: In function `boost::program_options::typed_value<std::string, char>::name() const':
sync_to_gps.cpp:(.text._ZNK5boost15program_options11typed_valueISscE4nameEv[_ZNK5boost15program_options11typed_valueISscE4nameEv]+0x29): undefined reference to `boost::program_options::arg'
CMakeFiles/sync_to_gps.dir/sync_to_gps.cpp.o:(.rodata._ZTVN5boost15program_options11typed_valueISscEE[_ZTVN5boost15program_options11typed_valueISscEE]+0x38): undefined reference to `boost::program_options::value_semantic_codecvt_helper<char>::parse(boost::any&, std::vector<std::string, std::allocator<std::string> > const&, bool) const'
../lib/libuhd.so.003.010: undefined reference to `boost::archive::text_iarchive_impl<boost::archive::text_iarchive>::load(std::string&)'
../lib/libuhd.so.003.010: undefined reference to `boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > >::maybe_assign(boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > > const&)'
../lib/libuhd.so.003.010: undefined reference to `boost::filesystem::path_traits::dispatch(boost::filesystem::directory_entry const&, std::string&)'
../lib/libuhd.so.003.010: undefined reference to `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)'
../lib/libuhd.so.003.010: undefined reference to `boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save(std::string const&)'
collect2: error: ld returned 1 exit status
examples/CMakeFiles/sync_to_gps.dir/build.make:107: recipe for target 'examples/sync_to_gps' failed
make[2]: *** [examples/sync_to_gps] Error 1
CMakeFiles/Makefile2:393: recipe for target 'examples/CMakeFiles/sync_to_gps.dir/all' failed
make[1]: *** [examples/CMakeFiles/sync_to_gps.dir/all] Error 2
Makefile:160: recipe for target 'all' failed
make: *** [all] Error 2
I had a similar issue which turned out to be an older version of GCC still installed on my Ubuntu system being called. Look at /usr/bin/gcc and /usr/bin/g++ and see if they're linked to /usr/bin/gcc-5 and /usr/bin/g++-5 respectively.