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!

1
  • 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. Commented Mar 2, 2014 at 7:06

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Also the library name should start with lib and you include only -fname if the library is called libname.a.
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

2 Comments

So Steve Barnes' suggestion did not work? I've been doing it that way, and it's worked for me.
I have to use this way also (only -l and not -L+-l). I'm on windows with version 2 of f2py.
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

1 Comment

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.