4

I have a fortran program that uses some library files. I am trying to link them along with the module file being created.

The library file I am trying to link is called ulib.a and is located in the directory /home/replace/lib/

The command I am using is:

f2py -L/home/replace/lib/ -lulib.a -c main.f -m progs

I am getting the following error:

/usr/bin/ld: cannot find -lulib.a
collect2: ld returned 1 exit status
/usr/bin/ld: cannot find -lulib.a
collect2: ld returned 1 exit status

I would appreciate any help!

RagHaven
  • 4,156
  • 21
  • 72
  • 113
  • 2
    A static library is just a set of object files, so you can include directly as `f2py -c main.f /home/replace/ulib.a -m progs` or something like that. – michaelmeyer Mar 02 '14 at 07:06

3 Answers3

3

Try leaving off the .a - I am reasonably sure that the linker already knows that libraries are .a so in your example it will be looking for ulib.a.a and failing.

Steve Barnes
  • 27,618
  • 6
  • 63
  • 73
2

I had to remove the extension from the library name and also provide the full path. For some reason providing the path using the -L argument did not work.

f2py -l/home/replace/lib/ulib -c main.f -m progs
RagHaven
  • 4,156
  • 21
  • 72
  • 113
  • So Steve Barnes' suggestion did not work? I've been doing it that way, and it's worked for me. – amaurea Mar 03 '14 at 23:08
  • I have to use this way also (only -l and not -L+-l). I'm on windows with version 2 of f2py. – JohnE Mar 03 '15 at 21:12
0

The library should have the full name libxxx.a where xxx is the given name. Then do

f2py -L. -lxxx -c main.f90 -m progs

Note that only xxx comes after -l. If you create the library yourself remember to include -fPIC. For example, it could look like this:

gfortran -c -fPIC source1.f90 source2.f90
ar crs libxxx.a obj1.o obj2.o
f2py -L. -lxxx -c main.f90 -m progs

Found guidance in this example: https://modelingguru.nasa.gov/docs/DOC-2343

Jonatan Öström
  • 2,428
  • 1
  • 16
  • 27
  • Sorry, I don't think this is very useful. (1) the OP says the library is in a different folder, which must be referenced. (2) Beyond that, what is different about this answer compared to the current one? – Ross Jun 21 '18 at 14:43