Solved I need to transfer project from Linux to FreeBSD and have a problem with compilation

Right now I get error that includes are not finded found:
Code:
#include <linux/if.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>
#include <linux/if_arp.h>
For which includes for FreeBSD should I replace those includes for Linux?
 
Don't know how compatible they are though, there are lots of implementation differences. So you may need to patch some of the actual code too.

Code:
root@molly:~ # cd /usr/include/
root@molly:/usr/include # find . -name 'if.h'
./net/if.h
root@molly:/usr/include # find . -name 'if_packet.h'
root@molly:/usr/include # find . -name 'if_ether.h'
./netinet/if_ether.h
root@molly:/usr/include # find . -name 'if_arp.h'
./net/if_arp.h
 
You could start to include ${SRC_TOP}/sys/compat/linuxkpi/common/include to the includes search path and use FreeBSD's Linux compatibilty layer. Some of the include files you need are there. To figure out the differences for the others is 90% transpiration, and 5% thinking & inspiration each.
EDIT I do not know if there are more include files in a full emulators/linux-c7 installation.
 
I mean: chances are you can isolate some parts of your software that can easily be ported to FreeBSD. And for the other parts, you can use FreeBSD's Linuxolator at runtime, and try to port them more slowly & thoughtful.
 
Thanks to all.
I mean: chances are you can isolate some parts of your software that can easily be ported to FreeBSD. And for the other parts, you can use FreeBSD's Linuxolator at runtime, and try to port them more slowly & thoughtful.
Could you give more information how to port project from Linux to freeBSD?

Can I compile project on a Linux OS for target freebsd?
I mean that I have project on Linux and need to compile it and those compiled .bin files I want to run on the freeBSD machine. Is it possible?
 
Could you give more information how to port project from Linux to freeBSD?
There is no "one-size-fits-all" tutorial covering this. You're going to need to do a lot of legwork yourself. And this starts by understanding how each system works.

Can I compile project on a Linux OS for target freebsd?
I mean that I have project on Linux and need to compile it and those compiled .bin files I want to run on the freeBSD machine. Is it possible?
This tells me you have zero experience compiling anything. Let alone porting something from one system to another.
 
I have no any expierence with Linux system and ask you to help me to decide problem with transfer project on the Linux to freeBSD.
If you can help, make it, pls, if no- I'll be find the way how to decide it.
 
Standard disclaimer: install the docs: pkg install {de,en}-freebsd-doc, replace de with your native tongue, and point your favorite browser to /usr/local/share/doc/freebsd. There's a Porter's Handbook.
You can add to the ALIAS section of /usr/local/etc/pkg.conf
Code:
  message: "query '[%C/%n] %M'",
  rmessage: query -i "[%C/%n-%v] %M",
and read through all pkg message|less.
 
What kind of project is that, exactly?
It's some custom project for Linux (write on C). And I need to run this executable files on the FreeBSD.
I can compile this project on Linux but it will not works on the FreeBSD. I tried to compile it on the FreeBSD but there is no some specific libraries for Linux on FreeBSD. And I find any way to cross compile this project under Linux but target for FreeBSD. Is it possible?
 
It's some custom project for Linux (write on C). And I need to run this executable files on the FreeBSD.
What does it do?
I tried to compile it on the FreeBSD but there is no some specific libraries for Linux on FreeBSD.
This is where experience comes in. You need to have a good understanding of the code and how it works before you can attempt to port it. Think of it as asking a mechanic friend how to improve the performance of your car without understanding how an engine works. He can tell you but you're not going to understand it.

And I find any way to cross compile this project under Linux but target for FreeBSD. Is it possible?
That depends on the project and how it's set up. Sometimes you can but most of the time your going to need to patch the code. Again, this is where experience comes in, if you know and understand what the code does you will know exactly what needs to be changed.
 
