Development for Linux on FreeBSD

Hi all!
Could you share your experience and advice on how easy it is to develop and test C++ software for Linux using FreeBSD? I'm new to FreeBSD. What tools should I consider?
I've read the documentation, compatibility tools, and virtual environments (jails). But I'd like to hear from real users.
Sorry if it's a stupid question (My First Steps in FreeBSD).
 
I compiled a World of Warcraft server with Clang on FreeBSD no problem, similar to Clang or GCC on Linux or Clang or MSVC on Windows (it uses cmake).

Without any CXX flags, it built and performs fastest on FreeBSD (vs Linux/Windows LLVM/Clang). FreeBSD I used LibreSSL instead of OpenSSL which was kind-of cool :D (I like building it differently :p)
 
I compiled a World of Warcraft server with Clang on FreeBSD no problem, similar to Clang or GCC on Linux or Clang or MSVC on Windows (it uses cmake).

Without any CXX flags, it built and performs fastest on FreeBSD (vs Linux/Windows LLVM/Clang). FreeBSD I used LibreSSL instead of OpenSSL which was kind-of cool :D (I like building it differently :p)

After your message I wanted to try compiling something on FreeBSD 😄
 
I think op asks an incomplete question. The question should be "can I develop user applications in C++ for linux, but under BSD? If a user app is doing standard libc stuff and maybe using a platform neutral framework then it really doesn't matter if they do the dev work in BSD. Just make sure to test it on linux too.

It's when developing system apps (apps that make use of syscalls, directly or indirectly) that the differences become clear.
 
Question is:

- do you want to develop applications that compile on Linux also?

- or do you want to crosscompile so that you can use the resulting binaries directly on Linux?
 
  • Like
Reactions: mer
"write c/c++ code to do something at application (not kernel level). It compiles and runs on X. Take same code and compile and run on Y".

Very different from "develop on X but cross compile hopefully to Y"
 
I have been writing portable C/C++ code on *BSD, AT&T and Linux hosts for decades -- and the short answer is: It depends on what kind of code you are writing. In "general" everything ports very smoothly between Linux and *BSD - and compiles using a simple make(1) or use cmake(1).

What's common between (all) the platforms are the linkable libraries and header files -- see what's installed under /lib and /usr/lib. If you plan to do GUI stuff you might want to research a bit -- but honestly most GUIs are really compiling and running on multi-platform these days.

You can use a common Development GUI to develop your code on (either) -- I have used Jetbrains CLION for many years on (FreeBSD and Linux), but there is also geany(1) which runs on Linux, *BSD and others. And yes you can run Microsoft VSCODE on both if you really want to? Old style programmers like me still use vi(1), vim(1) or whatever it's called -- others like their emacs(1). emacs(1) always felt too much VAX/VMS for me :-) ... but to each their own... CLION is (FREE) for non-commercial use these days -- see the jetbrains web site.

In any case... we have been coding like this for a VERY long time :-) -- you will be fine !

FOR EXAMPLE: everyone raves about Steam and Wine on Linux -- Wine was written SOLELY on *BSD platforms before it was eventually ported to Linux, compiled and run -- because... there was (NO LINUX)... literally !

[Edit - Correction] - this should really read "Wine was originally coded on (NON-LINUX) platforms because there was no LINUX." -- I was (ALSO) compiling Wine on AT&T Unix systems back in the day, but MAINLY on *BSD systems. Wine was actually compilable on a (ton) of other different platforms back in the day.
 
You can write *portable code* on FreeBSD but you must test it on Linux & any other platform you care about. If you write portable code, do read Henry Spencer's #ifdef considered harmful article! If you want to write code that uses linux specific features, you'll probably save time in the long run by developing it on Linux itself.
 
You can use zig to compile to a linux executable :

zig build-exe main.zig -target x86_64-linux-gnu

x@myfreebsd:~/TEST $ ls
main main.o main.zig

x@myfreebsd:~/TEST $ ./main
ELF binary type "0" not known.
sh: ./main: Exec format error
 
do you have any experience with (cross)compiling Linux kernels in BSD?
Is there anything special to pay attention to?

