another problem in build system of C++ projects

W. Tasin tasin at fhm.edu
Thu Nov 8 12:13:13 GMT 2001


Eva Brucherseifer wrote:

  > Hi,


Hi Eva,

first at all sorry if I haven't understood well. I'd tried something
like you described and I had no problems.

But I'm also some kind irritated about what you described ;-)


  >
  > there is another problem in the build system for C++ projects.
  >
  > Let's say, you have a subdir in your project and thus a library (say
libx.a),
  > and you use other external libs (like libyz.a) in this library libx.a.
  > Then you would add "-lyz" to the linker options and -lx.a would be added
  > automatically.


If I have a subdir in my project which will be linked against the
top-level dir i will have a compiler/linker line like this:

gcc ..... x/libx.a -lyz

and not like
gcc ..... -lx -lyz

If you don't do so you can have some version conflicts between the
libx.a installed on your system and the one (I guess the recent one)
which is part of your project.

libyz.a has to be installed on your system. AFAIK you must copy it to a
place outside of your project directory and "ranlib" it.

If the place of your lib is sth. common like /usr/lib or /usr/local/lib
you don't have to add the -L flag.

I have the same problem as you if I'm making 3 projects.

1st project libyz.a (installed on $libdir)
2nd project libx.a (installed on $libdir and uses a function of libyz.a)
3rd project uses a function of libx.a

and I haven't it also managed with the normal static libtype. It seems 
that the "ar" or "ranlib" command hasn't the possibility to save 
dependencies of libs against lib functions.


But if you use a libtool library (shared/static), this won't happen anymore.
This kind of library contains a depencies list, which libraries are 
necessary for the one (in this case libx.a ; libx.la is the 
corrisponding wrapper script). This also means no
activation of -lyz in the third project, only -lx that's all.
With this kind of library it will automatically add all libraries, which 
are needed. (And as a surprise, maybe it is more than only the -lyx)

Now how can this be managed with kdevelop.
Convert at least libx.a to a shared library (which means a libtool 
library either shared or static).
Edit manually configure.in.in and change the entries
---
dnl create only shared libtool-libraries
AC_ENABLE_SHARED(no)

dnl set the following to yes, if you want to create static
dnl libtool-libraries, too.
AC_ENABLE_STATIC(yes)
---
(Now you have specified that you want only static libs on default)

x/Makefile.am (the Makefile.am of libx.la) should look like:
---
####### kdevelop will overwrite this part!!! (begin)##########
lib_LTLIBRARIES = libx.la


libx_la_LDFLAGS = -version-info 0:0:0

libx_la_METASOURCES = AUTO

libx_la_SOURCES = func2.cpp


EXTRA_DIST = func2.cpp

####### kdevelop will overwrite this part!!! (end)############
libx_la_LIBADD = -lyz
---
(means adding the last line, outside of the kdevelop specific part)

You should do the same to libyz.a, but in this case it's not really 
necessary.


  >
  > If you now compile and link, the linker gives a lot of errors,
because the
  > symbols of libyz.a in libx.a cannot be resolved.
  > This can be fixed by changing the order:
  > -lx -lyz
  > instead of the current link order:
  > -lyz -lx
  >
  > A workarround is to add also the lib of the project to the linker
object.
  > Then libx.a appears twice, but it works:
  > -lx -lyz -lx
  >
  > Can that be changed in the build system? Or is that a problem of the
  > admin-files?
  >
  > Thanks,
  > eva
  >

I've done an example, which should show what I meant. You can get it at
ftp://ftp.ee.fhm.edu/pub/unix/ide/libs-example.tar.gz


testcxxx: contains a libmathe.a (static old-fashioned lib)
testcxxx1: contains a libmathe2.a and libmathe2.la (static libtool lib - 
which uses the function of libmathe.a)
testcxxx2: an application which uses a function of mathe2

don't forget: testcxxx and testcxxx1 have to be installed first before 
using testcxxx2.

Hope this makes it clear...
Ciao

Walter



-
to unsubscribe from this list send an email to kdevelop-request at kdevelop.org with the following body:
unsubscribe »your-email-address«



More information about the KDevelop mailing list