Hi all,
Firstly I apologize if I've posted in the wrong place.
I have been "playing" with Linux (more specifically Puppy) for about a month
now and been "poking" here and there.
However now is the time to really get stuck in and do some programming.
(The compiled type into elf binaries as opposed to scripts).
Coming from the M$ world, things a very different with Linux and I need to
get clarification on a few things:
1) If I write a simple C program (and not use any extra libs) and compile it,
will it run on any Linux distro provided it's using the same kernel and runs
on a x86 platform?
(assuming my program only has console output, i.e. no GUI for now).
2) Another scenario, I write a program in C and call an external lib,
will the compiled program still run on any distro provided I supply the
some_lib.so ?
I understand that in this case Linux may not find the required lib if I don't
supply an install script to tell it where to put the program and where to put
the lib, hence the need for .pet files in the case of puppy, is this also correct?
3) Yet another scenario, I write a C program but have the required lib as a
.h source file which will be included at compile time, I assume in this case
there would be no need to include a compiled (.so) file of the .h ?
4) Is it also correct to assume that a separate script (for example using
gtkdialog) could then be used a a "wrapper" between the console output
of my program and a GUI? although in this case there could be
compatibility issues with gtkdialog ?
5) Are libs (.so) compatible with any distro, again assuming same kernel and platform ?
So in other words if I need a certain .so can I copy it from another distro
and put it on my puppy machine?
(the usual "gotchas" with GUI stuff and where to put it still applies).
Any help/pointers will be greatly appreciated.
Dave.
The essence of Linux binaries and libraries
Found most of the answers myself, so in the hope that they will be helpful
to others, I will post them here and the methods I used.
After some digging around in some .pet files with a hex editor, I found that they
are .tar files and renaming the pet to a tar, puppy gave me the option to view
the files in the archive instead of it just wanting to install them by default.
With this "new" option available I could extract the elf binary then open a
console window and do a "ldd name_of_file" to get puppy to check the required
libs and if I have them.
Now if all is ok, I simply rename the archive back to a .pet and install it.
I then moved on to see what I could use from the Ubuntu repository on ibiblio
and discovered that Ubuntu uses a .deb file format which is a more complex
structure http://en.wikipedia.org/wiki/Deb_(file_format)
As an example I downloaded http://distro.ibiblio.org/pub/linux/dis ... e/c/cpuid/
I could not get puppy to let me look inside the .deb without wanting to install it, so I transfered the file
over to my XP box and used 7zip to extract the elf binary and copied it back to my puppy box.
I then did a "ldd cpuid" and got this back:
linux-gate.so.1 => (0xffffe000)
libc.so.6 => /lib/libc.so.6 (0xb7e60000)
/lib/ld-linux.so.2 (0xb7fa1000)
So all ok, I ran it and success:
Vendor ID: "GenuineIntel"; CPUID level 10
Intel-specific functions:
Version 000106ca:
Type 0 - Original OEM
Family 6 - Pentium Pro
Model 12 -
Stepping 10
Reserved 4
etc etc
Now I just need to give it some "eye candy" using gtkdialog and it will
make for a nice app to report cpu parameters.
Another nice thing about the Ubuntu files on ibiblio is that the source is
available as well in a .orig.tar.gz file, great for learning.
In the example above, there where no extra libs to install and none came
with the deb file, however since the main compiled binary worked flawlessly,
I have no reason to believe that it will be any different with a compiled lib.
My puppy version is 431 with the devx file and gcc installed.
Dave.
to others, I will post them here and the methods I used.
After some digging around in some .pet files with a hex editor, I found that they
are .tar files and renaming the pet to a tar, puppy gave me the option to view
the files in the archive instead of it just wanting to install them by default.
With this "new" option available I could extract the elf binary then open a
console window and do a "ldd name_of_file" to get puppy to check the required
libs and if I have them.
Now if all is ok, I simply rename the archive back to a .pet and install it.
I then moved on to see what I could use from the Ubuntu repository on ibiblio
and discovered that Ubuntu uses a .deb file format which is a more complex
structure http://en.wikipedia.org/wiki/Deb_(file_format)
As an example I downloaded http://distro.ibiblio.org/pub/linux/dis ... e/c/cpuid/
I could not get puppy to let me look inside the .deb without wanting to install it, so I transfered the file
over to my XP box and used 7zip to extract the elf binary and copied it back to my puppy box.
I then did a "ldd cpuid" and got this back:
linux-gate.so.1 => (0xffffe000)
libc.so.6 => /lib/libc.so.6 (0xb7e60000)
/lib/ld-linux.so.2 (0xb7fa1000)
So all ok, I ran it and success:
Vendor ID: "GenuineIntel"; CPUID level 10
Intel-specific functions:
Version 000106ca:
Type 0 - Original OEM
Family 6 - Pentium Pro
Model 12 -
Stepping 10
Reserved 4
etc etc
Now I just need to give it some "eye candy" using gtkdialog and it will
make for a nice app to report cpu parameters.
Another nice thing about the Ubuntu files on ibiblio is that the source is
available as well in a .orig.tar.gz file, great for learning.
In the example above, there where no extra libs to install and none came
with the deb file, however since the main compiled binary worked flawlessly,
I have no reason to believe that it will be any different with a compiled lib.
My puppy version is 431 with the devx file and gcc installed.
Dave.
Last edited by Dave_G on Wed 10 Aug 2011, 23:33, edited 2 times in total.
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
Re: The essence of Linux binaries and libraries
mostly true assuming the c library is the same or newer versionDave_G wrote:1) If I write a simple C program (and not use any extra libs) and compile it, will it run on any Linux distro provided it's using the same kernel and runs on a x86 platform?
(assuming my program only has console output, i.e. no GUI for now).
yes, but then you may as well use a static library2) Another scenario, I write a program in C and call an external lib, will the compiled program still run on any distro provided I supply the some_lib.so? I understand that in this case Linux may not find the required lib if I don't supply an install script to tell it where to put the program and where to put the lib, hence the need for .pet files in the case of puppy, is this also correct?
to make a static library just:ar -cru libMYLIB.a *.o
or compile them together gcc -Os *.c -o myprog
you can include anything with valid c code regardless of extension (ex. #include "helpercode.c")3) Yet another scenario, I write a C program but have the required lib as a .h source file which will be included at compile time, I assume in this case there would be no need to include a compiled (.so) file of the .h?
yes, as long as you have sane outputs it should be gtkdialog compatible4) Is it also correct to assume that a separate script (for example using gtkdialog) could then be used a a "wrapper" between the console output of my program and a GUI? although in this case there could be compatibility issues with gtkdialog?
sometimes, it depends on the versions and how it is compiled as well as their dependencies' versions and how they were compiled5) Are libs (.so) compatible with any distro, again assuming same kernel and platform ? So in other words if I need a certain .so can I copy it from another distro and put it on my puppy machine?
(the usual "gotchas" with GUI stuff and where to put it still applies).
(there is a long standing "wontfix" bug with autotools+pkg-config that causes the linker to directly link to dependencies instead of "lazy" loading at runtime)
btw you can use undeb for .deb files
and
rpm2cpio *.rpm |cpio -id for .rpm files
and
pet2tgz plus tgz2pet for .pet files[/quote]
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].