Home > Archive > Linux/Unix > December 2002 > Libraries and Compiling





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Libraries and Compiling
Boulware5

2002-12-19, 11:52 pm

I am not completely clear on this....

If a program is compiled under let's say gcc 3.2, will that program function correctly in a machine that is compiled with gcc 2.95 and its associated libraries? I ran into problems on my Slackware system because I would always upgrade to binaries that were compiled with a gcc version other than the gcc version and library version that my system (my kernel) was compiled under. Does this make sense? I'll try to be more clear if not. I would then have to recompile everything by source. And one more thing...

What if my system was compiled with gcc 3.0. Can I then install slackware binaries that were compiled under gcc 3.2? (this is hyperthetical) Or should I be aware only of the major gcc version differences (such as going from 2.95 to 3.2)

Hope this makes sense LOL
Mr. Linux Guy

2002-12-20, 10:29 am

In general, if you compile a program to run under Linux, it should no matter what version the compiler is, as long as you get the right binary. For example, you do not even have to use gcc to compile programs under Linux. Any compiler that you can get to run will work. Now I don't mean something that was written for OS/2 or Windows, but let's say that you decided to get creative and code your own C compiler. If your compiler supported all of the functions that the code makes use of, you should have no problem with it. The two things that you may run into problems could be the code itself . . . as newer versions of the compiler are released, they may add extra features that would cause errors, so you need to make sure that a certain program will compile correctly under a given version of your compiler. The next thing that could happen is that your linker will look for certain libraries that it uses to include in the link process. I suspect this is your problem. Because the compiler will look for the library files by name (which are version-specific), if it expects a file that it doesn't see, the compiler will barf. but usually you can use these files anyway. It doesn't always work, but what I normally do is go into the library folder and then make symlinks from the files that I have on my machine to the names of the library files that your compiler expects. This way you can often fake gcc out and the files you already have will be able to be used. You may need to read a little to find out what to call the new links though.
freak

2002-12-20, 10:43 am

great posts, Thanks guys!

Boulware5, you're gonna be a linux guru in no time, my friend.
Mr. Linux Guy

2002-12-20, 11:17 am

Actually, I think you can include or exclude linkage files with gcc directly. If you try this:

# gcc -S foo.c

you will get a file called foo.s containing a listing in aseembly language. Then do a

# as -o foo.o foo.s

to get your object file . . . i think you could do this directly with gcc like so:

# gcc -c -o foo.o foo.s

and use the linker to link the files that you want:

# ld -o program one.o two.o three.o

The object files you could include by hand. But this depends on how complicated your program is . . . it is possible that a great many files may be needed so usually I prefer to use the fake-out method when possible. If it doesn't work, try getting verbose output using gcc in order to see what files are being expected, then symlink your files to the ones your compiler wants:

lrwxrwxrwx /usr/lib/libstuff.so -> libstuff.so.4.1.0*
-rwxr-xr-x /usr/lib/libstuff.so.4.1.0*

And try that.
Boulware5

2002-12-20, 9:33 pm

Thanks for the reply. I was told by a Slackware user that it's a mistake to update your packages to the slackware-current. In case you are not familiar with Slack, it's packages that are constantly upgraded and will later be used for the upcoming Slackware 9.0. The reason being the slack-current is compiled under gcc 3.2. and slackware 8.1 uses gcc 2.9.5. Few more questions...

1. Shouldn't updating gcc and all my libraries solve such problems. And wouldn't you then have to recompile your kernel with the new gcc and libs and all your programs from source?

2. Let's say I want to update gcc and libraries. What are all the packages I should get. I know I need gcc and probably libc and binutils but what else exactly?

Thanks again Randy
Mr. Linux Guy

2002-12-21, 6:51 am

1. No. The problem with updating all of yourpackages is that Slack puts new stuff out on such a regular basis, that if you want to keep up with Patrick and crew, you will find yourself as a permanent alpha and beta tester. New stuff is always in development and thus always getting the newer versions of stuff will often be an exercise in helping the developers debug their code. the good side of this is that you are helping to develop the kernel and associated apps by doing this. In theory, yes, though. If all has been tested and found OK, updating everything would fix your problems. This is not always the most instructional, however, as lots of updating as I alluded to above, comes to renaming old files which can still be used with the current compiler. The older files should remain compatible for the most part with the new ones, and when this isnot the case, updating your library files only should do the trick. The reason forthis is because they are "dynamically linked". This means that just like the DLL's in Windows, you can update these independently of the programs that use them (the same is not true of statically compiled programs, which rather than looking for code in /usr/lib, have all their code inserted directly into the program).

2. I don't remember right off, but there are certain tips I can give you. First off, use the "ldd" command to see what libraries any given binary uses. FOr example, if you wanted to check out gcc, then you could try something like this:

# ldd `which gcc`

to see the shared libraries used by the "gcc" command. (Note that you need to specify the entire path to the binary you are interested in.) This way if a binary (newly created, down loaded, etc.) requires a library you can check your "lib" directory to see if it is there. If it is not, you will need to create and install it. Type "file library.so.x", substituting the name of your library for "library.so.x". If ELF is used the loader library "ld-linux.so" is required, and if a.out is used, "ld.so" is required.

Hope this answers your questions.
Sponsored Links





Free Braindumps | MCSE braindumps software forum

Copyright 2003 - 2008 examnotes.net