gcc error compiling file - c

[user#user Book]$ gcc -o notesearch.c notesearch
notesearch: In function `__x86.get_pc_thunk.bx':
(.text+0x30): multiple definition of `__x86.get_pc_thunk.bx'
/usr/lib/gcc/i686-pc-linux-gnu/4.9.2/../../../crti.o:(.gnu.linkonce.t.__x86.get_pc_thunk.bx+0x0): first defined here
notesearch: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/i686-pc-linux-gnu/4.9.2/../../../crti.o:(.fini+0x0): first defined here
notesearch: In function `data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/i686-pc-linux-gnu/4.9.2/../../../crt1.o:(.data+0x0): first defined here
notesearch: In function `data_start':
(.data+0x4): multiple definition of `__dso_handle'
/usr/lib/gcc/i686-pc-linux-gnu/4.9.2/crtbegin.o:(.data+0x0): first defined here
notesearch:(.rodata+0x4): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/i686-pc-linux-gnu/4.9.2/../../../crt1.o:(.rodata.cst4+0x0): first defined here
notesearch: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/i686-pc-linux-gnu/4.9.2/../../../crt1.o:(.text+0x0): first defined here
notesearch:(.rodata+0x0): multiple definition of `_fp_hw'
/usr/lib/gcc/i686-pc-linux-gnu/4.9.2/../../../crt1.o:(.rodata+0x0): first defined here
notesearch: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/i686-pc-linux-gnu/4.9.2/../../../crti.o:(.init+0x0): first defined here
/usr/lib/gcc/i686-pc-linux-gnu/4.9.2/crtend.o:(.tm_clone_table+0x0): multiple definition of `__TMC_END__'
notesearch:(.data+0x8): first defined here
/usr/bin/ld: warning: Cannot create .eh_frame_hdr section, --eh-frame-hdr ignored.
/usr/bin/ld: error in notesearch(.eh_frame); no .eh_frame_hdr table will be created.
collect2: error: ld returned 1 exit status
[user#user Book]$
I am trying to compile notesearch.c from the book "hacking the art of exploitation" and I get an error. I remember being able to do it just fine. I am on a x86 3.16.7.4-1-MANJARO Linux computer.

You need to say gcc -o notesearch notesearch.c. Otherwise, you are OUTPUTTING (-o) to the .c file, which is not good. Also, you may want to consider compiling with these other flags:
-Wall: Warn All, very useful.
-Werror: Again, very useful.
-g: This is my favorite flag. It compiles with debug symbols, so that you can start you program in gdb (Gnu DeBugger) and then examine what is happening, change values of variables during execution, and generally debug it. gdb is VERY helpful.

Related

multiple definition in C project

I have a problem with this project (it is a minigame similar to space invaders).
Every time I try to compile it it gives me these errors:
❯ make
gcc main.o collisioni.o stampa.o gestione.o -o progetto -lncurses
/usr/bin/ld: collisioni.o:(.bss+0x0): multiple definition of `maxx'; main.o:(.bss+0x0): first defined here
/usr/bin/ld: collisioni.o:(.bss+0x4): multiple definition of `maxy'; main.o:(.bss+0x4): first defined here
/usr/bin/ld: collisioni.o:(.bss+0x8): multiple definition of `flag_navicelle'; main.o:(.bss+0x8): first defined here
/usr/bin/ld: stampa.o:(.bss+0x0): multiple definition of `maxx'; main.o:(.bss+0x0): first defined here
/usr/bin/ld: stampa.o:(.bss+0x4): multiple definition of `maxy'; main.o:(.bss+0x4): first defined here
/usr/bin/ld: stampa.o:(.bss+0x8): multiple definition of `flag_navicelle'; main.o:(.bss+0x8): first defined here
/usr/bin/ld: gestione.o:(.bss+0x0): multiple definition of `maxx'; main.o:(.bss+0x0): first defined here
/usr/bin/ld: gestione.o:(.bss+0x4): multiple definition of `maxy'; main.o:(.bss+0x4): first defined here
collect2: error: ld returned 1 exit status
make: *** [makefile:2: progetto] Errore 1
The source code of the project is this: https://github.com/Stenafo/game
I compile the code using the makefile.
I don't understand where the problem is, a friend of mine manages to compile it without errors.
This project uses processes, however I have the same problem with threads.

Why do I get "multiple definition" errors when compiling my project?

Edit : initializing the constants of my project in a C module and declaring them in a corresponding header resolved the issue.
I am working on making a C implementation of the AES cipher (link : https://github.com/SuperTotoGo/AES_Cipher). Everything was working fine until I tried to separate my project in modules. Now when I compile I get this error :
gcc -std=c99 -g -o aes.out *.c
/usr/bin/ld: /tmp/ccpeYNuO.o:/home/pipou/AES_Cipher/aes_const.h:8: multiple definition of `AES_SUB_BOX'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:8: first defined here
/usr/bin/ld: /tmp/ccpeYNuO.o:/home/pipou/AES_Cipher/aes_const.h:28: multiple definition of `INV_AES_SUB_BOX'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:28: first defined here
/usr/bin/ld: /tmp/ccpeYNuO.o:/home/pipou/AES_Cipher/aes_const.h:48: multiple definition of `AES_LOG_TABLE'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:48: first defined here
/usr/bin/ld: /tmp/ccpeYNuO.o:/home/pipou/AES_Cipher/aes_const.h:68: multiple definition of `AES_ALOG_TABLE'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:68: first defined here
/usr/bin/ld: /tmp/ccpeYNuO.o:/home/pipou/AES_Cipher/aes_const.h:88: multiple definition of `AES_MULT_MAT'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:88: first defined here
/usr/bin/ld: /tmp/ccpeYNuO.o:/home/pipou/AES_Cipher/aes_const.h:96: multiple definition of `INV_AES_MULT_MAT'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:96: first defined here
/usr/bin/ld: /tmp/ccpeYNuO.o:/home/pipou/AES_Cipher/aes_const.h:104: multiple definition of `RCON'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:104: first defined here
/usr/bin/ld: /tmp/cczfD784.o:/home/pipou/AES_Cipher/aes_const.h:8: multiple definition of `AES_SUB_BOX'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:8: first defined here
/usr/bin/ld: /tmp/cczfD784.o:/home/pipou/AES_Cipher/aes_const.h:28: multiple definition of `INV_AES_SUB_BOX'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:28: first defined here
/usr/bin/ld: /tmp/cczfD784.o:/home/pipou/AES_Cipher/aes_const.h:48: multiple definition of `AES_LOG_TABLE'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:48: first defined here
/usr/bin/ld: /tmp/cczfD784.o:/home/pipou/AES_Cipher/aes_const.h:68: multiple definition of `AES_ALOG_TABLE'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:68: first defined here
/usr/bin/ld: /tmp/cczfD784.o:/home/pipou/AES_Cipher/aes_const.h:88: multiple definition of `AES_MULT_MAT'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:88: first defined here
/usr/bin/ld: /tmp/cczfD784.o:/home/pipou/AES_Cipher/aes_const.h:96: multiple definition of `INV_AES_MULT_MAT'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:96: first defined here
/usr/bin/ld: /tmp/cczfD784.o:/home/pipou/AES_Cipher/aes_const.h:104: multiple definition of `RCON'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:104: first defined here
/usr/bin/ld: /tmp/ccxcDlRl.o:/home/pipou/AES_Cipher/aes_const.h:8: multiple definition of `AES_SUB_BOX'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:8: first defined here
/usr/bin/ld: /tmp/ccxcDlRl.o:/home/pipou/AES_Cipher/aes_const.h:28: multiple definition of `INV_AES_SUB_BOX'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:28: first defined here
/usr/bin/ld: /tmp/ccxcDlRl.o:/home/pipou/AES_Cipher/aes_const.h:48: multiple definition of `AES_LOG_TABLE'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:48: first defined here
/usr/bin/ld: /tmp/ccxcDlRl.o:/home/pipou/AES_Cipher/aes_const.h:68: multiple definition of `AES_ALOG_TABLE'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:68: first defined here
/usr/bin/ld: /tmp/ccxcDlRl.o:/home/pipou/AES_Cipher/aes_const.h:88: multiple definition of `AES_MULT_MAT'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:88: first defined here
/usr/bin/ld: /tmp/ccxcDlRl.o:/home/pipou/AES_Cipher/aes_const.h:96: multiple definition of `INV_AES_MULT_MAT'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:96: first defined here
/usr/bin/ld: /tmp/ccxcDlRl.o:/home/pipou/AES_Cipher/aes_const.h:104: multiple definition of `RCON'; /tmp/ccHvhAUx.o:/home/pipou/AES_Cipher/aes_const.h:104: first defined here
collect2: error: ld returned 1 exit status
My functions prototypes are defined in the headers and my functions are implemented in the corresponding c files, from what I understood about modular projects I normally only need to include the header files in the main file to have it working.
So, would you have any idea what I did wrong?
Also if you have any tips about making modular C projects or any advice conecerning how I have done it, please tell me!
You have several variables defined in the aes_const.h header file. As a result, each source file that is compiled has a copy of those variables. So when everything in linked, you end up with multiple definitions.
Move these variable definitions into a single source file, then put extern declarations for them in the header file.
So the header should contain:
extern const uint8_t AES_SUB_BOX[16][16];
extern const uint8_t INV_AES_SUB_BOX[16][16];
extern const uint8_t AES_LOG_TABLE[16][16];
extern const uint8_t AES_ALOG_TABLE[16][16];
extern const uint8_t AES_MULT_MAT[4][4];
extern const uint8_t INV_AES_MULT_MAT[4][4];
extern uint8_t RCON[10];
And the existing definitions should be moved to a .c file, for example aes_const.c.
The prototypes are defined in the headers, which is why the compiler detects all the names and succeeds in compilation. The failure you're getting is during link-time. That is because the linker needs the implementation of the functions, which live in the .c files.
What you need to do is to compile all the .c files and link the resulting object files together. C projects usually build all the object files first (gcc -c *.c) and then link them all together in a separate step (gcc -o aes.out *.o)

Should I worry about gcc -pedantic option now?

I have just started to learn C as a hobby. I am doing it with the "C programming: A Modern Approach" book. There is a first program there which is called pun.c. Here is the code:
#include <stdio.h>
int main(void)
{
int int_figure;
float float_figure;
int_figure = 12;
float_figure = 12.0;
printf("To C or not to C, this is a question\n");
printf("%d\n", int_figure);
printf("%.2f\n", float_figure);
return 0;
}
Actually it does not matter because the thing I want to ask about is the same with any .c file compilation with gcc.
So in the book there are some options for gcc which allow finding errors during compilation.One of them is -Wall, another one is -pedantic. So when I compile the file with this option, the output in terminal is the following:
nickdudaev|c $ gcc -o -Wall pun pun.c
pun: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/../../../../lib/crti.o:(.fini+0x0): first defined here
pun: In function `data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/../../../../lib/crt1.o:(.data+0x0): first defined here
pun: In function `data_start':
(.data+0x8): multiple definition of `__dso_handle'
/usr/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/crtbegin.o:(.data+0x0): first defined here
pun:(.rodata+0x0): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/../../../../lib/crt1.o:(.rodata.cst4+0x0): first defined here
pun: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/../../../../lib/crt1.o:(.text+0x0): first defined here
pun: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/../../../../lib/crti.o:(.init+0x0): first defined here
/tmp/cc2TRR93.o: In function `main':
pun.c:(.text+0x0): multiple definition of `main'
pun:(.text+0xf6): first defined here
/usr/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/crtend.o:(.tm_clone_table+0x0): multiple definition of `__TMC_END__'
pun:(.data+0x10): first defined here
/usr/bin/ld: error in pun(.eh_frame); no .eh_frame_hdr table will be created.
collect2: error: ld returned 1 exit status
The program although runs correctly.
nickdudaev|c $ ./pun
To C or not to C, this is a question
12
12.00
So to the questions.
Should I on this stage (of learning) worry about this output and at all use those options?
Do I have probably some systematic error? Because output is the same for any file compilation. Maybe something is not properly installed?
I tried to search Google, but the only thing I found is descriptions of what gcc options do. But nothing about possible output and what to do with it.
This:
gcc -o -Wall pun pun.c
doesn't look right. You're saying -Wall where you should say the name of the output, i.e. the argument to -o.
Try:
gcc -Wall -o pun pun.c
Basically you're feeding pun, the old binary, to gcc as a source file.
The -o option in gcc is used to specify a custom output file name, otherwise,
If -o is not specified, the default is to put an executable file in a.out.
The recommended format is -o file. The next expected argument after -o is a filename, not another switch. See the online manual for more details.
You should re-write your compilation statement as
gcc -o pun pun.c -Wall

C program no longer compiles in Ubuntu

I made a program in C and I get these errors when I compile using gcc. I did not use to get them until recently and my program has not changed.
In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o:(.fini+0x0): first defined here
slots: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o:(.data+0x0): first defined here
slots: In function `__data_start':
(.data+0x8): multiple definition of `__dso_handle'
/usr/lib/gcc/x86_64-linux-gnu/4.6/crtbegin.o:(.data+0x0): first defined here
slots:(.rodata+0x0): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o:(.rodata.cst4+0x0): first defined here
slots: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o:(.text+0x0): first defined here
slots: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o:(.init+0x0): first defined here
/tmp/ccIlRWIn.o: In function `main':
slots.c:(.text+0x0): multiple definition of `main'
slots:(.text+0xe4): first defined here
/usr/lib/gcc/x86_64-linux-gnu/4.6/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
slots:(.dtors+0x8): first defined here
/usr/bin/ld: error in slots(.eh_frame); no .eh_frame_hdr table will be created.
collect2: ld returned 1 exit status
You forgot -o before the output filename so the linker is trying to use your old executable as input.
You could have probably defined an extern variable in a header file and include it in another file.
For example,
extern int _fini = 1; // declared in a.h
Say in a1.c or a2.c
#include "a.h" // _fini again defined in a1.c or a2.c
Seems you have more than one main and some other functions in your code. Make sure you didn't include multiple definitions of main more than once in your makefile.

When compiling,I write " gcc -g -Wall dene2 dene2.c", then gcc emits some trace

When I compile my code,I write gcc -g -Wall dene2 dene2.c in the console. Then gcc emits some text on the screen. I don't understand what this output means (I couldn't think of a meaningful title for that reason, sorry).
I have tried Google searching but haven't had any luck.
I'm not asking for a detailed examination of all of the output below. Just show me "how to catch fish".
dene2: In function `_start':
/build/buildd/eglibc-2.10.1/csu/../sysdeps/i386/elf/start.S:65: multiple
definition of `_start'
/usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crt1.o:/build/buildd/eglibc-2.10.1
/csu/../sysdeps/i386/elf/start.S:65: first defined here
dene2:(.rodata+0x0): multiple definition of `_fp_hw'
/usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crt1.o:(.rodata+0x0): first
defined here
dene2: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crti.o:(.fini+0x0): first defined
here
dene2:(.rodata+0x4): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crt1.o:(.rodata.cst4+0x0): first
defined here
dene2: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crt1.o:(.data+0x0): first defined
here
dene2: In function `__data_start':
(.data+0x4): multiple definition of `__dso_handle'
/usr/lib/gcc/i486-linux-gnu/4.4.1/crtbegin.o:(.data+0x0): first defined here
dene2: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crti.o:(.init+0x0): first defined
here
/tmp/ccMlGkkV.o: In function `main':
/home/fatih/Desktop/dene2.c:5: multiple definition of `main'
dene2:(.text+0xb4): first defined here
/usr/lib/gcc/i486-linux-gnu/4.4.1/crtend.o:(.dtors+0x0): multiple definition of
`__DTOR_END__'
dene2:(.dtors+0x4): first defined here
collect2: ld returned 1 exit status
I think you probably want a -o in that command line:
gcc -g -Wall -o dene2 dene2.c
What you have there without the -o is trying to link dene2 with the result of compiling dene2.c. dene2 is probably left over in your directory from previous build attempt. That's why you're seeing all the duplicate symbol errors.
You are missing the -o in your compile line.
gcc -g -Wall -o dene2 dene2.c
The linker is trying to link your executable together with the source code you're current compiling, resulting in multiple definitions.

Resources