types [follwup: code works]

B

Bill Cunningham

Upon typing this source code and redirecting stderr to bash I received
these errors. The compiled compiled cleanly and the resulting binary typed
this to the screen.
4
4
8
4

#include <stdio.h>

main() {
printf("%i\n",sizeof(int));
printf("%i\n",sizeof(long));
printf("%i\n",sizeof(long long));
printf("%u\n",sizeof(unsigned int ));
return 0;
}

No errors. Using 2>err I received this:

a: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/bin/../lib/gcc/i686-pc-linux-gnu/3.4.6/../../../crt1.o:(.text+0x0):
first defined here
a:(.rodata+0x0): multiple definition of `_fp_hw'
/usr/bin/../lib/gcc/i686-pc-linux-gnu/3.4.6/../../../crt1.o:(.rodata+0x0):
first defined here
a: In function `_fini':
/usr/src/build/229343-i386/BUILD/glibc-2.3.2-20030227/build-i386-linux/csu/crti.S:51:
multiple definition of `_fini'
/usr/bin/../lib/gcc/i686-pc-linux-gnu/3.4.6/../../../crti.o:/usr/src/build/229343-i386/BUILD/glibc-2.3.2-20030227/build-i386-linux/csu/crti.S:51:
first defined here
a:(.rodata+0x4): multiple definition of `_IO_stdin_used'
/usr/bin/../lib/gcc/i686-pc-linux-gnu/3.4.6/../../../crt1.o:(.rodata+0x4):
first defined here
a: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/bin/../lib/gcc/i686-pc-linux-gnu/3.4.6/../../../crt1.o:(.data+0x0):
first defined here
a: In function `__data_start':
(.data+0x4): multiple definition of `__dso_handle'
/usr/bin/../lib/gcc/i686-pc-linux-gnu/3.4.6/crtbegin.o:(.data+0x0): first
defined here
a: In function `_init':
/usr/src/build/229343-i386/BUILD/glibc-2.3.2-20030227/build-i386-linux/csu/crti.S:35:
multiple definition of `_init'
/usr/bin/../lib/gcc/i686-pc-linux-gnu/3.4.6/../../../crti.o:/usr/src/build/229343-i386/BUILD/glibc-2.3.2-20030227/build-i386-linux/csu/crti.S:35:
first defined here
collect2: ld returned 1 exit status

eh? What's up here?

Bill
 
K

Kojak

