Sunday, January 18, 2009

libf2c.so: undefined reference to `MAIN__'

Alright.. so problems with libf2c with debian, ubuntu, etc, getting too much of libf2c.so: undefined reference to `MAIN__'

ok, just link with the static library "libf2c.a"


sudo rm /usr/lib/libf2c.so && sudo ln -s /usr/lib/libf2c.a /usr/lib/libf2c.so


Done!

18 comments:

Riley Crane said...

Thank you! This was killing me...

Unknown said...

thanks, that was really helpful :)

Eugen said...

i would never figure it out by my own.

Thank you!

Pallab Basu said...

Thanks, Thanks and thanks.

Anonymous said...

how can you do this without root access?

HA said...

You're welcome everybody.. it was such a pain to figure it out!

Anonymous.. you can do the linking in your local directory and link against the library from there

For example

ln -s /usr/lib/libf2c.a ~/libf2c.so

This will place libf2c.so in your home directory (you can choose something else)

When you compile you should include that in your LD_PATH path

For example

gcc my_program.c -L~ -lf2c

I suggest creating a directory called mylib in your home folder and put your custom libraries there and permanently change the LD_LIBRARY_PATH to point there by default


mkdir ~/mylib
ln -s /usr/lib/libf2c.a ~/mylib/libf2c.so

in your .bashrc (csh is similar)

export LD_LIBRARY_PATH="$HOME/mylib":$LD_LIBRARAY_PATH

Good luck

Msalami said...

Thank yoooooooou soooooooooooooooo much. I was going to kill myself....
wish the best for you! ;)

Tim said...

Thanks! Why does none of the gcc documentation mention this?!

Anonymous said...

Thanks! In my case I didn't even have to link the .a to the .so, just removing the original .so link was enough.

Unknown said...

Thank you! I cannot even express how extremely helpful piece information this is for me. But I would be more than interested also why it's not working with shared library?

Anonymous said...

Thanks for pointing out the problem! Another fix, change the makefile, to link with f2c statically and with the rest dynamically, i.e.:
LAPACKLIBS=-llapack -lblas -Wl,-Bstatic -lf2c -Wl,-Bdynamic

Which is on line 18 in levmar 2.5, works just fine :)

Anonymous said...

You deserve a million thank yous...

Roger said...

Hello,

I tried doing this but it still gives me an error as -

/usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../../lib/libf2c.so(main.o): In function `main':
/build/buildd/libf2c2-20090411/main.c:138: undefined reference to `MAIN__'
collect2: ld returned 1 exit status

Can you plz help me with this?
Thanks in advance...

Laurie said...

I'm having exactly the same issue as Roger-- does anyone have any insight? Thank you!

Anonymous said...

Thank you!

Anonymous said...

Another big thank you!

Bruno Pinho said...

Hello from 2017 ¬¬

I am having this problem, but with the file - libf2c.so.2 - I don't know how to link it to the dynamic.

I created this thread:
https://stackoverflow.com/questions/45382324/dont-know-how-to-deal-with-a-f2c-error

This:

rm /usr/lib/libf2c.so.2 && ln -s /usr/lib/libf2c.a /usr/lib/libf2c.so.2

Didn't work.

Anonymous said...

with modern gcc you can just link like this

-l:libf2c.a

to link to the static library on your system