Compiling apache modules for Windows and Linux distros - linux

I have written an Apache2 module in C, now I am at the point of distributing the module.
I am not sure of the standard practices regarding the distribution of Apache modules, so I am considering to provide binaries for some of the more common platforms, like Windows and Ubuntu, etc.
I have two questions to ask-
Will the module compiled on my Linux distro (Ubuntu 10.04) will be able to run on other Linux distros as well ? (I only have one machine so can't test it). By the way the compiled module is a shared object file.
I couldn't find any reference or guide on how to compile apache modules on windows, so it would be very kind of you if you could give some heads up regarding this .
Thanks.

The answer is...possibly. If the apache module and the other system were compiled with a similar version of gcc then everything should be fine. If they are not the same then there is a chance for problems. It depends on the gcc version, and the options you passed in to gcc for compilation.
Someone else would be more qualified to go into specifics of how to make a binary more portable between distros.
CMake is a very popular tool for compiling C code that works in windows. http://www.cmake.org/cmake/resources/software.html. You should be able to install it with apt-get.

Related

Basic set of libraries in chroot (fedora linux)

I'm running an old version of my linux distro (fedora, but this is not very relevant) and for reasons which are completely irrelevant I'm not in a position to update it. However I do need a newer version of gcc and some other libraries than those supplied by my old distro.
I could compile a newer gcc and all the other libraries of course but I thought the simplest way would be to install a minimal set of packages from the latest distro version to a directory and then just chroot there. This way I'd take advantage of the binary packages present in the newest distro and all the infrastructure around it (like dependency installation, etc.) and I wouldn't need to compile everything from source.
My question is this: if I only would like to be able to compile with the most recent gcc and run those programs, what is the minimal set of packages I need? Since we are talking about fedora, what is the minimal set of rpms (beyond glibc and gcc)? Note that I don't need any X environment, networking, or anything like that, only the most basic terminal tools.
The minimal set varies depending on your user needs and what you're linking with. What I do when making a chroot environment is have a look at the distro I want to chroot and see if they have a base rpm/deb package that kickstarts everything. Then I install that in the chroot. From there I add libraries and applications as needed.
For an example where I create a chroot for RHEL on Arch see http://www.zenskg.net/wordpress/?p=267

Cygwin MinGW package vs. standalone MinGW

I would like to have a POSIX environment in Windows (to be used as a system shell) and at the same time produce native Windows executables. One option in the past was to install Cygwin and MinGW and possibly call MinGW compiler binaries from Cygwin.
Now an x64 MinGW is available straight as a Cygwin package and there are some blogs documenting how to get them play nicely together.
Before adopting this solution, I would like to know how and if the Cygwin package is different from a standalone MinGW-w64. Specifically which one is more efficient in producing native Win64 exe's? Is Cygwin package itself based on native executables, or is an extension to its gcc compilers?
Update
Some of you miscomprehended this question:
I am not interested in the difference between Cygwin and MinGW at all.
(and by the way, on the very home page of MinGW their main concern is to show how they differentiate from Cygwin)
My question instead is very specific: I am interested in the difference between a specific Cygwin package and its standalone version.
This package happens to be "mingw64-x86_64", which is split in several dependencies files, of which the most relevant is perhaps "mingw64-x86_64-gcc-core".
Sorry, but references found in some comments are utterly wrong with respect to what is asked here: first they address to Cygwin as a whole and not the mentioned package; secondly they refer to a rather old MinGW version, significantly different from that mentioned here (see here for the differences).
Someone also mentions MSYS2, which is a modern Cygwin fork, but again I am not interested to Cygwin (as whole), but to the said package.
Some of you might not be aware of this package, and in fact, if you google for "mingw64-x86_64", you don't find anything relevant for the Cygwin package, and most likely land on the general version, and this is why I am posting here.
TL;DR: Install Cygwin and the package mingw64-x86_64-gcc-core.
if the Cygwin package is different from a standalone MinGW-w64
They are the same.
MinGW - this is the project that can be found at mingw.org and
sourceforge.net/projects/mingw. This project has been superceded by the MSYS2
and MinGW-w64 projects.
Cygwin environment - Unix-like environment, namely Bash.
Cygwin compilers - these are the packages gcc-core and cygwin32-gcc-core
which include the files x86_64-pc-cygwin-gcc.exe and
i686-pc-cygwin-gcc.exe. These compilers create programs that rely on
cygwin1.dll.
MSYS2 environment - Unix-like environment, namely Bash. This is an
update to the MSYS environment provided by the old MinGW project.
MinGW-w64 compilers - these are the packages mingw64-x86_64-gcc-core and
mingw64-i686-gcc-core which include the files x86_64-w64-mingw32-gcc.exe
and
i686-w64-mingw32-gcc.exe. These compilers create Windows native
programs that do not rely on cygwin1.dll.
What do the C compilers on Cygwin generate?

How can I compile php-cgi binary using a custom glibc for suse enterprise linux out of cygwin?

Pretty straight to the point I think. Is this do-able?
Background: I'm doing this because I need to run php-cgi on suse enterprise 9 and can't get LD_PRELOAD or LD_LIBRARY_PATH to use other-than-system version of glibc.
php-cgi: /lib/tls/libc.so.6: version `GLIBC_2.7' not found
I downloaded 2.7 from here
http://rpmfind.net/linux/rpm2html/search.php?query=libc.so.6(GLIBC_2.7)
more precisely
ftp://rpmfind.net/linux/sourceforge/r/ro/roblinux/64-32_pkg/core/i686/glibc-2.7-2rt.i686.rpm
and unpacked it using rpm2cpio.
I need php-cgi because I can't install php and want to try JavaBridge for running php out of tomcat.
How can I compile php-cgi binary using a custom glibc for suse enterprise linux out of cygwin?
Pretty straight to the point I think.
No, a very confused and circuitous question.
First, cygwin has absolutely nothing to do with your question: it's for running UNIX programs on Windows, which is not at all what you are asking about.
Second, your question appears to be: "how do I run pre-build php-cgi binary on a system that has older glibc than the one php-cgi has been built on?", and not about compiling anything.
To that question, the answer is: you can't (easily) -- UNIX systems do not support forward binary compatibility (build on a new system, run on an older one). Only backward compatibility is supported (old dynamically-linked binaries continue to run on newer systems).
Your best approach is to try to build php-cgi on your system (which would eliminate its dependency on GLIBC_2.7. If you can't, you should still be able to run such a binary against unpacked glibc-2.7 build, if that binary doesn't re-exec itself. The way to do that, assuming you unpacked glibc-2.7 into e.g. /tmp/glibc-2.7 is something like:
/tmp/glibc-2.7/lib/ld-linux.so.2 --library-path \
/tmp/glibc-2.7/lib:/lib:/usr/lib \
/path/to/php-cgi <args>
(The library path above may need some adjustments to make the loader find all the required libraries.)
Update:
is it practical to compile stuff for my linux box in cygwin
It is possible, but significantly more pain then simply compiling on the linux box itself (and so isn't really practical). You appear to lack any reason to want to do that, other than mis-guided belief that cygwin solves all problems.

Compile for CentOS on Ubuntu

Can I install an older version of gcc/g++ (4.1.3) on the latest Ubuntu (which comes with 4.4.3) and use it to compile a .so which should run on CentOS? The binary compiled with the Ubuntu version of gcc fails to load on CentOS because of missing imports (GLIB_2_11, ...). I need C++ (including exceptions), so I can't just statically link against glibc, which I already tried.
Can I install the older gcc without removing the newer one? How do I go about the libs required by the older gcc?
I'm currently developing code in CentOS, but it's such a pain to use. I really want to move to an Ubuntu desktop.
g++-4.1 is available for Ubuntu; just run apt-get install g++-4.1 then run g++-4.1 instead of g++. However, simply using an older compiler may not fix all of your library issues.
Like Joachim Sauer said, your best bet is to do your development on Ubuntu then do the final compilation on CentOS.
Even though you're using C++, static linking should still be an option. (However, you're much better off compiling on CentOS and using dynamic linking.)
Edit: A virtual machine is the most straightforward way to build on CentOS, but if you want to avoid the memory and CPU overhead of running a VM and don't care about differences between Ubuntu's and CentOS's kernel, then you can create a subdirectory containing a CentOS or Fedora filesystem and chroot do that to do your builds. This blog posting has details.

How do I use cygwin to cross compile to linux, when I have an application that needs libX11.so, libGL.so, and libGLU.so?

Will I have to use the crosstool that cygwin provides to make the libX11.so, libGL.so, and libGLU.so libraries using their respective source code? Or do you know where I can find them compiled already for crosstool (I'm new to this cross compilation)?
Just for clarification: I'm on a windows 7 machine trying to get my application also to compile for linux systems by using cygwin's cross compilation. The application uses OpenGL. Thanks
To cross-compile for Linux you should install the needed development libs and headers on a linux box[1] and then copy /usr/lib and /usr/include your cygwin environment (e.g. /crosscompiler/linux/...). When you build the cross compiler in cygwin, tell it where those native linux headers and libs are so they'll be used when you compile your app.
[1] If you're looking to run on a wide variety of linux boxes make sure you pick an older linux distro (e.g. Red Hat 9) to ensure your app doesn't have dependencies on very new glibc, etc..
Why do you want to use Cygwin?
There is instructions on the OpenGL Wiki about how to use OpenGL on Windows using MinGW.
MinGW use the same GNU tools that are available on Linux (GCC, GDB, GMAKE, etc.) but produce Windows native executables. So, you shouldn't have trouble compiling your source code on both platforms.
I just ended up building on a native Linux machine.

Resources