compile problems: .mod files and libraries 
Author Message
 compile problems: .mod files and libraries

Hello all,

I'm not sure how fortran-related my question is... but it has
also something to do with module-files so I guess it's
appropriate here...

I currently have a project which has among others these directories:

$(ROOT)/src
$(ROOT)/clientcode

The source code in the src directory contains the source for a
library that I'm writing.  The clientcode directory contains code
that actually *uses* the library.

My current module and library setup is the following:

* all library code gets compiled to the src directory.  The
  object and module files are placed into this directory
  and also the libary file libmylib.a

* All the `client-programs' under the clientcode directory have
  at the beginning the statement

    use mylib

* To compile the `client-program' code in the clientcode directory,
  I simply add the compile-flags -I../src and -L../src and this works
  fine for all the compilers that I use.

However, I would now like to remove the clientcode programs from
the $(ROOT) directory as in essence they have nothing to do with
the library, they only *use* the library.  Should I one day
decide to make my library available, then the code from the
clientcode directory shouldn't be part of the library and the
files that i make available.

So now I want to test if i can 'install' the library somewhere
and let the client-programs use it.  What I do is the following:

* I compile the library under the $(ROOT)/src directory and
  place the file libmylib.a somewhere inside
  $(HOME)/lib or something.

* I have a `client-program' in for example $(HOME) (or any other random place)
  and this program uses my library, it has

    use mylib

  in the beginning of the program.

* Of couse, trying to compile the program with

    $(FC) test.f95

  does not work.  So i tried

    $(FC) -L$(HOME)/lib test.f95 -lmylib

  but then I still get an error that 'module MYLIB' cannot be
  found.  If I specify

    $(FC) -L$(HOME)/lib -I$(ROOT)/src test.f95 -lmylib

  then i get a clean compilation... because the .mod files are
  found under the $(ROOT)/src directory.  This however rises some questions
  for me:

1) Say you add a 'make install' in your Makefile.  Is it then
always necessary to copy the .mod files to some directory and
also ship them with your installation?  Just as you would also
install C/C++ header files somewhere?

2) Is it possible to work with *only* libmylib.a and *not* copy the module
files to some installation directory.  Maybe then add the module information
somehow in the archive, so that all you need to do is tell the compiler to look
for the object and module files in the archive libmylib.a?

3) Module files are different for different compilers... so
should it be unavoidable to also copy the module files, then I
have to add the module files for every possible compiler???

So basically what i want to do is to let user-space programs that
have nothing to do with the library use that library by
specifying a `use' statement and linking with the library... but
do i always need module files for that or can i live without them?

Thanks,
Bart

--
        "Share what you know.  Learn what you don't."



Tue, 04 Aug 2009 20:59:39 GMT  
 compile problems: .mod files and libraries

Quote:
> 1) Say you add a 'make install' in your Makefile.  Is it then
> always necessary to copy the .mod files to some directory and
> also ship them with your installation?  Just as you would also
> install C/C++ header files somewhere?

As long as you want to USE the modules, yes.

Quote:
> 2) Is it possible to work with *only* libmylib.a and *not* copy the module
> files to some installation directory.  Maybe then add the module information
> somehow in the archive, so that all you need to do is tell the compiler to look
> for the object and module files in the archive libmylib.a?

It is, in principle, possible to archive .mod files into libmylib.a.
This would require the compiler to be able to search available .a
archives for .mod files. AFAIK, no compiler has such an option.

Quote:
> 3) Module files are different for different compilers... so
> should it be unavoidable to also copy the module files, then I
> have to add the module files for every possible compiler???

yes. But that makes not much difference, since a library compiled with
one compiler is unlikely to work with other compiler, unless you also
provide the creator's RTL and it does not conflict with the user's
RTL. I think this is the same for C++.

