1

I am trying to compile GNU Coreutils as a set of shared libraries, instead of a set of executables. I thought that make would let me pass in a flag to tell it to do this, but from what I can see I would actually have to modify the configure.ac and Makefile.am in order to make this work. I would prefer not to do this, since this potentially introduces bugs into code that I can currently rely on being bug-free. I tried manually turning the object files into so's by entering:

make CFLAGS='-fpic'
gcc -shared -o ls.so coreutils/src/ls.o

I am able to create the so file, but there seem to be a number of flags that I am missing, and I don't see any way to access a list of necessary flags to compile and link the code (even though this information is clearly contained in the computer). The only thing I can think to do is manually go through all of the linker errors and try to figure out what flags are missing, but I'm hoping that there is a less tedious way of getting what I want.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Saff
  • 41
  • 5
  • 3
    What could possibly be the point of doing this? You can't just magically make a standalone program behave like a library by putting the code in a `.so` file. – R.. GitHub STOP HELPING ICE Jun 20 '15 at 02:15
  • At least, you have to worry about how you'll find/call the `main()` in each program's shared library. Normally, you have one function called `main()`. What about other name conflicts? You'll also need to worry about calling the `main()` correctly — does it rely on the `envp` argument (as in `int main(int argc, char **argv, char **envp)`)? Does it use other extra arguments? (Mac OS X has extra, extra arguments, I believe.) Zapping CFLAGS like you show is likely to be counter-productive; there are probably quite a lot of flags that you've removed from the compiler command lines by doing that. – Jonathan Leffler Jun 20 '15 at 02:21
  • Isn't there already a `coreutils-libs` package and the only file in there is `/usr/lib64/coreutils/libstdbuf.so`? Is this what you are attempting to make? – alvits Jun 20 '15 at 02:22
  • @jonathonI I'm trying to plug these into GNU Guile, which gives me the facilities needed to specify a function in an so file. And according to the GNU documentation, [link https://www.gnu.org/software/automake/manual/html_node/User-Variables.html]CFLAGS is a variable reserved for the user at runtime[/link] (I know many developers probably won't care, but this is an official bnu project). – Saff Jun 21 '15 at 22:58
  • @alvits It looks like there's an RPM package coreutils-lib. I'm not using that package manager, but I'll see if I can get it installed on my machine anyway. – Saff Jun 21 '15 at 23:03
  • @JonathanLeffler I did the link wrong in the comment above, and it's not letting me edit it. Here's the right link: https://www.gnu.org/software/automake/manual/html_node/User-Variables.html; I know that this is a page about automake, but it mentions CFLAGS specifically, as well as talking about how atuomake prevents CFLAGs clobbering at compile time (I don't know this for sure, but I'd be surprised if coreutils didn't use automake). – Saff Jun 21 '15 at 23:06
  • OK, it looks like coreutils-lib contains a single library for buffering strings that's used by coreutils, it doesnt proved the functionality in coreutils as a library. – Saff Jun 21 '15 at 23:22

1 Answers1

0

Not sure what you're trying to do, but related to this is the ./configure --enable-single-binary option which links all objects to a single executable.

pixelbeat
  • 30,615
  • 9
  • 51
  • 60