2

This might be an Android specific question, I don't know.

I have a .a file that is the result of build (The V8 build to be specific). From here, I thought that .a files were 'archives' and thus contained the relevant bits from the object files. Since I assumed they were archives, I moved them to another machine for my Android specific build. However, when I attempt to build an android native library, I get the following error:

error: cannot open /data/v8_3_26/out/android_arm.release/obj.target/v8_base.arm/src/api.o: No such file or directory

If I explicitly copy the .o files (and put them in the hard-coded path shown above) my Android build works fine. So I have a few questions.

  1. Is this just an Android specific thing, or do .a files just reference .o files in general?
  2. Can I create a .a file that actually contains the relative bits from the .o files?
  3. If not, do I really have to put the .o files in the same place they were on the build machine, or can this be specified during the linking step?

1 .o files vs .a files

Community
  • 1
  • 1
irbull
  • 2,490
  • 2
  • 20
  • 28
  • I'm not sure, but if I had to guess, I would say that your build configuration for the android native library is configured to look for individuals object files, instead of the static library (.a file). You need to look into those configuration files to make sure it looks to link to the static library and not individual object files. – Mikael Persson Jul 29 '14 at 00:24
  • `ar -rcs MyLib *.o` will archive all files you need. If your .a file does not contain the right .o files, extract it and rebuild it with the .o file. This happens for instance if the .a file does not belong to the project that built it. Example: Linking against libpng.a requires you to also have libz.a (contains all .o dependencies for libpng).. To get them into one, you extract both and rebuild the archive. This can also happen with GDI, WinAPI, etc.. Your compiler will not copy .o files from within other .a files, into yours. – Brandon Jul 29 '14 at 00:58
  • possible duplicate of [Android NDK linking V8 static library: cannot find symbols, but they are there](http://stackoverflow.com/questions/24279237/android-ndk-linking-v8-static-library-cannot-find-symbols-but-they-are-there) – irbull Jul 29 '14 at 06:35

1 Answers1

2

This is actually a duplicate of this question. However, I will give a bit more information here.

According to ar documentation, archive files (.a files) can be normal or thin. In the case of 'thin', the archives don't actually contain the contents of the archived files.

Instead, when a .a archive is a thin archive, it contains a symbol index and references to the original copies of the member files of the archive.

In the case of the V8 build, the archives are thin and thus don't contain the object files. This is why they are needed by ld when the linker runs.

Community
  • 1
  • 1
irbull
  • 2,490
  • 2
  • 20
  • 28