Note that there are some explanatory texts on larger screens.

plurals
  1. POGCC 4.5 vs 4.4 linking with dependencies
    primarykey
    data
    text
    <p>I am observing a difference when trying to do the same operation on GCC 4.4 and GCC 4.5. Because the code I am doing this with is proprietary, I am unable to provide it, but I am observing a similar failure with this simple test case.</p> <p>What I am basically trying to do is have one shared library (libb) depend on another shared library (liba). When loading libb, I assume that liba should be loaded as well - even though libb is not necessarily using the symbols in liba.</p> <p>What I am observing is when I compile with GCC 4.4, I observe that the liba is loaded, but if I compile with GCC 4.5, libb is not loaded.</p> <p>I have a small test case that consists of two files, a.c and b.c . The contents of the files:</p> <pre><code>//a.c int a(){ return 0; } //b.c int b(){ return 0; } //c.c #include &lt;stdio.h&gt; int a(); int b(); int main() { printf("%d\n", a()+b()); return 0; } //test.sh $CC -o liba.so a.c -shared $CC -o libb.so b.c -shared -L. -la -Wl,-rpath-link . $CC c.c -L. -lb -Wl,-rpath-link . LD_LIBRARY_PATH=. ./a.out </code></pre> <p>This is my output with different versions of GCC</p> <pre><code>$ CC=gcc-4.4 ./test.sh 1 $ CC=gcc-4.5 ./test.sh /tmp/cceJhAqy.o: In function `main': c.c:(.text+0xf): undefined reference to `a' collect2: ld returned 1 exit status ./test.sh: line 4: ./a.out: No such file or directory $ CC=gcc-4.6 ./test.sh /tmp/ccoovR0x.o: In function `main': c.c:(.text+0xf): undefined reference to `a' collect2: ld returned 1 exit status ./test.sh: line 4: ./a.out: No such file or directory $ </code></pre> <p>Can anyone explain what is happening? Another extra bit of information is that ldd on libb.so does show liba.so on GCC 4.4 but not on GCC 4.5.</p> <p><strong>EDIT</strong></p> <p>I changed test.sh to the following:</p> <pre><code>$CC -shared -o liba.so a.c $CC -L. -Wl,--no-as-needed -Wl,--copy-dt-needed-entries -la -shared -o libb.so b.c -Wl,-rpath-link . $CC -L. c.c -lb -Wl,-rpath-link . LD_LIBRARY_PATH=. ./a.out </code></pre> <p>This gave the following output with GCC 4.5:</p> <pre><code>/usr/bin/ld: /tmp/cc5IJ8Ks.o: undefined reference to symbol 'a' /usr/bin/ld: note: 'a' is defined in DSO ./liba.so so try adding it to the linker command line ./liba.so: could not read symbols: Invalid operation collect2: ld returned 1 exit status ./test.sh: line 4: ./a.out: No such file or directory </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    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