LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Mixing Shared and Dynamic Libraries (https://www.linuxquestions.org/questions/programming-9/mixing-shared-and-dynamic-libraries-43746/)

linuxeco 02-02-2003 09:43 AM

Mixing Shared and Dynamic Libraries
 
I have been working on a c++ program that consists of several source files. I am trying to compile them each into objects and then links them afterwards. This is working just fine except I would like the one object to staically include the libraries that it uses. I have ....

class.cc conf.cc html.cc libsql.cc main.cc sql.cc

sql.cc is the only object that requires mysql and mysql++. Although mysql may be common, mysql++ is not as common. I would like to be able to produce a final binary that does not need the dynamic libraries that relate to -lsqlplus and -lmysqlclient. This will make it easier for me to use the program on multiple machines without having to install additional libs. This is what the section of my makefile looks like. I tried going over the libtool documentation but I seem to be missing something. I am fresh out of ideas so maybe someone can help me.


Code:

CXX =  /usr/bin/c++
CFLAGS = -O2 -march=`uname -m` -funroll-loops
DEBUG = -g -Wall
MYSQL_LIB = -lmysqlclient -lsqlplus
MYSQL_INC = -I/usr/include/mysql -L/usr/lib/mysql
LIBTOOL = libtool
INSTALL = install
DESTDIR =
LOGO = logo.jpg
WEB_PATH = /home/public/public_html/apache
CONF = /etc/logview.conf

# Limits specifies teh maximum length of a string in the config file.
LIMIT = 100

all:
    ${CXX} -c conf.cc -DCONF=\"${CONF}\" -DLIMIT=${LIMIT}
    ${CXX} -static -c libsql.cc -DSQL ${MYSQL_INC}
    ar cru libsql.la libsql.o
    ranlib libsql.la
    ${CXX} -c main.cc
    ${CXX} -c html.cc
    ${CXX} -c class.cc
    ${LIBTOOL} ${CXX} ${CFLAGS} ${DEBUG} class.o main.o conf.o html.o lib.la -o logview \
${MYSQL_INC} ${MYSQL_LIB} -Wl,--rpath


linuxeco 02-02-2003 09:04 PM

Solved
 
Well I figured it out, but if anyone has any comments or alternative ways to handle this, I am interested in hearing them

Code:

CXX =  /usr/bin/c++
CXXFLAGS = -O2 -march=`uname -m` -funroll-loops
DEBUG = -g -Wall
MYSQL_LIB = -lmysqlclient
MYSQL_API_LIB = -lsqlplus
MYSQL_INC = -I/usr/include/mysql -L/usr/lib/mysql
LIBTOOL = libtool
INSTALL = install
DESTDIR =
LOGO = logo.jpg
WEB_PATH = /home/public/public_html/apache
CONF = /etc/logview.conf

# Limits specifies teh maximum length of a string in the config file.
LIMIT = 100

all:
        ${CXX} -c conf.cc -DCONF=\"${CONF}\" -DLIMIT=${LIMIT}
        ${CXX} -c sql.cc -DSQL ${MYSQL_INC}
        ${CXX} -c main.cc
        ${CXX} -c html.cc
        ${CXX} -c class.cc
        ${LIBTOOL} ${CXX} ${CXXFLAGS} ${DEBUG} class.o main.o conf.o html.o sql.o -o logview \
                /usr/lib/libsqlplus.a -lz ${MYSQL_INC} ${MYSQL_LIB} -W1,--rpath



All times are GMT -5. The time now is 08:33 PM.