0

to be short and sweet, this is happening right now and has never happened to me before today:

  g++ assn1m.c segment.cpp
/tmp/cc2yUKRO.o: In function `bit_to_ascii(char const*, char*)':
segment.cpp:(.text+0x0): multiple definition of `bit_to_ascii(char const*, char*)'
/tmp/cc2Xgj7t.o:assn1m.c:(.text+0x0): first defined here
/usr/lib/gcc/i586-suse-linux/4.4/../../../crt1.o: In function `_start':
/usr/src/packages/BUILD/glibc-2.10.1/csu/../sysdeps/i386/elf/start.S:115: undefined reference to `main'
collect2: ld returned 1 exit status
4

1 回答 1

2

You have two definitions of the function bit_to_ascii(char const*, char*), one of which is in assn1m.c and the other of which is in segment.cpp. This is often caused by defining it in a header file without inline and including it in multiple source files.

Note that in C99, the inline specifier works slightly differently than in C++. You may have to define it as extern inline to get it to work properly.

You also didn't define the main function anywhere for your program's entry point, or you're not linking in the object file where it's defined, though that's a separate issue from the multiple definitions error.

于 2012-07-13T22:34:57.393 回答