linux 解决.../bin/ld: cannot find -lxxx 问题+Segmentation fault (core dumped)

(注意!在jupyer内直接!export PATH是无效的,应该是%env PATH)

我的报错情况是这样的:

wjn@xxx137:~/2018-daguan-competition/biGruModel/glove$ make
mkdir -p build
gcc src/glove.c -o build/glove -lm -pthread -Ofast -march=native -funroll-loops -Wall -Wextra -Wpedantic
In file included from src/glove.c:25:0:
/home/wangjiana/.linuxbrew/Cellar/gcc/5.5.0_4/lib/gcc/x86_64-unknown-linux-gnu/5.5.0/include/stdint.h:9:26: fatal error: stdint.h: No such file or directory
compilation terminated.
make: *** [glove] Error 1

已经对上面的问题有经验了:碰到No such file or directory就意识到是某个系统变量需要重新export,参考我的另一篇(未公开):《fatal error: libxml/parser.h: No such file or directory解决方法》,知道应该修改C_INCLUDE_PATH。首先执行locate stdint.h,发现不少包含stdint.h的路径,选择其中一条或几条加入——执行:

export C_INCLUDE_PATH=/home/wangjiana/.linuxbrew/Cellar/gcc/5.5.0_4/lib/gcc/x86_64-unknown-linux-gnu/5.5.0/include:/home/wangjiana/.linuxbrew/Cellar/gcc/5.5.0_4/include/c++/5.5.0:/home/wangjiana/.linuxbrew/Cellar/glibc/2.23/include:/usr/include:/usr/local/include:$HOME/.local/include:$C_INCLUDE_PATH

为了保险起见上面的命令已经放到ssh.sh里了,每次打开会自动执行。

(这里还有一个可能要执行的,但是似乎不执行也可以,先不要执行:

export PATH=/home/wangjiana/.linuxbrew/bin/gcc:$PATH

然后报错变成了:

wjn@xxx137:~/2018-daguan-competition/biGruModel/glove$ make
mkdir -p build
gcc src/glove.c -o build/glove -lm -pthread -Ofast -march=native -funroll-loops -Wall -Wextra -Wpedantic
src/glove.c: In function 'save_params':
src/glove.c:249:57: warning: 'fgs' may be used uninitialized in this function [-Wmaybe-uninitialized]
                 for (b = 0; b < (vector_size + 1); b++) fprintf(fgs," %lf", gradsq[a * (vector_size
                                                         ^
/home/wangjiana/.linuxbrew/bin/ld: cannot find -lm
/home/wangjiana/.linuxbrew/bin/ld: cannot find -lpthread
/home/wangjiana/.linuxbrew/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
make: *** [glove] Error 1

终于进入正题了!这种错误也是有套路的!

如果报错是cannot find -lxxx,那么缺的文件就是libxxx.so。locate找一下:

wjn@xxx137:~/.linuxbrew/lib$ locate libpthread.so
/home/wangjiana/.linuxbrew/Cellar/glibc/2.23/lib/libpthread.so
/home/wangjiana/.linuxbrew/Cellar/glibc/2.23/lib/libpthread.so.0
/lib/x86_64-linux-gnu/libpthread.so.0
/lib32/libpthread.so.0
/usr/lib/x86_64-linux-gnu/libpthread.so

如果选择把上面的路径放到export LD_LIBRARY_PATH里面,那么之后输入任何东西都会出现segmentation fault,所以不能这样做(为什么我还没搞明白)

换方法。缺什么补什么。报错的路径是/home/wangjiana/.linuxbrew/bin,那么libxxx.so放的路径应该是/home/wangjiana/.linuxbrew/lib!

执行:

ln -s /usr/lib/x86_64-linux-gnu/libm.so /home/wangjiana/.linuxbrew/bin/libm.so
ln -s /usr/lib/x86_64-linux-gnu/libpthread.so /home/wangjiana/.linuxbrew/bin/libpthread.so
ln -s /usr/lib/x86_64-linux-gnu/libc.so /home/wangjiana/.linuxbrew/bin/libc.so

再次make,解决。其它的问题也是,如果能加入LD_LIBRARY_PATH就加,如果加了后报错Segmentation fault (core dumped),就用ln -s 链接到 /home/wangjiana/.linuxbrew/lib下(如ln -s /lib/x86_64-linux-gnu/libglib-2.0.so.0 /home/wangjiana/.linuxbrew/lib/libglib-2.0.so.0,注意这里是lib不是bin,和上面不同!注意再次使用locate查看是否链接成功)

你可能感兴趣的:(linux 解决.../bin/ld: cannot find -lxxx 问题+Segmentation fault (core dumped))