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.
Related
I couldn't find a direct answer on Google, and since I haven't done stuff on Linux for a long time hoped to find help here. I am getting a linking error on Ubuntu when building a shared object. The linker tells me I should recompile with -fPIC even though I have set -fPIC for all source files. The output of make:
mkdir -p ../_Bin/Debug/HttpClientApi
g++ -fPIC -pedantic -Wall -Wextra -std=c++11 -c CentralServerClient.cpp -o ../_Bin/Debug/HttpClientApi/CentralServerClient.o
CentralServerClient.cpp:4:80: warning: unused parameter ‘pEventListener’ [-Wunused-parameter]
void CCentralServerClient::AddEventListener(ICentralServerClientEventListener* pEventListener)
^
CentralServerClient.cpp:29:83: warning: unused parameter ‘pEventListener’ [-Wunused-parameter]
void CCentralServerClient::RemoveEventListener(ICentralServerClientEventListener* pEventListener)
^
g++ -fPIC -pedantic -Wall -Wextra -std=c++11 -c HttpRequest.cpp -o ../_Bin/Debug/HttpClientApi/HttpRequest.o
g++ -fPIC -pedantic -Wall -Wextra -std=c++11 -c HttpResponse.cpp -o ../_Bin/Debug/HttpClientApi/HttpResponse.o
g++ -fPIC -pedantic -Wall -Wextra -std=c++11 -c IOService.cpp -o ../_Bin/Debug/HttpClientApi/IOService.o
g++ -Wl,-shared -Wl,-v -Wl,-g -o ../_Bin/Debug/HttpClientApi.so ../_Bin/Debug/HttpClientApi/CentralServerClient.o ../_Bin/Debug/HttpClientApi/HttpRequest.o ../_Bin/Debug/HttpClientApi/HttpResponse.o ../_Bin/Debug/HttpClientApi/IOService.o
collect2 version 4.9.2
/usr/bin/ld -plugin /usr/lib/gcc/x86_64-linux-gnu/4.9/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/4.9/lto-wrapper -plugin-opt=-fresolution=/tmp/ccZ9RMHe.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --sysroot=/ --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -z relro -o ../_Bin/Debug/HttpClientApi.so /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.9/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/4.9 -L/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.9/../../.. -shared -v -g ../_Bin/Debug/HttpClientApi/CentralServerClient.o ../_Bin/Debug/HttpClientApi/HttpRequest.o ../_Bin/Debug/HttpClientApi/HttpResponse.o ../_Bin/Debug/HttpClientApi/IOService.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/4.9/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crtn.o
GNU ld (GNU Binutils for Ubuntu) 2.25
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crt1.o: relocation R_X86_64_32S against `__libc_csu_fini' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crt1.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Makefile:15: recipe for target '../_Bin/Debug/HttpClientApi.so' failed
make: *** [../_Bin/Debug/HttpClientApi.so] Error 1
gcc is gcc version 4.9.2 (Ubuntu 4.9.2-10ubuntu13)
Any help is appreciated.
Instead of giving g++ -Wl,-shared you should give it -shared. The reason is that g++ need to know which crt1.o to use - one suitable for shared libraries (compiled with -fPIC, scrt1.o) or one which is not suitable.
When you give -shared to g++ it knows to use scrt1.o. But when you pass `-Wl,-shared', g++ doesn't know that you are building shared library - it 'thinks', you are building a normal executable (linker does know what is happening) and asks linker to link with crt1.o. Linker refuses and you have an error.
I can build a Linux executable with g++ like below without any problem:
g++ -I/usr/local/include -I/usr/local/include/FL/images -I/usr/include/freetype2 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_THREAD_SAFE -D_REENTRANT -o '2016_02_06a_1st_Window' '2016_02_06a_1st_Window.cxx' /usr/local/lib/libfltk.a -lXext -lXft -lfontconfig -lpthread -ldl -lm -lX11
But When I try to build a MS Windows executable with MinGW like below and error happens:
i586-mingw32msvc-g++ -I/usr/local/include -I/usr/local/include/FL/images -I/usr/include/freetype2 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_THREAD_SAFE -D_REENTRANT 2016_02_06a_1st_Window.cxx -L/usr/local/lib -lfltk -lXext -lXft -lfontconfig -lpthread -ldl -lm -lX11 -o 2016_02_06a_1st_Window.exe
The error of MinGW is:
Compiling and linking..
/usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/../../../../i586-mingw32msvc/bin/ld: cannot find -lXext
collect2: ld returned 1 exit status
I have installed all kinds of Xext libraries like these:
I have the following Xext libraries on my machine:
user#computer:~$ locate *Xext*
/usr/include/X11/extensions/Xext.h
/usr/lib/i386-linux-gnu/libXext.a
/usr/lib/i386-linux-gnu/libXext.so
/usr/lib/i386-linux-gnu/libXext.so.6
/usr/lib/i386-linux-gnu/libXext.so.6.4.0
I feel like g++ knows where Xext libraries are, but MinGW doesn't know. Any idea would be helpful.
you are running a cross compiler, which host is linux and target is windows, so when you link your target binaries, you should have target libraries. in your case, you should have libX for windows, and you listed are linux libraries, that's why your cross compiler cannot find libraries to link.
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.
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.
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.