Many Linux binaries can run as-is on FreeBSD. sysrc linux_enable=YES. For some you need to mount Linux proc, sys or /dev/shm (or all of these) filesystems. /etc/fstab:
Code:
linproc /compat/linux/proc      linprocfs rw                          0 0
linsys  /compat/linux/sys       linsysfs  rw                          0 0
tmpfs   /compat/linux/dev/shm   tmpfs     rw,size=8G,noexec,mode=1777 0 0
Linux libraries come with emulators/linux_base-c7 or the full-blown CentOS linux-c7
EDIT I.e. if it compiles & runs on CentOS 7 you can take that same executable and run on FreeBSD. (on the same architecture, e.g. amd64 aka x86_64)
 
What does it do?
"Custom project" is too vague for an answer.

It is just project wich sent some data to the remote server. It uses network IP connection. This is not my code and I just try to run it on freebsd system. I have source code for it and need to compile it for freebsd. In present time it is doesn't matter what project does. It uses some network libraries like in first post of this topic. If you need more detail of this, may be some libraries or more, I'll try to answer.

EDIT I.e. if it compiles & runs on CentOS 7 you can take that same executable and run on FreeBSD. (on the same architecture, e.g. amd64 aka x86_64)
Do you mean that possible to compile it on the centOS and try to run on freeBSD?
 
You need to have a good understanding of the code and how it works before you can attempt to port it
I really don't know very well how this code works. For me, I need compile it and run on freeBSD. I know, this code sends some data to the server.
 
You can always look at the existing code for "sending data" in the ports collection . Any ftp or tftp implementation in the ports for instance.
 
I know, this code sends some data to the server.
That's still too vague to make a proper assessment of the work that may need to be done.

Does the code compile and work on CentOS 7? Or does it require something like a recent Ubuntu? If it compiles and runs on CentOS 7 then I would take the route mjollnir suggested. Just run the Linux executable on the Linux Compatibility Layer.
 
Does the code compile and work on CentOS 7? Or does it require something like a recent Ubuntu? If it compiles and runs on CentOS 7 then I would take the route @mjollnir suggested. Just run the Linux
I'll try to compile it on the centOS and Ubuntu and will give answer tomorrow.
Thanks all for help.
 
Do you mean that possible to compile it on the centOS and try to run on freeBSD?
Long story short (answer from Radio Yerevan): Yes, BUT if it needs some exotic library that you can not find in any of the linuxXYZ-c7 ports/packages, then you'll have to use archivers/rpm4 to install them and I strongly suggest to set up a Linux jail inside your FreeBSD host for that. Build your project on a "real" CentOS 7. Do not compile in a standard Linux jail. That would need a special setup. It's possible, though. CentOS 7 in a bhyve(8) VM should be fine.
 
Build a cross compiling toolchain on Linux so you can build Linux and FreeBSD binaries from the same Linux machine.
Perfectly possible, I do it the other way around to create Linux binaries on my FreeBSD machine. Won't solve the original problem with headers though, you can't just use a Linux system header with a cross-compiler targeting FreeBSD.
 
  • Like
Reactions: a6h
It is just project wich sent some data to the remote server. It uses network IP connection. This is not my code and I just try to run it on freebsd system. I have source code for it and need to compile it for freebsd. In present time it is doesn't matter what project does. It uses some network libraries like in first post of this topic.
You still fail to answer what the actual purpose of the software is.

From the communication so far, I assume that this is some kind of “script kiddie” software used to break into a system.
 
You still fail to answer what the actual purpose of the software is.

From the communication so far, I assume that this is some kind of “script kiddie” software used to break into a system.
This is no hack software. This absolutely legal software. But this software from my work, for commercial project. Sorry, I can't due to NDA tell more about it.
And I don't know really more about this software. We write soft for OPNsense project. And I need that my software will works on this OPNsense platform.
I compiled my software for CentOS today and I want to try test it on the OPNsense.
 
In another words, I want to compile my soft for Ubuntu (CentOS) for OPNsense (FreeBSD). I need run this soft on the OPNsense platform.
 
Back
Top