Linux编译C语言时出错 /home/zwlong/222/LESduct2.c:323: undefined reference to `sqrt'

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux编译C语言时出错 /home/zwlong/222/LESduct2.c:323: undefined reference to `sqrt'相关的知识,希望对你有一定的参考价值。

Linux编译C语言时出错 /home/zwlong/222/LESduct2.c:321: undefined reference to `sqrt' /home/zwlong/222/LESduct2.c:323: undefined reference to `pow' /home/zwlong/222/LESduct2.c:325: undefined reference to `sqrt' /home/zwlong/222/LESduct2.c:332: undefined reference to `sqrt'

参考技术A undefined
reference未定义的引用,指的是编译器在链接的时候没有找到相应函数的原型。缺少相应的头文件,因为头文件中定义了函数的原型。
加上#include
试试。
参考技术B 使用man
3
sqrt查看这个sqrt出自什么地方啊!
#include
undefined
reference表示这个函数不能链接,亦即没有定义,要么自己重新定义,要么链接到系统的函数库。
参考技术C sqrt
应该是数学库里的东东,你在那函数前面得加上
#include

Linux内核出错

我在尝试编译Linux内核时遇到以下错误,同样来自kernel.org的4.14 rc2和来自kernel.org的4.13.4以及使用git克隆的linux-stable。

root@kami:/home/linux-stable# make O=/home/LINUX
make[1]: Entering directory '/home/LINUX'
  CHK     include/config/kernel.release
  Using /home/linux-stable as source for kernel
  GEN     ./Makefile
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  UPD     include/generated/utsrelease.h
  CC      kernel/bounds.s
  CHK     include/generated/bounds.h
  UPD     include/generated/bounds.h
  CHK     include/generated/timeconst.h
  UPD     include/generated/timeconst.h
  CC      arch/x86/kernel/asm-offsets.s
  CHK     include/generated/asm-offsets.h
  UPD     include/generated/asm-offsets.h
  CALL    /home/linux-stable/scripts/checksyscalls.sh
  DESCEND  objtool
  CC       /home/LINUX/tools/objtool/orc_dump.o
orc_dump.c: In function 'orc_dump':
orc_dump.c:105:26: error: passing argument 2 of 'elf_getshdrnum' from       incompatible pointer type [-Werror=incompatible-pointer-types]
  if (elf_getshdrnum(elf, &nr_sections)) {
                      ^
In file included from /usr/local/include/gelf.h:32:0,
                 from elf.h:22,
                 from warn.h:26,
                 from orc_dump.c:20:
/usr/local/include/libelf.h:304:12: note: expected 'size_t * {aka unsigned     int *}' but argument is of type 'long unsigned int *'
 extern int elf_getshdrnum (Elf *__elf, size_t *__dst);
        ^~~~~~~~~~~~~~
orc_dump.c:190:17: error: format '%lx' expects argument of type 'long   unsigned int', but argument 3 has type 'Elf64_Sxword {aka long long int}'    [-Werror=format=]
    printf("%s+%lx:", name, rela.r_addend);
               ~~^          ~~~~~~~~~~~~~
               %llx
cc1: all warnings being treated as errors
mv: cannot stat '/home/LINUX/tools/objtool/.orc_dump.o.tmp': No such file  or directory
/home/linux-stable/tools/build/Makefile.build:95: recipe for target '/home  /LINUX/tools/objtool/orc_dump.o' failed
make[4]: *** [/home/LINUX/tools/objtool/orc_dump.o] Error 1
Makefile:41: recipe for target '/home/LINUX/tools/objtool/objtool-in.o'   failed
make[3]: *** [/home/LINUX/tools/objtool/objtool-in.o] Error 2
Makefile:61: recipe for target 'objtool' failed
make[2]: *** [objtool] Error 2
/home/linux-stable/Makefile:1622: recipe for target 'tools/objtool' failed
make[1]: *** [tools/objtool] Error 2
make[1]: Leaving directory '/home/LINUX'
Makefile:145: recipe for target 'sub-make' failed
make: *** [sub-make] Error 2

如果有人可以提供帮助,我将不胜感激。

似乎是精灵和兽人的问题。

我正在使用knoppix 8.1 64位安装,但平台运行在32位。我已经安装了内核自述文件中指定的所有最低要求。我尝试使用我自己选择的选项中的.config文件和oldconfig选项以及localmodconfig选项。

答案

我安装了4.13(metapackage)的linux-headers,它通过从kernel.org版本4.13.4下载的源代码满足了对CONFIG_STACK_VALIDATION的需求的elfs和orcs。

虽然它没有超过来自git的linux-stable的精灵和兽人。

我有一些新的错误,一些司机没有建立。

root@kami:/home/linux-4.13.4# make O=/home/linux-4134
make[1]: Entering directory '/home/linux-4134'
  CHK     include/config/kernel.release
  Using /home/linux-4.13.4 as source for kernel
  GEN     ./Makefile
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  CHK     include/generated/bounds.h
  CHK     include/generated/timeconst.h
  CHK     include/generated/asm-offsets.h
  CALL    /home/linux-4.13.4/scripts/checksyscalls.sh
  DESCEND  objtool
  CHK     scripts/mod/devicetable-offsets.h
  CHK     include/generated/compile.h
  CHK     kernel/config_data.h
  BLD FW  drivers/net/wan/wanxlfw.inc
/bin/sh: as68k: command not found
/home/linux-4.13.4/drivers/net/wan/Makefile:58: recipe for target 'drivers/net/wan/wanxlfw.inc' failed
make[4]: *** [drivers/net/wan/wanxlfw.inc] Error 127
/home/linux-4.13.4/scripts/Makefile.build:561: recipe for target 'drivers/net/wan' failed
make[3]: *** [drivers/net/wan] Error 2
/home/linux-4.13.4/scripts/Makefile.build:561: recipe for target 'drivers/net' failed
make[2]: *** [drivers/net] Error 2
/home/linux-4.13.4/Makefile:1019: recipe for target 'drivers' failed
make[1]: *** [drivers] Error 2
make[1]: Leaving directory '/home/linux-4134'
Makefile:145: recipe for target 'sub-make' failed
make: *** [sub-make] Error 2

以上是关于Linux编译C语言时出错 /home/zwlong/222/LESduct2.c:323: undefined reference to `sqrt'的主要内容,如果未能解决你的问题,请参考以下文章

Linux下C/C++动态库在运行时是怎样加载进来的

在 openSUSE 上用 C 语言在 mpi 中编译 hello world 程序时出错

c/c++ 数据库连接时编译出错

如何在Linux下用C/C++语言操作数据库sqlite3

Openwrt 编译ipk出错,如下错误,怎么解决? denghuinow@Ubuntu:

Linux内核出错