Reaction score: 7,698
It depends on your definition of a Linux API call. If you mean kernel API call, then most likely no. The kernels are quite different. If you're talking about C library API calls, then yes, it will likely compile. Although the C libraries aren't 100% source compatible, Linux may have some functions that FreeBSD doesn't and visa versa. Some calls can also respond a little different or require different arguments.If you use Linux's system call API or other Linux API's Documentation to write a C/C++/Assembly source code ... will the code compile and link/run under FreeBSD ?
#ifdefconstructs. Just look at the number of ports in our ports tree. Most applications are written and developed on Linux and compile just fine with FreeBSD.
FreeBSD can execute Linux binaries using the Linux ABI layer: Chapter 10. Linux® Binary CompatibilityHow about the executable files?
Yes, but this has little to do with execution, it's just a way to store an executable. See elf(5).Both systems use elf right ?
Reaction score: 222
In general, you'll be quite safe if you limit yourself to functions that are part of the standard C library or a POSIX specification. Compile withAlthough the C libraries aren't 100% source compatible, Linux may have some functions that FreeBSD doesn't and visa versa.
-std=c11 -pedanticand use feature defines where you need POSIX functionality (e.g.
#define _POSIX_C_SOURCE 200112Lbefore any
#includes in a source file that needs a function from POSIX.1-2001 or earlier) to make the compiler reject anything else and possibly platform-specific.