开发者

Linking multiple times a single cross platform object file?

开发者 https://www.devze.com 2023-04-08 09:33 出处:网络
If I compile a cross-platform piece of code into an object file, will it be possible to use the linker to create separate platform-dependent execu开发者_开发百科tables (.exe,.bin) from that single bin

If I compile a cross-platform piece of code into an object file, will it be possible to use the linker to create separate platform-dependent execu开发者_开发百科tables (.exe,.bin) from that single binary file?

EDIT: It seems the answerers don't really understand my question. I'm asking if you can use a cross-platform object and generate platform-dependent executables from that.


That pretty much depends entirely on the linker and other development tools that you have. Certainly cross compilation is possible in an advanced environment like gcc, where you can generate object code for different architectures.

But packaging all those different-architecture objects into a single executable is not something I've ever seen done in gcc.

I've seen fat binaries on the Apple platforms (where an executable would run on the old 68K Macs or the newer PowerPC ones) but I've never really been a big fan of them and Apple was in total control of the environment there.

In addition, the loader code (part of the OS usually) has to be able to detect which architecture it should extract and run from such a fat binary (this is where Apple's control came in handy - they could modify their various operating systems to detect and load the correct version).

Personally, I think you'd either be better off using a portable language (Java, Perl, Python et al) or packaging your application into different binaries - you could always use one of the excellent cross-platform installation toolkits to install the correct version.


Based on your edit clarifying the question: yes. If the object files are truly cross-platform, they will work on all those platforms. So, by definition, you can construct a platform-specific executable based on that. Note that this is not the same as compiling some cross-platform source code since the compilation process itself will most likely lock it to a specific platform.

And, again, it depends on the tool chain being used (compiler, linker, loader, etc).


Fat binaries are supposed to be supported on linux as well, never tried however.

The FatELF page says they support static and dynamic libraries, their faq seems extensive.

0

精彩评论

暂无评论...
验证码 换一张
取 消