Closed
Description
I have two rust source files and one c source code file (see this gist).
I compile the code like this:
$ gcc -c function_arg.c -o /tmp/libcxx.a
# clang -c function_arg.c -o /tmp/libcxx.a
# using clang instead of gcc doesn't resolve the issue
$ rustc -o /tmp/libfoo.rlib function_arg.rs
$ rustc -L /tmp/ function_arg_run.rs -o /tmp/main
Most of the times I get this error:
$ rustc -L /tmp/ ././tests/function_arg_run.rs -o /tmp/main
tests/function_arg_run.rs:7:26: 7:36 error: unresolved name `foo::apply`.
tests/function_arg_run.rs:7 unsafe { println!("{}", foo::apply(double, 2)) }
^~~~~~~~~~
note: in expansion of format_args!
<std macros>:2:23: 2:77 note: expansion site
<std macros>:1:1: 3:2 note: in expansion of println!
tests/function_arg_run.rs:7:11: 7:50 note: expansion site
But sometimes the code compiles just fine.
The reason seems to lie in the rustc -o /tmp/libfoo.rlib function_arg.rs
command.
When I run into the "unresolved name" error, the /tmp/libfoo.rlib
has a size of 11012 bytes and does not contain the string "apply".
In the case where everything just compiles fine, /tmp/libfoo.rlib
is 4828 bytes and contains "apply" three times:
$ grep apply /tmp/libfoo.rlib --text --only-matching | wc -l
3
I do not change a single line in the source code but the compiler sometimes results in different output files, which is really strange.
I use these versions:
$ rustc -v
rustc 0.13.0-nightly (63c4f22f2 2014-11-05 22:31:44 +0000)
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.7.2-5' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.7.2 (Debian 4.7.2-5)
$ clang -v
Debian clang version 3.5.0-1~exp1 (trunk) (based on LLVM 3.5.0)
Target: x86_64-pc-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/bin/../lib/gcc/i486-linux-gnu/4.7
Found candidate GCC installation: /usr/bin/../lib/gcc/i486-linux-gnu/4.7.2
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.6
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.6.3
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.7
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.7.2
Found candidate GCC installation: /usr/lib/gcc/i486-linux-gnu/4.7
Found candidate GCC installation: /usr/lib/gcc/i486-linux-gnu/4.7.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6.3
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7.2
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.7
Candidate multilib: .;@m64
Selected multilib: .;@m64