When it comes to compiling a kernel - I build/compile my kernels on the hardware platform I am going to run/boot/execute it on. So Sorry, no, I don't have any experience with cross-compiling a kernel. Main reason (at the time.. maybe even "now") was to pickup the "CPU chip specific stuff" during the compile/link steps of kernel building. This is (maybe?) less important now... but I am old school :-).

[Edited - I was off topic on my original post]
 
to pickup the "CPU chip specific stuff" during the compile/link steps of kernel building
Usually any kernel source for a specific platform already has that specific stuff in it and in the the config. Since the kernel runs on bare metal, in theory, it can be compiled on any platform. However, as cracauer@ mentioned, nowadays Linux kernel source tree contains lot of scripts/utilities etc.
 
Usually any kernel source for a specific platform already has that specific stuff in it and in the the config. Since the kernel runs on bare metal, in theory, it can be compiled on any platform. However, as cracauer@ mentioned, nowadays Linux kernel source tree contains lot of scripts/utilities etc.

The kernel also has C-written programs that are compiled and run during the build. So pure crosscompilation is not possible without sorting that first. There might be variables for that already in the tree,
 
I have been writing portable C/C++ code on *BSD, AT&T and Linux hosts for decades -- and the short answer is: It depends on what kind of code you are writing. In "general" everything ports very smoothly between Linux and *BSD - and compiles using a simple make(1) or use cmake(1).

What's common between (all) the platforms are the linkable libraries and header files -- see what's installed under /lib and /usr/lib. If you plan to do GUI stuff you might want to research a bit -- but honestly most GUIs are really compiling and running on multi-platform these days.

You can use a common Development GUI to develop your code on (either) -- I have used Jetbrains CLION for many years on (FreeBSD and Linux), but there is also geany(1) which runs on Linux, *BSD and others. And yes you can run Microsoft VSCODE on both if you really want to? Old style programmers like me still use vi(1), vim(1) or whatever it's called -- others like their emacs(1). emacs(1) always felt too much VAX/VMS for me :-) ... but to each their own... CLION is (FREE) for non-commercial use these days -- see the jetbrains web site.

In any case... we have been coding like this for a VERY long time :-) -- you will be fine !

FOR EXAMPLE: everyone raves about Steam and Wine on Linux -- Wine was written SOLELY on *BSD platforms before it was eventually ported to Linux, compiled and run -- because... there was (NO LINUX)... literally !
Wow, I didn't know about Wine, very interesting!
Thanks for such a detailed answer. I use Vim for development, so I have no problems with the code editor. I was especially interested in how convenient it is to live on FreeBSD and write programs for Linux. It's great to get so much feedback, thank you all! :D
 
You can use zig to compile to a linux executable :
For C and C++, the ZigCC is also very capable of producing a linux, windows, macOS binary from an alternative host. ZigCC is basically clang with a bunch of different platform libraries already pre-bundled in. Its how a cross-compiler *should* be packaged.

The FreeBSD ports plist is generated / recursive but the OpenBSD's port is useful to show the supported platforms.
 
FOR EXAMPLE: everyone raves about Steam and Wine on Linux -- Wine was written SOLELY on *BSD platforms before it was eventually ported to Linux, compiled and run -- because... there was (NO LINUX)... literally !

Quick correction - this should really read "Wine was originally coded on (NON-LINUX) platforms because there was no LINUX." -- I was (ALSO) compiling Wine on AT&T Unix systems back in the day, but MAINLY on *BSD systems. Wine was actually compilable on a (ton) of other different platforms back in the day.
 
(A LOT) has changed with C/C++ compilers and operating systems since 1991/1992. Yeah back then I read that article too - but C/C++ coding is a lot different now in (this century).
Looks to me like you can still find plenty of #ifdef harmfulness this century:
One curious thing of note is that there were 40,000 lines of optimized
crypto implementations pulled out of the Linux kernel compat module but
not really wired up correctly, and mangled beyond repair with mazes of
Linux→FreeBSD ifdefs.
 
Back
Top