kripken/emscripten — Issue #257: can't use .a archives in emcc
Author: paleozogt
Created: 2012-02-15 23:11:14+00:00
State: open

When linking .js files, emcc can't handle .a archives. While you can link a series of .o files into a .js file, if those .o files have been archived together into a .a, emcc breaks. Archives of .o files are a pretty common output of many open-source toolchains.

```
$ls -l
total 8
-rw-r--r-- 1 40 2012-02-15 17:56 test1.c
-rw-r--r-- 1 40 2012-02-15 17:56 test2.c
$
$cat test1.c test2.c
int test1_func(int val) {
return 0;
}
int test2_func(int val) {
return 0;
}
$
$emcc test1.c -o test1.o; emcc test2.c -o test2.o
clang: warning: argument unused during compilation: '-nostdinc++'
clang: warning: argument unused during compilation: '-nostdinc++'
$
$emar r libtest.a test1.o test2.o
/home/asimmons/installs/bin/llvm-ar: creating libtest.a
$ls -l
total 20
-rw-r--r-- 1 1254 2012-02-15 18:00 libtest.a
-rw-r--r-- 1 40 2012-02-15 17:56 test1.c
-rw-r--r-- 1 520 2012-02-15 18:00 test1.o
-rw-r--r-- 1 40 2012-02-15 17:56 test2.c
-rw-r--r-- 1 520 2012-02-15 18:00 test2.o
$
$emcc test1.o test2.o -o libtest.js
$
$emcc libtest.a libtest.js
/home/asimmons/installs/bin/llvm-nm: '/tmp/tmpt0vFEo/libtest.o': No such file
/home/asimmons/installs/bin/llvm-nm: /tmp/tmpt0vFEo/libtest.o: unrecognizable file type
/home/asimmons/installs/bin/llvm-nm: '/tmp/tmpt0vFEo/libtest.o': No such file
/home/asimmons/installs/bin/llvm-nm: /tmp/tmpt0vFEo/libtest.o: unrecognizable file type
Traceback (most recent call last):
File "/home/asimmons/emscripten/emscripten/emcc", line 562, in
shutil.move(in_temp(unsuffixed_basename(input_files[0]) + '.o'), in_temp(target_basename + '.bc'))
File "/usr/lib/python2.6/shutil.py", line 264, in move
copy2(src, real_dst)
File "/usr/lib/python2.6/shutil.py", line 99, in copy2
copyfile(src, dst)
File "/usr/lib/python2.6/shutil.py", line 52, in copyfile
fsrc = open(src, 'rb')
IOError: [Errno 2] No such file or directory: '/tmp/tmpt0vFEo/libtest.o'
```