My OS is Ubuntu Linux 20.04
I reinstalled gcc and some libraries
I didn't change anything in the system, I don't know what could have happened.
Error:
/usr/bin/ld: /lib/x86_64-linux-gnu/libc.so.6: unknown type [0x13] section `.relr.dyn'
/usr/bin/ld: skipping incompatible /lib/x86_64-linux-gnu/libc.so.6 when searching for /lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: cannot find /lib/x86_64-linux-gnu/libc.so.6
/usr/bin/ld: /lib64/ld-linux-x86-64.so.2: unknown type [0x13] section `.relr.dyn'
/usr/bin/ld: skipping incompatible /lib64/ld-linux-x86-64.so.2 when searching for /lib64/ld-linux-x86-64.so.2
/usr/bin/ld: cannot find /lib64/ld-linux-x86-64.so.2
collect2: error: ld returned 1 exit status
Code:
#include <stdio.h>
int main()
{
printf("Hello, world!\n");
return 0;
}
You've updated gcc and libc, but not binutil. This will update ld to understand .relr.dyn.
Related
I have a sample code temp.c:
#include "win.h"
win.h is in /home/me/Documents/Code/libs/TUI/win.h and has all the declared functions
which functions are defined in some files in /home/me/Documents/Code/libs/TUI/win/[lots of files].c which every file starts with
#include "../win.h"
//functions
So while using gcc -I /home/me/Documents/Code/libs/TUI /home/me/Documents/Code/temp.c -o /home/me/Documents/Code/temp, gcc returns every function used in temp.c declared in win.h as undefined
Exact output:
gcc -g -I/home/me/Documents/Code/libs/TUI /home/me/Documents/Code/temp.c -o /home/pk/Documents/Code/temp
/usr/bin/ld: /tmp/cc4berEn.o: in function `main':
/home/me/Documents/Code/temp.c:8: undefined reference to `innit'
/usr/bin/ld: /home/me/Documents/Code/temp.c:11: undefined reference to `newTable'
/usr/bin/ld: /home/me/Documents/Code/temp.c:13: undefined reference to `tableSetHeaders'
/usr/bin/ld: /home/me/Documents/Code/temp.c:35: undefined reference to `tableAppendRow'
/usr/bin/ld: /home/me/Documents/Code/temp.c:45: undefined reference to `printTable'
collect2: error: ld returned 1 exit status
notes
Using -I /home/me/Documents/Code/libs/TUI/win.h returns fatal error: win.h: No such file or directory 3 | #include "win.h"
/home/me/Documents/Code/libs/TUI is a folder
Writing every source file's name is not an option
Already tried this
-g for debug
I'm currently attempting to install graphics.h on manjaro, but the library doesn't seem to work. Currently I am getting the following errors when I try running the following code:
#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>
int main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, NULL);
circle(50, 50, 30);
delay(500000);
closegraph();
return 0;
}
/usr/bin/ld: /tmp/ccm2VUMu.o: in function `main':
circle.c:(.text+0x32): undefined reference to `initgraph'
/usr/bin/ld: circle.c:(.text+0x46): undefined reference to `circle'
/usr/bin/ld: circle.c:(.text+0x55): undefined reference to `delay'
/usr/bin/ld: circle.c:(.text+0x5a): undefined reference to `closegraph'
collect2: error: ld returned 1 exit status
I installed graphics.h from the arch user repository using yay, and have made sure to install it's dependencies (guile, sdl, sdl_image), so I'm not sure where to go next.
I have a very simple code:
#include <openssl/sha.h>
int main() {
SHA_CTX sha1;
SHA_Init(&sha1);
}
I have installed both libssl-dev and libcrypto++-dev:
However I have a build failure using the following command:
$ gcc -lcrypto -lssl main.c
/tmp/ccfnCAxT.o: In function `main':
main.c:(.text+0x1f): undefined reference to `SHA1_Init'
collect2: error: ld returned 1 exit status
$
$ gcc -lssl main.c
/tmp/ccfnCAxT.o: In function `main':
main.c:(.text+0x1f): undefined reference to `SHA1_Init'
collect2: error: ld returned 1 exit status
Platform: Ubuntu 16.04
-lssl is not needed, -lcrypto is enough, and it must be at the end:
gcc -o main main.c -lcrypto
(or whatever you want your program to be called goes after -o)
I have a very simple program (simple.c):
#include <stdio.h>
int main(){
int a = 4;
return 0;
}
I am trying to use a the following linker script (MEMORY):
MEMORY
{
m_text : ORIGIN = 0x0000000000400000, LENGTH = 0x0001FBF0
m_data : ORIGIN = 0x0000000000600000, LENGTH = 0x00004000
}
SECTIONS
{
.text :
{
*(.text) /* Program Code */
} > m_text
.data : { *(.data) } > m_data
.bss : { *(.bss) } > m_data
}
I am using following commands to compile and link:
gcc -c simple.c
ld -T MEMORY -o simple -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o /usr/lib/x86_64-linux-gnu/crtn.o simple.o
I am getting the following ERROR:
ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
.
.
.
ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_line): relocation 0 has invalid symbol index 2
/usr/lib/x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x12): undefined reference to `__libc_csu_fini'
/usr/lib/x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x19): undefined reference to `__libc_csu_init'
/usr/lib/x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x25): undefined reference to `__libc_start_main'
simple.o: In function `main':
simple.c:(.text+0xa): undefined reference to `puts'
If I try to use :
ld -T MEMORY4 -o simple -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o /usr/lib/x86_64-linux-gnu/crtn.o simple.o -lc
It gives the ERROR
ld: cannot find -lc
Any suggestions? All I want to do is place my simple.c into some different memory region then default.
There are a couple of problems, but the main one is with your linker script doesn't have a .debug_info or .debug_line section.
I have an ultra-simple C program:
#include <stdio.h>
main()
{
printf("This is a C program\n");
}
which does not compile, yielding the error:
cc main.c
/usr/bin/ld: cannot find -lgcc_s
collect2: ld returned 1 exit status
Compilation exited abnormally with code 1 at Sun Oct 30 01:42:10
sudo ln -s /lib/libgcc_s.so.1 /lib/libgcc_s.so
Per this post this works great!