Quote:
> So basically what i want to do is to let user-space programs that
> have nothing to do with the library use that library by
> specifying a `use' statement and linking with the library... but
> do i always need module files for that or can i live without them?

You can choose a little more portable approach - USE association
instead of host association, make subroutines external, make the
modules contain only constants, type definitions, and interfaces,
and distribute them as sources. In this way you get sth. similar to C
headers. Nevertheless, mixing compilers remains a problem due to RTL
conflicts.


Tue, 04 Aug 2009 22:38:08 GMT  
 compile problems: .mod files and libraries

Quote:

>> [...]
>> 3) Module files are different for different compilers... so
>> should it be unavoidable to also copy the module files, then I
>> have to add the module files for every possible compiler???

> yes. But that makes not much difference, since a library compiled with
> one compiler is unlikely to work with other compiler, unless you also
> provide the creator's RTL and it does not conflict with the user's
> RTL. I think this is the same for C++.
> [...]

OK.  After reading your answer I assume this is probably the best
way to do distribute my library:

* pack the whole project directory, including sources but without
  .o, .mod and .a files into a .tar.gz.

* Let the users download and unpack this .tar.gz.

* Let them make the necessary changes to the Makefile to set
  things like:
        - compiler
        - compiler flags
        - archiver
        - installation directory
        - ...

* Let them compile the code with their favorite Fortran compiler.

* Make sure the Makefile copies the .a library file and the .mod
  files to the installation directory.

* Let the users 'use' my library through a 'use' statement at the
  beginning of their programs and also let them know that they
  should specify the necessary compiler flags so that their
  compiler knows that it has to search for the .a file and the
  .mod files in the installation directory.

This approach seems flexible enough to me.  Only one quite
important thing: luckily I am an Open Source enthouisast so that the
very first step of packing the sources into the .tar.gz in step 1 is
possible... :-)

Best wishes,
Bart

--
        "Share what you know.  Learn what you don't."



Tue, 04 Aug 2009 23:06:49 GMT  
 compile problems: .mod files and libraries

Quote:


>>> [...]
>>> 3) Module files are different for different compilers... so
>>> should it be unavoidable to also copy the module files, then I
>>> have to add the module files for every possible compiler???
>> yes. But that makes not much difference, since a library compiled with
>> one compiler is unlikely to work with other compiler, unless you also
>> provide the creator's RTL and it does not conflict with the user's
>> RTL. I think this is the same for C++.
>> [...]

> OK.  After reading your answer I assume this is probably the best
> way to do distribute my library:

> * pack the whole project directory, including sources but without
>   .o, .mod and .a files into a .tar.gz.

> * Let the users download and unpack this .tar.gz.

> * Let them make the necessary changes to the Makefile to set
>   things like:
>         - compiler
>         - compiler flags
>         - archiver
>         - installation directory
>         - ...

You might want to look into autoconf and supply a configure utility that creates the
makefile based on envars the user sets (like compiler flags, etc). The user also specifies
the installation directory in the configure step. Typically the procedure goes like this:

./configure --prefix=<user's install-dir>
make         (builds the library and mods)
make test    (tests the library in-place)
make install (puts the library in install-dir/lib and the .mods in install-dir/include)

(no smart comments from Mr Kleb about where in the order the tests are/should be done!)

That's it. The user specifies all the necessary compiler flags (e.g. FC, FC_FLAGS, F90,
F90_FLAGS, etc, or whatever you want to call them as envars. There are a bunch of default
rules for what there are called.

Have a look at:
   http://www.gnu.org/software/autoconf/

One thing you don't want is to have users edit the makefile (not a hard and fast
rule...sometimes they have to; but it's really easy to break a makefile unless they are
aware of the usual gotchyas)

cheers,

paulv

--
Paul van Delst             Ride lots.



Wed, 05 Aug 2009 00:13:28 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. 'library' of .mod files

2. mod sound file editing library?

3. Fortran90 static library and .mod files

4. f90 mod files and library construction

5. Problem compiling with multi-threading library

6. Problems compiling with python libraries

7. Problems with Dynamic Library compiling on AIX 4.2 Python 1.5.2

8. Compiling Mod with folded elements ?

9. Compiling PHP CGI [not mod]

10. MOD Library ?

11. Link mod unable to find library...

12. MOD and /MOD with Pygmy Forth

 

 
Powered by phpBB® Forum Software