undefined reference when linking against libresolv - c++

I have a project that is a library that links against libresolv,
It works fine on recent distros: Ubuntu 10.x Fedora 13, Mandriva
2010.1 but on Centos 5.x I get the following errors
glibc installed is: glibc-2.5-18.el5_1.1
g++ -DHAVE_CONFIG_H -I. -I./include -I/usr/include/postgresql -O3
-ansi -Wall -Wno-deprecated -D_FORTIFY_SOURCE=0 -MT testUpLog.o -MD
-MP -MF .deps/testUpLog.Tpo -c -o testUpLog.o testUpLog.cc
mv -f .deps/testUpLog.Tpo .deps/testUpLog.Po
/bin/sh ./libtool --tag=CXX --mode=link g++ -O3 -ansi -Wall
-Wno-deprecated -D_FORTIFY_SOURCE=0 -L/usr/lib64 -L/lib64
-L/usr/lib64/mysql -o testUpLog testUpLog.o libUpTools.la -lpq
-lmysqlclient -lssl -lpthread
libtool: link: g++ -O3 -ansi -Wall -Wno-deprecated -D_FORTIFY_SOURCE=0
-o .libs/testUpLog testUpLog.o -L/usr/lib64 -L/lib64
-L/usr/lib64/mysql ./.libs/libUpTools.so -lpq -lmysqlclient -lssl
-lpthread
./.libs/libUpTools.so: undefined reference to `__ns_name_uncompress'
./.libs/libUpTools.so: undefined reference to `__ns_initparse'
./.libs/libUpTools.so: undefined reference to `__ns_parserr'
collect2: ld returned 1 exit status
make[1]: *** [testUpLog] Error 1
make[1]: Leaving directory `/tmp/UpTools-8.5.3'
make: *** [check-am] Error 2
library.la file contains:
dlname='libUpTools.so.0'
library_names='libUpTools.so.0.0.0 libUpTools.so.0 libUpTools.so'
old_library='libUpTools.a'
inherited_linker_flags=''
dependency_libs=' -L/usr/lib64 -L/lib64 -L/usr/lib64/mysql -lpq
-lmysqlclient -lssl -lpthread'
weak_library_names=''
current=0
age=0
revision=0
installed=no
shouldnotlink=no
dlopen=''
dlpreopen=''
libdir='/usr/lib'
You can read configure.ac on
http://pastebin.com/hs5q21Rq
Thanks in advance

If libUpTools uses functions lib libresolv, you need to say so:
libUpTools_la_LIBADD = -lresolv (of course -lresolv may be replaced by variables determined by configure etc.)
That way, -lresolv will end up in the .la file and also in the .so file (if you chose to build it) that you can run ldd on for verification.

Related

How to rectify `undefined reference to `MPI::Comm::Comm()'` when compiling with Makefile?