Le Sun, 22 Mar 2009 16:34:59 -0500,
Bill Cunningham a écrit :
[...]
#include <stdio.h>
main() {

use 'int main (void)' instead
printf("%i\n",sizeof(int));
printf("%i\n",sizeof(long));
printf("%i\n",sizeof(long long));
printf("%u\n",sizeof(unsigned int ));

Be consistent when using 'sizeof' operator using "%zi",
for example. That said, ...
[...]
No errors. Using 2>err I received this:

a: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/bin/../lib/gcc/i686-pc-linux-gnu/3.4.6/../../../crt1.o:(.text+0x0):

[...]

collect2: ld returned 1 exit status

eh? What's up here?

.... this seems to be a problem with your compiler setup.

Cheers,
 
B

Barry Schwarz

Upon typing this source code and redirecting stderr to bash I received
these errors. The compiled compiled cleanly and the resulting binary typed
this to the screen.

I give up - what binary?
4
4
8
4

#include <stdio.h>

main() {

Implied return types have been removed from the standard. If you want
main to return an int, say so.
printf("%i\n",sizeof(int));

Here we go again. Why do you assume the second argument is an int?
And a signed one at that?
printf("%i\n",sizeof(long));
printf("%i\n",sizeof(long long));

Do you have a C99 compiler? If so, you could use %zu and not worry
about the type of the second argument. If not, why do you assume long
long exists?
printf("%u\n",sizeof(unsigned int ));
return 0;
}

No errors. Using 2>err I received this:

What about the errors you mention in the first paragraph? Did you
have errors or not?
a: In function `_start':
(.text+0x0): multiple definition of `_start'

Make up your mind. Is this an error or not? If it is an error, the
question becomes why do you execute code that does not compile
cleanly? (Actually these look like link errors but the question
remains valid.)
/usr/bin/../lib/gcc/i686-pc-linux-gnu/3.4.6/../../../crt1.o:(.text+0x0):
first defined here
a:(.rodata+0x0): multiple definition of `_fp_hw'
/usr/bin/../lib/gcc/i686-pc-linux-gnu/3.4.6/../../../crt1.o:(.rodata+0x0):
first defined here
a: In function `_fini':
/usr/src/build/229343-i386/BUILD/glibc-2.3.2-20030227/build-i386-linux/csu/crti.S:51:
multiple definition of `_fini'
/usr/bin/../lib/gcc/i686-pc-linux-gnu/3.4.6/../../../crti.o:/usr/src/build/229343-i386/BUILD/glibc-2.3.2-20030227/build-i386-linux/csu/crti.S:51:
first defined here
a:(.rodata+0x4): multiple definition of `_IO_stdin_used'
/usr/bin/../lib/gcc/i686-pc-linux-gnu/3.4.6/../../../crt1.o:(.rodata+0x4):
first defined here
a: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/bin/../lib/gcc/i686-pc-linux-gnu/3.4.6/../../../crt1.o:(.data+0x0):
first defined here
a: In function `__data_start':
(.data+0x4): multiple definition of `__dso_handle'
/usr/bin/../lib/gcc/i686-pc-linux-gnu/3.4.6/crtbegin.o:(.data+0x0): first
defined here
a: In function `_init':
/usr/src/build/229343-i386/BUILD/glibc-2.3.2-20030227/build-i386-linux/csu/crti.S:35:
multiple definition of `_init'
/usr/bin/../lib/gcc/i686-pc-linux-gnu/3.4.6/../../../crti.o:/usr/src/build/229343-i386/BUILD/glibc-2.3.2-20030227/build-i386-linux/csu/crti.S:35:
first defined here
collect2: ld returned 1 exit status

eh? What's up here?

Well, you did manage to quote the errors properly so that is an
improvement.

As much as I would like to blame the undefined behavior in your code,
I expect this is really either an installation problem or an
invocation problem. In either case, you need to ask in a newsgroup
that deals with your system.
 
K

Keith Thompson

Bill Cunningham said:
<OT>
I'm using a newley compiled gcc-3.4.6 and binutils-2.19. I'm using a RPM
with glibc.
[...]

What command did you use to compile and link the program?
 
K

Keith Thompson

Bill Cunningham said:
[snip]
What command did you use to compile and link the program?

<OT>
I just used a makefile that was generated by a bash script. It is called
configure and has an executable attribute set. I didn't go into the Makefile
to see its contents. Compilation and installation seemed to work.

Well, your makefile had to invoke the compiler and/or linker somehow.

Try

gcc foo.c -o foo && ./foo

where foo.c is the name of your source file. If that doesn't work,
your compiler and/or linker is broken; try gnu.gcc.help. If it does,
then something else is wrong, probably in the configure script or
makefile; ask in comp.unix.programmer.

I won't ask why you're using a configure script and makefile for a
trivial program like that.
 
B

Bill Cunningham

It appears that your toolchain is broken. gcc -v might help you
determine
why it's linking with some C runtime objects twice. Did you upgrade some
packages recently? The crt1.o and crti.o object files are linked with
every executable. These objects provide _start (which is what is called
or
jumped to before exit(main(argc, argv)); typically), and initialize
various
state. The newsgroup gnu.gcc.help might be more helpful.

-George

<OT>
I'm using a newley compiled gcc-3.4.6 and binutils-2.19. I'm using a RPM
with glibc.

Bill
</OT>
 
B

Bill Cunningham

[snip]
What command did you use to compile and link the program?

<OT>
I just used a makefile that was generated by a bash script. It is called
configure and has an executable attribute set. I didn't go into the Makefile
to see its contents. Compilation and installation seemed to work.

</OT>

Bill
 
B

Bill Cunningham

Well, your makefile had to invoke the compiler and/or linker somehow.

Try

gcc foo.c -o foo && ./foo

where foo.c is the name of your source file. If that doesn't work,
your compiler and/or linker is broken; try gnu.gcc.help. If it does,
then something else is wrong, probably in the configure script or
makefile; ask in comp.unix.programmer.

This compiled a ran without problem.

Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top