c - 使用 gcc 编译时对 pow 的未定义引用
问题描述
我pow
在 C 中使用函数并包含math.h
库
以下是我得到的错误:
/usr/bin/ld: /tmp/ccUkOL31.o: in function `main': a1B.c:(.text+0xf3): undefined reference to 'pow' collect2: error: ld returned 1 exit status
虽然我在 StackOverflow 上读到需要链接。但这很奇怪。当我们使用gcc
. g++
似乎是自动执行的。
解决方案
Is there any way to avoid that extra step when we are compiling with gcc?
The way I do it is having a script that invokes gcc
(I have ~/bin
in my SPATH
)
$ cat ~/bin/mycc
#!/bin/sh
gcc -std=c11 -pedantic -Wall $* -lm
$ mycc example1.c example2.c
推荐阅读
- oop - DAO 和 SOLID 设计原则
- amazon-dynamodb - 可查询的未绑定数量
- sql-server - 如何使用 SQL Server OPENQUERY 一次删除 1000 行
- discord.py - Discord Bot 发送多条消息
- swift - 使用 NetworkExtension API 在 macOS 中实现 Web 过滤器
- php - Laravel Nova:向 Laravel Nova 资源添加行号(非 ID)
- javascript - 寻求建议如何处理这个嵌套的 JSON/Object
- c - 为什么 `volatile` 变量的值不会改变?
- python - 在Python2.7的函数中独立执行代码块
- javascript - 页面加载时调用 Javascript onclick 函数