I am trying to compile a code by Makefile. I received the code from github. I tried to implement the solution from links:
[https://github.com/LLNL/scr/issues/130][1]
[https://stackoverflow.com/questions/62461718/mpi-complile-error-undefined-reference-to-mpiwinfree][2], etc.
These solutions are not working for me or they are too technical. I am sorry to say as I am not from a programming background, it is difficult for me to understand.
The make file are as follows:
Makefile.include
.SUFFIXES: .cxx .cu .f90 .o
.PHONY: docs
CUDA_INSTALL_PATH = /usr/local/cuda
DEVICE = cpu
#~ DEVICE = gpu
CXX = mpicxx -g -O3 -std=c++11 -fPIC -fopenmp -ffast-math -funroll-loops -rdynamic -Wfatal-errors -I../include
NVCC = nvcc -Xcompiler "-fopenmp -O3" -std=c++11 -use_fast_math -I../include
FC = mpif90 -g -O3 -fPIC -fopenmp -funroll-loops -rdynamic -I../include
LFLAGS = -D$(DEVICE) -lstdc++ -ldl -lm
#~ LFLAGS += -lmpi_cxx
ifeq ($(DEVICE),gpu)
LFLAGS += -lcudart
endif
OBJECT = ../kernel/$(DEVICE)Laplace.o ../kernel/$(DEVICE)BiotSavart.o\
../kernel/$(DEVICE)Stretching.o ../kernel/$(DEVICE)Gaussian.o\
../kernel/$(DEVICE)CoulombVdW.o
.cxx.o:
$(CXX) -c $? -o $# $(LFLAGS)
.cu.o:
$(NVCC) -c $? -o $# $(LFLAGS)
.f90.o:
$(FC) -c $? -o $#
and Makefile:
include ../Makefile.include
lib_parallel_ij: parallel_wrapper_ij.o $(OBJECT)
ar -cr libfmm.a parallel_wrapper_ij.o $(OBJECT)
ranlib libfmm.a
test_parallel_ij: test_parallel_ij.o
make lib_parallel_ij
$(FC) $? -L. -lfmm $(LFLAGS)
mpirun -np 2 ./a.out
clean:
make -C .. clean
When I am trying to compile it. It gives me the following errors:
mpif90 -g -O3 -fPIC -fopenmp -funroll-loops -rdynamic -I../include -c test_parallel_ij.f90 -o test_parallel_ij.o
make lib_parallel_ij
make[1]: Entering directory '/home/bidesh/panelCode/UVLM/NVLM_FMM/solver_single_rotor_try/exafmm-alpha-vortex/wrapper'
mpicxx -g -O3 -std=c++11 -fPIC -fopenmp -ffast-math -funroll-loops -rdynamic -Wfatal-errors -I../include -c parallel_wrapper_ij.cxx -o parallel_wrapper_ij.o -Dcpu -lstdc++ -ldl -lm
mpicxx -g -O3 -std=c++11 -fPIC -fopenmp -ffast-math -funroll-loops -rdynamic -Wfatal-errors -I../include -c ../kernel/cpuLaplace.cxx -o ../kernel/cpuLaplace.o -Dcpu -lstdc++ -ldl -lm
mpicxx -g -O3 -std=c++11 -fPIC -fopenmp -ffast-math -funroll-loops -rdynamic -Wfatal-errors -I../include -c ../kernel/cpuBiotSavart.cxx -o ../kernel/cpuBiotSavart.o -Dcpu -lstdc++ -ldl -lm
mpicxx -g -O3 -std=c++11 -fPIC -fopenmp -ffast-math -funroll-loops -rdynamic -Wfatal-errors -I../include -c ../kernel/cpuStretching.cxx -o ../kernel/cpuStretching.o -Dcpu -lstdc++ -ldl -lm
mpicxx -g -O3 -std=c++11 -fPIC -fopenmp -ffast-math -funroll-loops -rdynamic -Wfatal-errors -I../include -c ../kernel/cpuGaussian.cxx -o ../kernel/cpuGaussian.o -Dcpu -lstdc++ -ldl -lm
mpicxx -g -O3 -std=c++11 -fPIC -fopenmp -ffast-math -funroll-loops -rdynamic -Wfatal-errors -I../include -c ../kernel/cpuCoulombVdW.cxx -o ../kernel/cpuCoulombVdW.o -Dcpu -lstdc++ -ldl -lm
ar -cr libfmm.a parallel_wrapper_ij.o ../kernel/cpuLaplace.o ../kernel/cpuBiotSavart.o ../kernel/cpuStretching.o ../kernel/cpuGaussian.o ../kernel/cpuCoulombVdW.o
ranlib libfmm.a
make[1]: Leaving directory '/home/bidesh/panelCode/UVLM/NVLM_FMM/solver_single_rotor_try/exafmm-alpha-vortex/wrapper'
mpif90 -g -O3 -fPIC -fopenmp -funroll-loops -rdynamic -I../include test_parallel_ij.o -L. -lfmm -Dcpu -lstdc++ -ldl -lm
./libfmm.a(parallel_wrapper_ij.o): In function `MPI::Op::Init(void (*)(void const*, void*, int, MPI::Datatype const&), bool)':
/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/ompi/mpi/cxx/op_inln.h:121: undefined reference to `ompi_mpi_cxx_op_intercept'
./libfmm.a(parallel_wrapper_ij.o): In function `MPI::Intracomm::Clone() const':
/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/ompi/mpi/cxx/intracomm_inln.h:23: undefined reference to `MPI::Comm::Comm()'
./libfmm.a(parallel_wrapper_ij.o): In function `MPI::Graphcomm::Clone() const':
/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/ompi/mpi/cxx/intracomm.h:25: undefined reference to `MPI::Comm::Comm()'
./libfmm.a(parallel_wrapper_ij.o): In function `MPI::Cartcomm::Sub(bool const*) const':
/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/ompi/mpi/cxx/intracomm.h:25: undefined reference to `MPI::Comm::Comm()'
./libfmm.a(parallel_wrapper_ij.o): In function `MPI::Intracomm::Create_graph(int, int const*, int const*, bool) const':
/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/ompi/mpi/cxx/intracomm.h:25: undefined reference to `MPI::Comm::Comm()'
./libfmm.a(parallel_wrapper_ij.o): In function `MPI::Cartcomm::Clone() const':
/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/ompi/mpi/cxx/intracomm.h:25: undefined reference to `MPI::Comm::Comm()'
./libfmm.a(parallel_wrapper_ij.o):/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/ompi/mpi/cxx/intracomm.h:25: more undefined references to `MPI::Comm::Comm()' follow
./libfmm.a(parallel_wrapper_ij.o):(.data.rel.ro._ZTVN3MPI8DatatypeE[_ZTVN3MPI8DatatypeE]+0x78): undefined reference to `MPI::Datatype::Free()'
./libfmm.a(parallel_wrapper_ij.o):(.data.rel.ro._ZTVN3MPI3WinE[_ZTVN3MPI3WinE]+0x48): undefined reference to `MPI::Win::Free()'
collect2: error: ld returned 1 exit status
Makefile:48: recipe for target 'test_parallel_ij' failed
make: *** [test_parallel_ij] Error 1
I am unable to solve the error. I couldn't compile the code. I will be greatly helped if I can get some clue to compile it.
Thanks a lot.
[1]: https://github.com/LLNL/scr/issues/130
[2]: MPI complile error, undefined reference to `MPI::Win::Free()

Error while compiling JUMPCoin Wallet on Raspberry Pi (leveldb/libmemenv.a: error adding symbols:)

I am trying to compile a wallet for my JUMP coins (https://github.com/Jumperbillijumper/jumpcoin).
I cloned the repo,
cd to src/
and ran $ make -f makefile.unix
and now I am getting this error:
/home/pi/jumpcoin/jumpcoin/src/leveldb/libmemenv.a: error addingsymbols: Archive has no index; run ranlib to add one
collect2: error: ld returned 1 exit status
makefile.unix:206: recipe for target 'jumpcoind' failed
make: *** [jumpcoind] Error 1
Log:
pi#Raspberry_Pi:~/jumpcoin/jumpcoin/src $ make -f makefile.unix
/bin/sh ../share/genbuild.sh obj/build.h
g++ -c -O2 -pthread -Wall -Wextra -Wno-ignored-qualifiers -Wformat -Wformat-security -Wno-unused-parameter -g -DBOOST_SPIRIT_THREADSAFE -I/home/pi/jumpcoin/jumpcoin/src -I/home/pi/jumpcoin/jumpcoin/src/obj -DUSE_UPNP=0 -DUSE_IPV6=1 -I/home/pi/jumpcoin/jumpcoin/src/leveldb/include -I/home/pi/jumpcoin/jumpcoin/src/leveldb/helpers -DHAVE_BUILD_INFO -fno-stack-protector -fstack-protector-all -Wstack-protector -D_FORTIFY_SOURCE=2 -MMD -MF obj/txdb-leveldb.d -o obj/txdb-leveldb.o txdb-leveldb.cpp
g++ -O2 -pthread -Wall -Wextra -Wno-ignored-qualifiers -Wformat -Wformat-security -Wno-unused-parameter -g -DBOOST_SPIRIT_THREADSAFE -I/home/pi/jumpcoin/jumpcoin/src -I/home/pi/jumpcoin/jumpcoin/src/obj -DUSE_UPNP=0 -DUSE_IPV6=1 -I/home/pi/jumpcoin/jumpcoin/src/leveldb/include -I/home/pi/jumpcoin/jumpcoin/src/leveldb/helpers -DHAVE_BUILD_INFO -fno-stack-protector -fstack-protector-all -Wstack-protector -D_FORTIFY_SOURCE=2 -o jumpcoind obj/groestl.o obj/blake.o obj/skein.o obj/keccak.o obj/jh.o obj/alert.o obj/version.o obj/checkpoints.o obj/netbase.o obj/addrman.o obj/crypter.o obj/key.o obj/db.o obj/init.o obj/irc.o obj/keystore.o obj/miner.o obj/main.o obj/net.o obj/protocol.o obj/jumpcoinrpc.o obj/rpcdump.o obj/rpcnet.o obj/rpcmining.o obj/rpcwallet.o obj/rpcblockchain.o obj/rpcrawtransaction.o obj/script.o obj/sync.o obj/util.o obj/wallet.o obj/walletdb.o obj/noui.o obj/kernel.o obj/pbkdf2.o obj/scrypt.o obj/scrypt-arm.o obj/scrypt-x86.o obj/scrypt-x86_64.o obj/zerocoin/Accumulator.o obj/zerocoin/AccumulatorProofOfKnowledge.o obj/zerocoin/Coin.o obj/zerocoin/CoinSpend.o obj/zerocoin/Commitment.o obj/zerocoin/ParamGeneration.o obj/zerocoin/Params.o obj/zerocoin/SerialNumberSignatureOfKnowledge.o obj/zerocoin/SpendMetaData.o obj/zerocoin/ZeroTest.o obj/txdb-leveldb.o -Wl,-z,relro -Wl,-z,now -Wl,-Bdynamic -l boost_system -l boost_filesystem -l boost_program_options -l boost_thread -l db_cxx -l ssl -l crypto -l miniupnpc -Wl,-Bdynamic -l z -l dl -l pthread /home/pi/jumpcoin/jumpcoin/src/leveldb/libleveldb.a /home/pi/jumpcoin/jumpcoin/src/leveldb/libmemenv.a
/home/pi/jumpcoin/jumpcoin/src/leveldb/libmemenv.a: error adding symbols: Archive has no index; run ranlib to add one
collect2: error: ld returned 1 exit status
makefile.unix:206: recipe for target 'jumpcoind' failed
make: *** [jumpcoind] Error 1
ok the problem was in the src/leveldb directory (obviously)
I took the src/leveldb directory from this repo (https://github.com/sagacrypto/SagaCoin) and replaced the current one. Then everything works fine. (at least for me :P)
yeah I know it is not best practice but this one was driving me nuts :D

Specifying Google perftools to g++ for using C++ in R

I installed Google perftools (google-perftools 1.7-1ubuntu1), and add -lprofiler to PKG_LIBS in R, when compiling the C++ code.
library(RcppArmadillo)
library(Rcpp)
Sys.setenv("PKG_CXXFLAGS"="-fopenmp")
Sys.setenv("PKG_LIBS"="-fopenmp -lprofiler")
sourceCpp('my.cpp')
The output is:
/usr/bin/ld: cannot find -lprofiler
collect2: ld returned 1 exit status
make: *** [sourceCpp_17496.so] Error 1
g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -I"/usr/local/lib/R/site-library/RcppArmadillo/include" -fopenmp -fpic -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c my.cpp -o my.o g++ -shared -Wl,-Bsymbolic-functions -Wl,-z,relro -o sourceCpp_17496.so my.o -llapack -lblas -lgfortran -lm -lquadmath -fopenmp -fopenmp -lprofiler -L/usr/lib/R/lib -lR
Error in sourceCpp("my.cpp") :
Error 1 occurred building shared library.
WARNING: The tools required to build C++ code for R were not found.
Please install GNU development tools including a C++ compiler.
Even if I run g++ in bash, I get the same error
$ g++ -shared -Wl,-Bsymbolic-functions -Wl,-z,relro -o sourceCpp_17496.so my.o -llapack -lblas -lgfortran -lm -lquadmath -fopenmp -fopenmp -lprofiler -L/usr/lib/R/lib -lR
/usr/bin/ld: cannot find -lprofiler
collect2: ld returned 1 exit status
I wonder why -lprofiler doesn't specify google perfotools? How can I solve the problem? Thanks!
My g++ is g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3.
Quick ones:
Do you actually have the package libgoogle-perftools-dev installed? Ie do you have shared and static libraries /usr/lib/libprofiler.* ? This is the mother of all development FAQs: you need package libfoo to run code against foo, and package libfoo-dev to compile against foo.
I have old working examples in the slides from my 'HPC with R' talks from a few years ago; those should all work as is.

undefined reference to `utf8_nextCharSafeBody_48' icu4c while building a library

I have tried to build the stmd library (http://getassoc.cs.nii.ac.jp/package/stmd-1.1.5.tar.gz) on Ubuntu 12.04.2 amd64 which use the ICU library.
I have installed libicu-dev (version: 48) from Ubuntu repository and using the following configuration.
./configure --with-icu-config=/usr/bin/icu-config --with-defaultstemmer=SNOWBALL --enable-snowball=yes --enable-kill3number=yes
and then,
make
I got the following errors..
/bin/bash ./libtool --mode=link g++ -I. -g -O2 -Wall -Wno-parentheses -Wdeclaration-after- statement -g -O -D_BSD_SOURCE -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED=1 '-DDEFAULT_STEMMER=SNOWBALL' '-DSTMD_MYSTEMMER_DIR="/usr/local/bin"' -g -Wall -O2 -Wall -ansi -pedantic -Wshadow -Wpointer-arith -Wmissing-prototypes -Wwrite-strings -Wno-long-long -D_REENTRANT -I/usr/include '-DUSE_SNOWBALL=1' -I/usr/local/include -DKILL3NUMBER=1 -L/usr/lib -ldl -lm -L/usr/lib -licui18n -licuuc -licudata -ldl -lm -L/usr/local/lib -o stmd stmd.o stmc.o sigflg.o nio.o -L. -L/usr/lib -ldl -lm -L/usr/lib -licui18n -licuuc -licudata -ldl -lm -L/usr/local/lib -lystem -lstemmer -lexpat -ldl
libtool: link: g++ -I. -g -O2 -Wall -Wno-parentheses -Wdeclaration-after-statement -g -O -D_BSD_SOURCE -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED=1 -DDEFAULT_STEMMER=SNOWBALL -DSTMD_MYSTEMMER_DIR=\"/usr/local/bin\" -g -Wall -O2 -Wall -ansi -pedantic -Wshadow -Wpointer-arith -Wmissing-prototypes -Wwrite-strings -Wno-long-long -D_REENTRANT -I/usr/include -DUSE_SNOWBALL=1 -I/usr/local/include -DKILL3NUMBER=1 -o stmd stmd.o stmc.o sigflg.o nio.o -L/usr/lib -L/usr/local/lib -L/home/kobkrit/stmd-1.1.5 -licui18n -licuuc -licudata -lm -lystem -lstemmer /usr/lib/x86_64-linux-gnu/libexpat.so -ldl
/home/kobkrit/stmd-1.1.5/libystem.a(normalizer.o): In function `utf8toutf16':
/home/kobkrit/stmd-1.1.5/normalizer.c:177: undefined reference to `utf8_nextCharSafeBody_48'
/home/kobkrit/stmd-1.1.5/normalizer.c:191: undefined reference to `u_errorName_48'
/home/kobkrit/stmd-1.1.5/libystem.a(normalizer.o): In function `utf16toutf8':
/home/kobkrit/stmd-1.1.5/normalizer.c:227: undefined reference to `u_errorName_48'
/home/kobkrit/stmd-1.1.5/normalizer.c:219: undefined reference to `utf8_appendCharSafeBody_48'
/home/kobkrit/stmd-1.1.5/normalizer.c:223: undefined reference to `utf8_appendCharSafeBody_48'
/home/kobkrit/stmd-1.1.5/libystem.a(normalizer.o): In function `normalizer_sparse_tostr':
/home/kobkrit/stmd-1.1.5/normalizer.c:125: undefined reference to `unorm_normalize_48'
/home/kobkrit/stmd-1.1.5/normalizer.c:138: undefined reference to `unorm_normalize_48'
/home/kobkrit/stmd-1.1.5/normalizer.c:140: undefined reference to `u_errorName_48'
/home/kobkrit/stmd-1.1.5/libystem.a(ngram.o): In function `nextchar':
/home/kobkrit/stmd-1.1.5/ngram.c:158: undefined reference to `utf8_nextCharSafeBody_48'
/home/kobkrit/stmd-1.1.5/ngram.c:150: undefined reference to `utf8_nextCharSafeBody_48'
/home/kobkrit/stmd-1.1.5/libystem.a(ngram.o): In function `ng_output':
/home/kobkrit/stmd-1.1.5/ngram.c:182: undefined reference to `utf8_appendCharSafeBody_48'
collect2: ld returned 1 exit status
make: *** [stmd] Error 1
It seems about the problem between linker to ICU library, so I take a look on Makefile, I found
...
CFLAGS+=$(shell /usr/bin/icu-config --cflags)
CFLAGS+=$(shell /usr/bin/icu-config --cppflags)
LDFLAGS+=$(shell /usr/bin/icu-config --ldflags-searchpath)
LDFLAGS+=$(shell /usr/bin/icu-config --ldflags)
...
(I don't quite sure, does it relate to the problem or not?)
I tried build the stmd library on Ubuntu 10.04.4 LTS amd64 and it went fine and work perfectly. But sadly my server's hardware is not compatible with the old Ubuntu. Please help.
Your command line:
g++ ... -licui18n -licuuc -licudata -ldl -lm ... -o stmd stmd.o stmc.o ...
is incorrect: the order of object files and libraries on command line matters.

ld path update for compiling

I just installed manually apr and apr_util so i can install activemq c++ library.
When i try to make the cpp library i get the following error:
**
libtool: link: g++ -ansi -pedantic -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -I/usr/local/apr/include/apr-1 -I/usr/local/apr/include/apr-1 -I/usr/kerberos/include -W -Wall -Wextra -Wconversion -fPIC -fstrict-aliasing -Wstrict-aliasing=2 -Wno-long-long -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -I/usr/local/apr/include/apr-1 -I/usr/local/apr/include/apr-1 -I/usr/kerberos/include -Wno-non-virtual-dtor -Wno-unused-parameter -Wno-uninitialized -I./../main -g -O2 -pthread -o .libs/example example-main.o ../main/.libs/libactivemq-cpp.so -lexpat -L/usr/kerberos/lib64 /usr/local/apr/lib/libaprutil-1.so /usr/local/apr/lib/libapr-1.so -luuid -lrt -lcrypt /usr/local/apr/lib/libexpat.so -lssl -lcrypto -ldl -lz -lpthread -pthread -Wl,-rpath -Wl,/usr/local/lib -Wl,-rpath -Wl,/usr/local/apr/lib
/usr/bin/ld: cannot find -lexpat
collect2: ld returned 1 exit status
**
and expat is within apr-util and not being linked. how can i update the ld path so that make or environment will find it?
or in short: how can i resolve this?
Usually you'll need to manually specify the library path using -L option.
It would look like ld filename -Lpath -llibname in a single ld operation. Or in this case you may need to add the paths of your library(apr-util here) to the constant of library paths in a Makefile.