LD_LIBRARY_PATH doesn't seem to work

前端 未结 3 822
广开言路
广开言路 2021-02-05 17:08

I\'m trying to compile a test file:

gcc -o test  test.c -lg2c

but I get the error:

/usr/bin/ld: cannot find -lg2c
相关标签:
3条回答
  • 2021-02-05 17:38

    Try setting LIBRARY_PATH, instead of LD_LIBRARY_PATH.

    From the gcc man page:

    LIBRARY_PATH

    The value of LIBRARY_PATH is a colon-separated list of directories, much like PATH. When configured as a native compiler, GCC tries the directories thus specified when searching for special linker files, if it can't find them using GCC_EXEC_PREFIX. Linking using GCC also uses these directories when searching for ordinary libraries for the -l option (but directories specified with -L come first).

    0 讨论(0)
  • 2021-02-05 17:42

    Make sure that you export LD_LIBRARY_PATH after modifying it. Otherwise GCC won't be able to see the modified version.

    LD_LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/3.4.6:$LD_LIBRARY_PATH
    export LD_LIBRARY_PATH
    gcc -o test test.c -lg2c
    
    0 讨论(0)
  • 2021-02-05 17:50

    Create a new folder inside your home directory (not root directory!). Copy all the required library associated with -lg2c from /usr/lib/gcc/x86_64-redhat-linux/3.4.6 to this folder.

    Set the path in your bash profile to this new folder.

    I also got this issue, and solve it with this workaround. Perhaps we (as non-root users) don't have the necessary access/right to /usr/lib/gcc/x86_64-redhat-linux/3.4.6

    0 讨论(0)
提交回复
热议问题