How to build X11 apps binary all *bsd compatible?

How to buid X11 small aplications which whoul be "binary crossplatform" at least whithin different FreeBSD wersions. In whoul be preferred to form one executable file. But also acceptable as a set file and additional libraries. (I can whrite an innstallation sh script).

I begin to code in wild unix world. In past I code microcontroller, win32, and sh. Simultaniosly I started C++ learnig.. whith some systematic approach, but my approach of learning the Unix X11 build techiques is anarhytic.

Though the coplilation I perform either if proof of comlecated envirements such as qt4, or by making not clear to me google founded patterns, and mixes of those patterns.

The fact, that the app I have buit whith qt4 in FreeBSD 7.2 dont work in 4.11 FreeBSD (do work - in 8.0) -- I expected. But the opposite fact, that the 4.11 builded application, assebled whith "pure" xlib libraries -- refuse to executes at 7.2 -- sad suprised me :(.

Source(first.c)

Code:
#include <X11/Xlib.h> // Every Xlib program must include this
#include <unistd.h>   // So we got the profile for 10 seconds

#define NIL (0)	   // A name for the void pointer
	 
 main()
{
	  int blackColor = BlackPixel(dpy, DefaultScreen(dpy));
	  int whiteColor = WhitePixel(dpy, DefaultScreen(dpy));
	  Display *dpy = XOpenDisplay(NIL);
	  Window w = XCreateWindow(dpy, DefaultRootWindow(dpy), 0, 0, 
				   200, 100, 0, 
				   CopyFromParent, CopyFromParent, CopyFromParent,
				   NIL, 0);
	  XMapWindow(dpy, w);
	  XFlush(dpy);
	  sleep(10);
}
Build command (It is not quite clear to me what I'm dooint and how I cat do it better)
Code:
сс -o -first.aut first.c -lX11 -L/usr/X6R11/lib -I /usr/X6R11/include
Binary, i got at 7.2, on 4.11 finaly has posted the message:
Segmentation Fault
same shit if built in 4.11 I tryed to execute in 7.2

What should I use to have binary crossplatform succses in such type of Х11 applications (they must be executable in all X window managers... like blackbox)?
 
Lomik said:
The fact, that the app I have buit whith qt4 in FreeBSD 7.2 dont work in 4.11 FreeBSD (do work - in 8.0) -- I expected. But the opposite fact, that the 4.11 builded application, assebled whith "pure" xlib libraries -- refuse to executes at 7.2 -- sad suprised me :(.
That's because there's only COMPAT_FREEBSD5, 6 and 7. There is no COMPAT_FREEBSD4.

Things change. Libraries change, so the ABI changes.
 
Hmm.. Never looked at it actually but you're right.

The OP is probably missing misc/compat4x.

But something that will never work is building for 7.x and running that on 4.x.
 
Perhaps Lomik is better off just building for 4 then? But really, is that wise? After all, 7 is a far superior product to 4...I think it would be wise to simply build for 7.
 
4.x and 5.x aren't supported anymore anyway. I guess the best option would be to build for 6.x. Both 7.x and 8.x can run 6.x binaries provided COMPAT_FREEBSD6 is build into the kernel (GENERIC has it) and misc/compat6x is installed.
 
You must realize that FreeBSD 4 and 7 are almost 10 years apart, with major architectural differences between them.

Nonetheless, it should be possible to run a FreeBSD 4 (& even older) executables on FreeBSD 7.
You will not be able to run a FreeBSD 7 executable on FreeBSD 4.

For FreeBSD 7, compatibility for FreeBSD 4, 5, and 6 are included in the GENERIC kernel, so unless you compiled a custom kernel with these options removed you don't need to do anything.

Next make sure you have the compatibility libraries installed, these are the correct versions of the shared system libraries for FreeBSD 4. You can't use the FreeBSD 7 libs since they changed to much.
To do this, simply install the compat4x package:
# pkg_add -r compat4x-i386

Another problem you may run into is mismatches with other 3rd-party shared libraries your app is using (i.e. libX11, libqt).
You can either install/copy these libraries on your FreeBSD 7 system, or make a statically compiled binary.
 
Thanx a lot to all.

Carpetsmoker said:
You must realize that FreeBSD 4 and 7 or make a statically compiled binary.
Somebody explain it for me. My programming background is still not enough for unix userland coding. //I have only simple embedded C/asm coding.
 
Most modern executables use dynamically loaded libraries. These libraries contain common functions like printf. Instead of each executable containing the same code by including all those functions, these functions are stored separately in a library, /lib/libc.so.7 i.e., and are loaded when the executable starts. Because the libraries changes between major versions of FreeBSD you will either need to load the compatible 'older' library versions or you need to statically link those libraries to the executable.

rtld(1)
http://en.wikipedia.org/wiki/Dynamic_linker
 
Back
Top