Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linker Error : gcc

I am getting this error every time, while compiling programs, configuring and installing
some things like binutils, textinfo, etc..

 /usr/local/bin/ld: this linker was not configured to use sysroots
 collect2: error: ld returned 1 exit status

I want to know clearly about this. When will will come and what is the actual problem, and also how to solve it?

like image 380
Reddi Rajendra P Avatar asked May 08 '13 09:05

Reddi Rajendra P


People also ask

How do I fix linker error?

You can fix the errors by including the source code file that contains the definitions as part of the compilation. Alternatively, you can pass . obj files or . lib files that contain the definitions to the linker.

What is a linker error?

Linker errors occur when the linker is trying to put all the pieces of a program together to create an executable, and one or more pieces are missing. Typically, this can happen when an object file or libraries can't be found by the linker.

Does GCC have a linker?

GCC uses a separate linker program (called ld.exe ) to perform the linking.

How do I fix the linker error C++ undefined symbol?

So when we try to assign it a value in the main function, the linker doesn't find the symbol and may result in an “unresolved external symbol” or “undefined reference”. The way to fix this error is to explicitly scope the variable using '::' outside the main before using it.


2 Answers

If you were attempting to install a version of binutils that should work alike the one found in /usr/bin, you should know that

  • gcc invokes ld with a --sysroot=/ option.
  • ld of binutils built from source with the default options rejects a --sysroot option.
  • A --sysroot option will only be accepted by ld if binutils was configured with option --with-sysroot.

So, to cover this use-case, configure binutils with option --with-sysroot=/.

like image 181
Bruno Haible Avatar answered Sep 18 '22 07:09

Bruno Haible


Try to use gcc with the following option: gcc --sysroot=/usr/local

But, as the others told you in the comments, don't try to mess your system with critical packages such as the binutils, except if you know what you are doing.

like image 21
perror Avatar answered Sep 18 '22 07:09

perror