我正在开发一个大型的混合C ++ / Fortran项目。目前,可执行文件会在启动前立即进行段错误,然后才能达到main
,AFAICT。实际上在加载共享库之前。
一些输出:
$ ./myprog
Segmentation fault (core dumped)
$ gdb ./myprog core
GNU gdb (Ubuntu 7.7-0ubuntu3) 7.7
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./myprog...done.
[New LWP 9194]
bt
Core was generated by `./myprog'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x0000000000000001 in ?? ()
(gdb) bt
#0 0x0000000000000001 in ?? ()
#1 0x00007fff08fa02ca in ?? ()
#2 0x0000000000000000 in ?? ()
此外:
$ LD_DEBUG=all ./myprog
Segmentation fault (core dumped)
$ ldd ./myprog
linux-vdso.so.1 => (0x00007fffd81fe000)
libxerces-c-3.1.so => /usr/lib/x86_64-linux-gnu/libxerces-c-3.1.so (0x00007f774738e000)
libxml-security-c.so.17 => /usr/lib/x86_64-linux-gnu/libxml-security-c.so.17 (0x00007f7747083000)
libblas.so.3 => /usr/lib/libblas.so.3 (0x00007f7746ab6000)
liblapack.so.3 => /usr/lib/liblapack.so.3 (0x00007f774631a000)
libboost_serialization.so.1.54.0 => /usr/lib/x86_64-linux-gnu/libboost_serialization.so.1.54.0 (0x00007f77460af000)
libboost_filesystem.so.1.54.0 => /usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.54.0 (0x00007f7745e98000)
libboost_system.so.1.54.0 => /usr/lib/x86_64-linux-gnu/libboost_system.so.1.54.0 (0x00007f7745c94000)
libhdf5_cpp.so.7 => /usr/lib/x86_64-linux-gnu/libhdf5_cpp.so.7 (0x00007f7745a43000)
libhdf5.so.7 => /usr/lib/x86_64-linux-gnu/libhdf5.so.7 (0x00007f77455a6000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7745388000)
libgfortran.so.3 => /usr/lib/x86_64-linux-gnu/libgfortran.so.3 (0x00007f774506f000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7744e6a000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f7744b5f000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7744859000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f7744641000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f774427b000)
libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f7743ea1000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f7743c87000)
/lib64/ld-linux-x86-64.so.2 (0x00007f7756ed5000)
libquadmath.so.0 => /usr/lib/x86_64-linux-gnu/libquadmath.so.0 (0x00007f7743a49000)
可以看出,它取决于相当数量的库,但在LD加载其中任何一个之前崩溃。我不知道下一步该去哪儿。有什么建议吗?
答案 0 :(得分:2)
这是因为使用-fPIC
编译目标文件而使用-shared
编译可执行文件。