Reputation: 227
I was doing a selection sort coding and was getting a small logical error somewhere(The output was skipping the maximum number and printing 0 at start always). So I tried using gdb to debug my coding. But I am getting "no debugging symbols found". I tried using -g while compiling the code as gcc -o -g selection_sort selection_sort.c
. This gives a long list of some errors.
selection_sort: In function `__x86.get_pc_thunk.bx': (.text+0x30):
multiple definition of `__x86.get_pc_thunk.bx' /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crti.o(.debug_info): relocation
0 has invalid symbol index 8 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crti.o(.debug_info): relocation
1 has invalid symbol index 9 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crti.o(.debug_info): relocation
2 has invalid symbol index 10 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crti.o(.debug_ranges):
relocation 0 has invalid symbol index 4 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crti.o(.debug_ranges):
relocation 1 has invalid symbol index 4 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crti.o(.debug_ranges):
relocation 2 has invalid symbol index 5 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crti.o(.debug_ranges):
relocation 3 has invalid symbol index 5 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crti.o(.debug_ranges):
relocation 4 has invalid symbol index 6 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crti.o(.debug_ranges):
relocation 5 has invalid symbol index 6
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crti.o:(.gnu.linkonce.t.__x86.get_pc_thunk.bx+0x0):
first defined here selection_sort: In function `_fini': (.fini+0x0):
multiple definition of `_fini'
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crti.o:(.fini+0x0):
first defined here selection_sort: In function `data_start':
(.data+0x0): multiple definition of `__data_start' /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
0 has invalid symbol index 11 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
1 has invalid symbol index 12 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
2 has invalid symbol index 2 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
3 has invalid symbol index 2 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
4 has invalid symbol index 11 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
5 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
6 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
7 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
8 has invalid symbol index 12 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
9 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
10 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
11 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
12 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
13 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
14 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
15 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
16 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
17 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
18 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
19 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
20 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
21 has invalid symbol index 22 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_line): relocation
0 has invalid symbol index 2
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crt1.o:(.data+0x0):
first defined here selection_sort: In function `data_start':
(.data+0x4): multiple definition of `__dso_handle'
/usr/lib/gcc/i686-linux-gnu/4.8/crtbegin.o:(.data+0x0): first defined
here selection_sort:(.rodata+0x4): multiple definition of
`_IO_stdin_used'
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crt1.o:(.rodata.cst4+0x0):
first defined here selection_sort: In function `_start': (.text+0x0):
multiple definition of `_start'
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crt1.o:/build/buildd/eglibc-2.19/csu/../sysdeps/i386/start.S:115: first defined here selection_sort:(.rodata+0x0): multiple definition
of `_fp_hw'
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crt1.o:(.rodata+0x0):
first defined here selection_sort: In function `_init': (.init+0x0):
multiple definition of `_init' /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crti.o(.debug_line): relocation
0 has invalid symbol index 4 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crti.o(.debug_line): relocation
1 has invalid symbol index 5 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crti.o(.debug_line): relocation
2 has invalid symbol index 6
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crti.o:/build/buildd/eglibc-2.19/csu/../sysdeps/i386/crti.S:63:
first defined here /tmp/ccUdOuVC.o: In function `main':
selection_sort.c:(.text+0x0): multiple definition of `main'
selection_sort:(.text+0x100): first defined here
/usr/lib/gcc/i686-linux-gnu/4.8/crtend.o:(.tm_clone_table+0x0):
multiple definition of `__TMC_END__' selection_sort:(.data+0x8): first
defined here /usr/bin/ld: warning: Cannot create .eh_frame_hdr
section, --eh-frame-hdr ignored. /usr/bin/ld: error in
selection_sort(.eh_frame); no .eh_frame_hdr table will be created.
collect2: error: ld returned 1 exit status.
Here's the code:
#include<stdio.h>
int main()
{
int a[5] = {9,7,1,8,2};
int min, temp, i, j;
for( i=0; i<=4; i++)
{
min = i;
for( j=i;j<=4; j++)
{
if(a[j+1] < a[min])
min = j+1;
}
if (min != i)
{
temp = a[min];
a[min] = a[i];
a[i] = temp;
}
}
for( i=0; i<5; i++)
{
printf("The sorted array is: %d\n", a[i]);
}
}
Upvotes: 1
Views: 260
Reputation: 145287
You cannot give gcc
the -g
option just after -o
: you are instructing gcc
to name the executable -g
and link the previous executable selection_sort
together with the new object file.
Compile with this command:
gcc -Wall -g -o selection_sort selection_sort.c
Once you get an executable, you can start debugging... There are out of bounds array references in your code.
Upvotes: 5