---
title: "使用Eclipse编译c程序 数学函数提示undefined reference to “XXX”的解决方法"
author: "roufenghust"
date: "2014-04-15T21:39:50Z"
tags: ["Eclipse", "GCC"]
categories: ["编程语言"]
slug: "eclipse-c-undefined-reference-to-xxx"
draft: false
lastmod: "2014-04-15T21:39:28Z"
id: 2047081
url: "https://semantic.iteye.com/blog/2047081"
---

用Eclipse编译使用数学函数的C语言程序时，如sqrt,pow，即使已经加入math.h，也会提示类似于undefined reference to `sqrt’这样的错误。搜索得知需要给gcc加上-lm参数.
添加参数方法：
<span style="color:red">右键点击当前 project 选中 properties菜单->C/C++ build -> Settings -> GCC C Linker ->Libraries ->新建参数m</span>


![](http://dl2.iteye.com/upload/attachment/0096/1462/167e88f8-4c08-32d1-bbdd-d7033f0d6ef3.jpg)