DF sparked my interest in system-stylee programming again, so I have a couple of questions:
a) At the last UEA meeting, I heard ALUG had been offered a 25% O'Reilly discount. I thought, mmm, munch. Is this going to be honoured as an ALUG-library only option, or if I come up with a huge order can I route it thru ALUG?
b) I'm trying to build and link against a static library: gcc -g -Wall -o libdog.o libdog.c ar rcs libdog.a libdog.o gcc -g -Wall -o sll.o sll.c ld -L. -ldog -o sll sll.o
libdog.c: #includes void speak() { printf("Arf!\n"); }
sll.c: #includes [extern] void speak(); int main(int argc, char** argv) { speak(); return 0; }
The ld command warns me that it can't find a _start symbol, then wibbles about undefined symbol speak. It definitely finds libdog.a though (from -verbose), and nm libdog.a reports something very much like:
libdog.a: 00000000 t Letext U printf 00000006 T speak
I've tried it with and without extern. Given I figured out how to build & link shared libraries for JNI, on AIX, with only man pages, I'm feeling fairly annoyed at myself for not being able to do statics with a big book in front of me. Help!
Finally, I might be able to help out with organising UEA ALUG meetings. Being a student, I go onto campus pretty regularly anyway. Mail me, MJR.
Alexis -- http://www.ikitten.co.uk "C++ : an octopus made by nailing extra legs onto a dog" "Resolve first your body and mind, your private relationships and your public ones. The state will soon follow." - Confucian-esque "I find that the harder I work, the more luck I seem to have" - T Jefferson
OK
a-1) Subscribe from the email address you wish to post, otherwise we have to auth your posts each time.
but more to the point ... --- LxS Alexis.Lee@uea.ac.uk wrote:
DF sparked my interest in system-stylee programming again, so I have a couple of questions:
Hey, DOn't blame me, I did nothing. It wasn't my fault.
What was it?
a) At the last UEA meeting, I heard ALUG had been offered a 25% O'Reilly discount. I thought, mmm, munch. Is this going to be honoured as an ALUG-library only option, or if I come up with a huge order can I route it thru ALUG?
I will follow this up. Email me off list with what you want.
b) I'm trying to build and link against a static library: gcc -g -Wall -o libdog.o libdog.c ar rcs libdog.a libdog.o gcc -g -Wall -o sll.o sll.c ld -L. -ldog -o sll sll.o
I'm no expert but...
That all looks ok
libdog.c: #includes void speak() { printf("Arf!\n"); }
sll.c: #includes [extern] void speak(); int main(int argc, char** argv) { speak(); return 0; }
Do you have a header file with the function diffinitions for speak?
also try
int main (int argc, char *argv[]) { speak(); return 0; }
Doesn't make any difference but it makes it alot easier to read.
The ld command warns me that it can't find a _start symbol, then wibbles about undefined symbol speak. It definitely finds libdog.a though (from -verbose), and nm libdog.a reports something very much like:
libdog.a: 00000000 t Letext U printf 00000006 T speak
I've tried it with and without extern. Given I figured out how to build & link shared libraries for JNI, on AIX, with only man pages, I'm feeling fairly annoyed at myself for not being able to do statics with a big book in front of me. Help!
Have you got a copy of programming with GNU software handy?
Finally, I might be able to help out with organising UEA ALUG meetings. Being a student, I go onto campus pretty regularly anyway. Mail me, MJR.
Hurrah
Alexis
http://www.ikitten.co.uk "C++ : an octopus made by nailing extra legs onto a dog"
Thats from the small talk web site along with
"saying Java is easier than C++ is like saying K2 is shorter than everest"
But my most recent favourite I found when going throught the kernel source
in /usr/src/linux/Documentation/CodingStyle
"First off, I'd suggest printing out a copy of the GNU coding standards, and NOT read it. Burn them, it's a great symbolic gesture."
Thanks
D
"Resolve first your body and mind, your private relationships and your public ones. The state will soon follow." - Confucian-esque "I find that the harder I work, the more luck I seem to have" - T Jefferson
__________________________________________________ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/
David Freeman wrote:
OK
a-1) Subscribe from the email address you wish to post, otherwise we have to auth your posts each time.
Unfortunatly, Mailman looks at the Sender: mail header which may not be the same as your subscribed email address (especially in an enviroment with multiple outgoing relays), and as the sender header should point to mail relay where the mail originally came from not a arbitarily defined one (eg the sender header for this mail will point to abower@pandora.zeus.co.uk which is a valid mail relay but my email address is abower@zeus.com). This could cause more problems (Indeed this message will need to be approved) I will have a read of RFC2882 & 2881 tomorrow and the Mailman docs to see which is broken (either the offending mail systems or Mailman).
Adam
On Tue, May 22, 2001 at 01:06:22PM +0100, LxS wrote:
a) At the last UEA meeting, I heard ALUG had been offered a 25% O'Reilly discount. I thought, mmm, munch. Is this going to be honoured as an ALUG-library only option, or if I come up with a huge order can I route it thru ALUG?
I bet O'Reilly didn't give discount for the sake of their health - I bet they are hoping to get extra business so it's probably worth a try. The only restriction I remember hearing is that all the books have to go to the same address which is currently DF.
b) I'm trying to build and link against a static library: gcc -g -Wall -o libdog.o libdog.c ar rcs libdog.a libdog.o gcc -g -Wall -o sll.o sll.c ld -L. -ldog -o sll sll.o
The ld command warns me that it can't find a _start symbol...
Because you aren't linking crt0.o or whatever the startup module is called on Linux (the module that normally calls the C main() function). Maybe this is what you intended but if it isn't, the easiest fix is to use gcc as the linker, e.g:
gcc -L. -o sll sll.o -ldog
then wibbles about undefined symbol speak. It definitely finds libdog.a though (from -verbose), and nm libdog.a reports something very much like:
[snip]
What is happenning is that, because you have the -ldog option on your link command before the module that uses the speak symbol, at the time the linker searches the libdog.a library it doesn't yet know that it needs the function speak and won't bother including it. Later on it finds it needs a function called speak but it doesn't go back and re-search libraries it has already searched and it gets to the end of the list of modules and libraries with the symbol undefined.
In most cases, the answer is to put the libraries at the end of the link command and make sure the order is correct. For your case it looks simple enough:
ld -L. -o sll sll.o -ldog
It can get tricky with stuff that is mutually or circularly dependant but you can include libraries in the search list more than once to solve that.
Steve.
b) I'm trying to build and link against a static library: gcc -g -Wall -o libdog.o libdog.c ar rcs libdog.a libdog.o
ranlib libdog.a Not really needed for a lib with just the one function, but will save pain later...
gcc -g -Wall -o sll.o sll.c ld -L. -ldog -o sll sll.o
I'd do: gcc -o sll -L. sll.o -ldog or gcc -o sll sll.o libdog.a
gcc -v indicates that "collect2" is being used rather than ld, but the *exact same* arguments can drive ld. Go figure.
ld -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o sll /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/gcc-lib/i386-linux/2.95.2/crtbegin.o -L. -L/usr/lib/gcc-lib/i386-linux/2.95.2 sll.o -ldog -lgcc -lc -lgcc /usr/lib/gcc-lib/i386-linux/2.95.2/crtend.o /usr/lib/crtn.o
The standard initialization/exit modules are now linked in.