app failing to link to mysql libraries (CentOS) - c++

The link step gets undefined references for all my mysql calls:
~/private/WDI/git$ make
c++ -L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -ldl -o tom tom.o Block.o IPC.o ConnectMxctl.o CI_Metadata.o Log.o
tom.o: In function `connect_to_table_managers()':
/home/chap/private/WDI/git/tom.cpp:128: undefined reference to `mysql_num_rows'
/home/chap/private/WDI/git/tom.cpp:132: undefined reference to `mysql_num_fields'
/home/chap/private/WDI/git/tom.cpp:133: undefined reference to `mysql_fetch_row'
/home/chap/private/WDI/git/tom.cpp:153: undefined reference to `mysql_num_rows'
/home/chap/private/WDI/git/tom.cpp:157: undefined reference to `mysql_fetch_row'
/home/chap/private/WDI/git/tom.cpp:167: undefined reference to `mysql_free_result'
The link libraries in the c++ command were generated by mysql_config --libs. Here's a partial listing of the directory:
/usr/lib/x86_64-linux-gnu$ ll libmysql*
-rw-r--r-- 1 root root 4838468 Jul 23 23:28 libmysqlclient.a
lrwxrwxrwx 1 root root 16 Jul 23 23:28 libmysqlclient_r.a -> libmysqlclient.a
lrwxrwxrwx 1 root root 17 Jul 23 23:28 libmysqlclient_r.so -> libmysqlclient.so
lrwxrwxrwx 1 root root 20 Jul 23 23:28 libmysqlclient_r.so.18 -> libmysqlclient.so.18
lrwxrwxrwx 1 root root 24 Jul 23 23:28 libmysqlclient_r.so.18.0.0 -> libmysqlclient.so.18.0.0
lrwxrwxrwx 1 root root 20 Jul 23 23:28 libmysqlclient.so -> libmysqlclient.so.18
lrwxrwxrwx 1 root root 24 Jul 23 23:28 libmysqlclient.so.18 -> libmysqlclient.so.18.0.0
-rw-r--r-- 1 root root 3408144 Jul 23 23:28 libmysqlclient.so.18.0.0
So things appear to be in their proper places. Why would these symbols be unresolvable?

You should put most independent library in the end of the command, so compiler can find symbol and definitions properly:
c++ -L/usr/lib/x86_64-linux-gnu -o tom tom.o Block.o IPC.o \
ConnectMxctl.o CI_Metadata.o Log.o \
-lmysqlclient -lpthread -lz -lm -lrt -ldl
By doing it this way, compiler will continue searching undefined symbols from next linking files. For exampile if IPO.o has uses symbol(type/class/struct/function etc) defined in CI_Metadata.o, compiler can find it because you put CI_Metadata.o after IPO.o. Most libraries are independent, that's why they are in the end of compile/link command.

Related

Linkage error with Boost Log 1.65.0 example from the Boost.org

I tried to build this example and got a linkage error:
hekto#ubuntu:~$ g++ -g -Wall -std=c++11 -pthread -DBOOST_LOG_DYN_LINK -pthread sample.cpp -o sample -lboost_log -lboost_thread -lboost_system
/tmp/cc2EUizv.o: In function `boost::log::v2_mt_posix::basic_formatter<char> boost::log::v2_mt_posix::parse_formatter<char>(char const*)':
/usr/include/boost/log/utility/setup/formatter_parser.hpp:207: undefined reference to `boost::log::v2_mt_posix::basic_formatter<char> boost::log::v2_mt_posix::parse_formatter<char>(char const*, char const*)'
collect2: error: ld returned 1 exit status
How to overcome that?
I'm answering my own question, following the #Praetorian help and suggestion.
The Boost Log relies on two libraries (I thought it was only one):
hekto#ubuntu:~$ ls -l /usr/lib/x86_64-linux-gnu/libboost_log*
-rw-r--r-- 1 root root 3510082 Mar 6 2018 /usr/lib/x86_64-linux-gnu/libboost_log.a
-rw-r--r-- 1 root root 2441460 Mar 6 2018 /usr/lib/x86_64-linux-gnu/libboost_log_setup.a
lrwxrwxrwx 1 root root 28 Mar 6 2018 /usr/lib/x86_64-linux-gnu/libboost_log_setup.so -> libboost_log_setup.so.1.65.1
-rw-r--r-- 1 root root 671944 Mar 6 2018 /usr/lib/x86_64-linux-gnu/libboost_log_setup.so.1.65.1
lrwxrwxrwx 1 root root 22 Mar 6 2018 /usr/lib/x86_64-linux-gnu/libboost_log.so -> libboost_log.so.1.65.1
-rw-r--r-- 1 root root 905752 Mar 6 2018 /usr/lib/x86_64-linux-gnu/libboost_log.so.1.65.1
If you compile and link on Linux, you'll have to provide a list of Boost libraries on the command line. According to an answer to this question, given by the main developer (#AndreySemashev) of the Boost Log, these libraries on the command line should look like this:
-lboost_log_setup -lboost_log
Probably it makes sense to provide two libraries instead of one (for example, when you link statically), but I couldn't find any recommendations about when we should use a single library, and when - both of them.

C++ compiler cannot find Boost libraries even after installing them

While compiling few test applications, I get the following error:
g++: error: −lboost_system: No such file or directory
g++: error: −lboost_filesystem: No such file or directory
while running the following command:
g++ -I/usr/include/boost/ -L/usr/lib/x86_64-linux-gnu/ aescuda.cpp -o test.o −lboost_system −lboost_filesystem
The libraries are installed and present in location as shown below:
<prompt>$ ll /usr/lib/x86_64-linux-gnu/libboost_system.*
-rw-r--r-- 1 root root 49178 Jun 20 2014 /usr/lib/x86_64-linux-gnu/libboost_system.a
lrwxrwxrwx 1 root root 25 Jun 20 2014 /usr/lib/x86_64-linux-gnu/libboost_system.so -> libboost_system.so.1.54.0
-rw-r--r-- 1 root root 14536 Jun 20 2014 /usr/lib/x86_64-linux-gnu/libboost_system.so.1.54.0
<prompt>$ ll /usr/lib/x86_64-linux-gnu/libboost_filesystem.*
-rw-r--r-- 1 root root 217628 Jun 20 2014 /usr/lib/x86_64-linux-gnu/libboost_filesystem.a
lrwxrwxrwx 1 root root 29 Jun 20 2014 /usr/lib/x86_64-linux-gnu/libboost_filesystem.so -> libboost_filesystem.so.1.54.0
-rw-r--r-- 1 root root 88936 Jun 20 2014 /usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.54.0
Can anyone suggest where am I going wrong :(
You have a wrong character in front of the l:
−lboost_system
It should be an ASCII hyphen:
-lboost_system
This causes the compiler driver to treat the whole string as an input file name (which obviously does not exist, hence the No such file or directory error), and not as an option to be passed to the linker.
(Perhaps consider switching the terminal font.)

Unable to link dynamic library : Compiling through Xcode make

My project structure is as follows:
Project>src>main.cpp
The main.cpp calls methods which have a dependancy to a dynamic library (.dylib). In my /usr/local/bin the dynamic library has the name libgismo.dylib but it is an alias which points to libgismo.0.8.1.dylib
My make file is:
# Targets
SRCPATH = ./src
GISMOPATH = /usr/local/include/gismo
CXX = g++
INCLUDE = -I/usr/local/bin -I/usr/local/include -I$(GISMOPATH) -I/usr/local/lib
DYLD_LIBRARY_PATH = -L/usr/local/lib
LIBS = -libgismo
all: main
main : $(SRCPATH)/main.cpp
#$(CXX) $(INCLUDE) $(SRCPATH)/main.cpp -o main $(DYLD_LIBRARY_PATH) $(LIBS)
$(info Compiling main)
clean :
#rm main
But when I build it through Xcode the following error is generated:
ld: library not found for -libgismo.0
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main] Error 1
Command /Applications/Xcode.app/Contents/Developer/usr/bin/make failed with exit code 2
The output to:
$ make -n
is
g++ -I/usr/local/bin -I/usr/local/include -I/usr/local/include/gismo -I/usr/local/lib ./src/main.cpp -o main -L/usr/local/lib/ -libgismo
AND
$ ls -l /usr/local/lib/*gismo*
is
-rw-r--r-- 1 root wheel 1337 May 14 11:35 /usr/local/lib/gismoConfig.cmake
-rw-r--r-- 1 root wheel 366 May 14 11:35 /usr/local/lib/gismoConfigVersion.cmake
-rw-r--r-- 1 root wheel 3900 May 14 11:34 /usr/local/lib/gismoUse.cmake
-rwxr-xr-x 1 root wheel 9195544 May 14 11:52 /usr/local/lib/libgismo.0.8.1.dylib
lrwxr-xr-x 1 root wheel 20 May 12 10:23 /usr/local/lib/libgismo.0.dylib -> libgismo.0.8.1.dylib
lrwxr-xr-x 1 root wheel 16 May 12 10:23 /usr/local/lib/libgismo.dylib -> libgismo.0.dylib
How do I fix this?
Thanks!

Compiling Qt 4.8.3 from source with OpenGL support on CentOS

Trying to compile Qt 4.8.4 with opengl support for installing Visit. I run
./configure -opengl -verbose
The console gives me:
OpenGL auto-detection... ()
g++ -c -m64 -pipe -O2 -Wall -W -I../../../mkspecs/linux-g++-64 -I. -I/usr/include/GL -I/usr/X11R6/include -o opengl.o opengl.cpp
g++ -m64 -Wl,-O1 -o opengl opengl.o -L/usr/lib64/X11 -L/usr/lib64 -lGL -lXext -lX11 -lm
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../libGL.so when searching for -lGL
/usr/bin/ld: skipping incompatible /usr/lib/libGL.so when searching for -lGL
/usr/bin/ld: cannot find -lGL
collect2: ld returned 1 exit status
gmake: *** [opengl] Error 1
OpenGL disabled.
OpenGL ES 2.x auto-detection... ()
g++ -c -m64 -pipe -O2 -Wall -W -I../../../mkspecs/linux-g++-64 -I. -I/usr/X11R6/include -o opengles2.o opengles2.cpp
opengles2.cpp:45:25: error: GLES2/gl2.h: No such file or directory
opengles2.cpp: In function ‘int main(int, char**)’:
opengles2.cpp:50: error: ‘GLfloat’ was not declared in this scope
opengles2.cpp:50: error: ‘glUniform1f’ was not declared in this scope
opengles2.cpp:51: error: ‘GL_COLOR_BUFFER_BIT’ was not declared in this scope
opengles2.cpp:51: error: ‘glClear’ was not declared in this scope
gmake: *** [opengles2.o] Error 1
OpenGL ES 2.x disabled.
OpenGL ES 1.x auto-detection... ()
g++ -c -m64 -pipe -O2 -Wall -W -I../../../mkspecs/linux-g++-64 -I. -I/usr/X11R6/include -o opengles1.o opengles1.cpp
opengles1.cpp:45:23: error: GLES/gl.h: No such file or directory
opengles1.cpp: In function ‘int main(int, char**)’:
opengles1.cpp:50: error: ‘GLfloat’ was not declared in this scope
opengles1.cpp:50: error: expected ‘;’ before ‘a’
opengles1.cpp:51: error: ‘a’ was not declared in this scope
opengles1.cpp:51: error: ‘glColor4f’ was not declared in this scope
opengles1.cpp:52: error: ‘GL_COLOR_BUFFER_BIT’ was not declared in this scope
opengles1.cpp:52: error: ‘glClear’ was not declared in this scope
gmake: *** [opengles1.o] Error 1
OpenGL ES 1.x disabled.
All the OpenGL functionality tests failed!
You might need to modify the include and library search paths by editing
QMAKE_INCDIR_OPENGL, QMAKE_LIBDIR_OPENGL and QMAKE_LIBS_OPENGL in
/home/.../Downloads/qt-everywhere-opensource-src-4.8.3/mkspecs/linux-g++-64.
So, i look inside /mkspecs/linux-g++-64, there's only one file, qmake.conf
#
# qmake configuration for linux-g++
#
# Written for GNU/Linux platforms that have both lib and lib64 directories,
# like the AMD Opteron.
#
MAKEFILE_GENERATOR = UNIX
TARGET_PLATFORM = unix
TEMPLATE = app
CONFIG += qt warn_on release incremental link_prl gdb_dwarf_index
QT += core gui
QMAKE_INCREMENTAL_STYLE = sublib
QMAKE_CFLAGS = -m64
QMAKE_LFLAGS = -m64
include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)
QMAKE_LIBDIR_X11 = /usr/X11R6/lib64
QMAKE_LIBDIR_OPENGL = /usr/X11R6/lib64
I don't have a /usr/X11R6 directory, but X_11 reports that everything is OK in the output.
I add the variables:
QMAKE_INCDIR_OPENGL = /usr/include/GL
QMAKE_LIBDIR_OPENGL = /usr/lib64
QMAKE_LIBS_OPENGL = -lGLU -lGL
Contents of /usr/include/GL:
drwxr-xr-x. 3 root root 4.0K Jun 29 14:26 .
drwxr-xr-x. 46 root root 12K Jun 29 16:07 ..
-rw-r--r--. 1 root root 7.7K Nov 12 2010 freeglut_ext.h
-rw-r--r--. 1 root root 681 Nov 12 2010 freeglut.h
-rw-r--r--. 1 root root 26K Nov 12 2010 freeglut_std.h
-rw-r--r--. 1 root root 710K Dec 13 2013 glext.h
-rw-r--r--. 1 root root 83K Dec 13 2013 gl.h
-rw-r--r--. 1 root root 126K Dec 13 2013 gl_mangle.h
-rw-r--r--. 1 root root 17K Dec 13 2013 glu.h
-rw-r--r--. 1 root root 3.3K Dec 13 2013 glu_mangle.h
-rw-r--r--. 1 root root 639 Nov 12 2010 glut.h
-rw-r--r--. 1 root root 44K Dec 13 2013 glxext.h
-rw-r--r--. 1 root root 17K Dec 13 2013 glx.h
-rw-r--r--. 1 root root 4.6K Feb 23 2013 glxint.h
-rw-r--r--. 1 root root 3.4K Dec 13 2013 glx_mangle.h
-rw-r--r--. 1 root root 2.1K Feb 23 2013 glxmd.h
-rw-r--r--. 1 root root 80K Feb 23 2013 glxproto.h
-rw-r--r--. 1 root root 12K Feb 23 2013 glxtokens.h
drwxr-xr-x. 2 root root 4.0K Jun 25 17:20 internal
contents of /usr/lib64
lrwxrwxrwx. 1 root root 15 Jun 25 17:20 libGLU.so -> libGLU.so.1.3.1
lrwxrwxrwx. 1 root root 15 Jun 25 15:59 libGLU.so.1 -> libGLU.so.1.3.1
-rwxr-xr-x. 1 root root 514K Dec 13 2013 libGLU.so.1.3.1
-rw-r--r--. 1 root root 656 Jun 25 16:20 libGL.la
lrwxrwxrwx. 1 root root 14 Jun 25 17:20 libGL.so -> libGL.so.1.2.0
lrwxrwxrwx. 1 root root 15 Jun 25 16:20 libGL.so.1 -> libGL.so.331.79
-rwxr-xr-x. 1 root root 1.2M Jun 25 16:20 libGL.so.331.79
lrwxrwxrwx. 1 root root 15 Jun 25 17:20 libGLU.so -> libGLU.so.1.3.1
lrwxrwxrwx. 1 root root 15 Jun 25 15:59 libGLU.so.1 -> libGLU.so.1.3.1
-rwxr-xr-x. 1 root root 514K Dec 13 2013 libGLU.so.1.3.1
./configure -opengl -verbose gives the same result
in addition
glxgears
works fine.
What am I doing wrong?
I guess you might install mesa driver that provides libGL.so.1.2.0 and changes the libGL.so symbolic link.
libGL.so -> libGL.so.1.2.0
libGL.so.1 -> libGL.so.331.79
libGL.so.331.79
In /usr/lib64,
rm libGL.so
ln -s libGL.so.1 libGL.so
will give you
libGL.so -> libGL.so.1 -> libGL.so.331.79

RInside Compilation: Make Targets

I am new to using make and I am trying to run the RInside example for Qt density demo given here: http://dirk.eddelbuettel.com/blog/2011/03/25/. I have saved the code into the following files:
main.cpp
Makefile
qtdensity.cpp
include/qtdensity.h
I am running Ubuntu 13.10, I have R, Rcpp and Inside installed. When I go to the terminal and run
> make -f Makefile
I get the error
make: *** No targets. Stop.
Please let me know how to proceed.
Thank you
I can't see how to ask a follow up to the first answer so I have to extend my question:
I have just created the files and was able to run qmake on main.cpp, qtdensity.cpp, qtdensity.h, and qtdensity.pro which worked but when I tried to run make, I get the following errors:
Lots of R - related errors ...
qtdensity.cpp:(.text+0x53a): undefined reference to `Rf_mkString'
qtdensity.cpp:(.text+0x54e): undefined reference to `Rf_install'
qtdensity.cpp:(.text+0x559): undefined reference to `Rf_findVarInFrame'
qtdensity.cpp:(.text+0x560): undefined reference to `R_UnboundValue'
...
qtdensity.cpp:(.text.startup+0x2a5): undefined reference to `R_NaReal'
qtdensity.cpp:(.text.startup+0x2b2): undefined reference to `R_NaN'
main.o: In function `_GLOBAL__sub_I_main':
main.cpp:(.text.startup+0x2a5): undefined reference to `R_NaReal'
main.cpp:(.text.startup+0x2b2): undefined reference to `R_NaN'
main.o: In function `main':
main.cpp:(.text.startup+0x352): undefined reference to `RInside::RInside(int, char const* const*, bool, bool, bool)'
main.cpp:(.text.startup+0x397): undefined reference to `RInside::~RInside()'
main.cpp:(.text.startup+0x3b3): undefined reference to `RInside::~RInside()'
moc_qtdensity.o: In function `_GLOBAL__sub_I__ZN9QtDensity18qt_static_metacallEP7QObjectN11QMetaObject4CallEiPPv':
moc_qtdensity.cpp:(.text.startup+0x2a5): undefined reference to `R_NaReal'
moc_qtdensity.cpp:(.text.startup+0x2b2): undefined reference to `R_NaN'
collect2: error: ld returned 1 exit status
make: *** [qdensity] Error 1
The Qt example is different because it uses Qt. You always need to start by creating the Makefile itself from the .pro file. Witness:
edd#max:~/git/rinside/inst/examples/qt$ ls -l ## no Makefile
total 28
drwxrwxr-x 2 edd edd 4096 Dec 27 18:38 cmake
-rw-rw-r-- 1 edd edd 518 Dec 27 18:38 main.cpp
-rw-rw-r-- 1 edd edd 5953 Dec 27 18:38 qtdensity.cpp
-rw-rw-r-- 1 edd edd 1532 Dec 27 18:38 qtdensity.h
-rw-rw-r-- 1 edd edd 2378 Feb 11 20:14 qtdensity.pro
-rw-rw-r-- 1 edd edd 887 Dec 27 18:38 README
edd#max:~/git/rinside/inst/examples/qt$ qmake ## creates Makefile
edd#max:~/git/rinside/inst/examples/qt$ make
g++ -c -m64 -pipe -I/usr/share/R/include [... lots and lots omitted ...]
g++ -m64 -Wl,-O1 -o qtdensity qtdensity.o main.o moc_qtdensity.o [....]
edd#max:~/git/rinside/inst/examples/qt$ ls -l qtdensity
-rwxrwxr-x 1 edd edd 76666 Feb 14 15:02 qtdensity
edd#max:~/git/rinside/inst/examples/qt$
This is of course also described in the README in this directory...