Reputation: 4337
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!
Upvotes: 4
Views: 4338
Reputation: 2609
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
Upvotes: 0
Reputation: 4337
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
Upvotes: 2
Reputation: 28390
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.
Upvotes: 3