Note that there are some explanatory texts on larger screens.

plurals
  1. POMixed language statically linking with gfortran and gcc
    primarykey
    data
    text
    <p>I have some code written in C and Fortran that I want to compile into a statically-linked executable. If I compile the code dynamically (using the <code>-fno-underscoring</code> option for gfortran), it all works fine. However, I want to link it into a .so file, statically linking most of the needed libraries, and then link dynamically to <code>libkrb5</code>, very much like the method described in <a href="http://stupefydeveloper.blogspot.com/2008/06/gcc-statically-linked-shared-library.html" rel="nofollow noreferrer">this blog post</a>.</p> <p>I followed the steps in the previous blog post, and I managed to compile the .so library without any problems. <code>nm</code> shows that it is in good shape, with my Fortran subroutines and C functions showing up:</p> <pre><code>[...]001020b9 T turnover [...]000d31ea T initio </code></pre> <p>The first function is written in Fortran, and the second in C. They don't have underscores or anything, so they should link. My main program (in Fortran) is compiled like the other Fortran source files. When I try to link, though, I get an error:</p> <pre><code>gfortran -m32 main_program.o -o program_static -L./ -llibname -lkrb5 -lgssapi_krb5 -lsasl2 -lgfortran /usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/crt1.o: In function `_start': /build/buildd/glibc-2.9/csu/../sysdeps/i386/elf/start.S:115: undefined reference to `main' </code></pre> <p>collect2: ld returned 1 exit status</p> <p>In <code>main_program.o</code>, I can see that there's </p> <pre><code>00000000 T MAIN__ </code></pre> <p>Everything looks in order, so why is it not linking?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload