I have a problem, i want to compile my application with static linking of mysql connector.
My command line:
g++ -o newserver stdafx.cpp … -lboost_system -lboost_thread
-lpthread -lmysqlcppconn -static /usr/lib/libmysqlcppconn-static.a -std=c++0x
But i have error:
/usr/bin/ld: cannot find -lmysqlcppconn
/tmp/ccxpOfdZ.o: In function `IsEqualsDns(unsigned long, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
Server.cpp:(.text+0x356e): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
collect2: ld returned 1 exit status
How can i fix this?
Thanks!
Where is the library
libsqlcppconn.aorlibsqucppconn.so(static or dynamic)? The compiler is looking for it, and
doesn’t find it.
Presumably, this is the same library as
/usr/lib/mysqlcppconn-static.a. If so, just drop the-lmysqlcppconn. Or just use-lmysqlcppconn-static(nospaces), and forget about the
/usr/lib/libmysqlconn-static.a.With a name like that, there shouldn’t be a corresponding
.so,which means that g++ will link it statically, even without the
-static. You only need the-staticif there is botha
libmysqlconn-static.soand alibmysqlconn-static.ain thesame directory.
With regards to the second error (which is just a warning, but
will cause problems if you try to run the linked program on
other machines, or even after an upgrade of your machine): if
you use
-staticanywhere in your command line (as youcurrently do), then it applies to all files linked afterwards.
Including the system libraries, which you don’t want to link
statically. My guess is that the
-staticisn’t necessary (seeabove); if it is, place it immediately before the library you
want to link statically, and place a
-dynamicimmediatelyafter (so that any following libraries, including the system
libraries, will be dynamically linked).