Vijay Rajanna
Vijay Rajanna

Reputation: 41

Queries on Cross compiling, from Windows to Linux and from Linux to Windows,

I am working on a C, project which uses ffmpeg library. Currently I'm working on windows platform, and I'll be cross compiling the project for Linux ARM. With that background, I have few basic questions.

  1. If I use ANSI C++, I can be sure that, I'll be able to cross compile the project using corresponding compilers [ MSVC, MingW ]

    But ..

  2. If I'm using "Win32" and other "Windows" specific APIs in my project, how does the cross compiler will handle it, to make the project able to run on Linux.

  3. Similarly, If I'm using Linux specific "features" in my project, how does the cross compiler will handle it, to make the project able to run on Windows.

Upvotes: 2

Views: 233

Answers (2)

sashoalm
sashoalm

Reputation: 79665

If you use Winapi, your project will not be able to run on Linux.

Upvotes: 1

bdonlan
bdonlan

Reputation: 231373

When you cross-compile, the code that is being cross-compiled must use APIs that are available on the target platform (ie, the one that it will eventually run on). A cross-compiler does not magically give access to Win32 APIs when its output is run on a Linux machine; it is the same as compiling the code on the target machine, but means you don't need to actually do so. You could achieve the same thing, in other words, by just running a native (non-cross) compiler on an ARM Linux box, but you'd need a powerful enough ARM box to run the compiler.

That said, in principle, you could cross-compile to Linux while using winelib to provide win32 APIs. Not sure how well it works on ARM though - it's only really meant to be used on x86.

Finally, note that cross-compiling tends to be quite complex even in the best of times. It may make your life simpler to cross-compile from x86 Linux to ARM Linux instead of x86 Windows to ARM Linux - while it's possible to do cross-OS and cross-platform builds, the less variables you have changing the simpler things will be.

Upvotes: 2

Related Questions