C:对地板的未定义引用

C:对地板的未定义引用,c,gcc,eclipse-cdt,ubuntu-12.04,math.h,C,Gcc,Eclipse Cdt,Ubuntu 12.04,Math.h,我正在Ubuntu上使用Eclipse编写/编译/运行C代码。 我正在努力建立我的项目。 以下是Eclipse控制台中的输出 22:18:31 **** Build of configuration Debug for project Project1 **** make all Building file: ../project1.c Invoking: GCC C Compiler gcc -I/lib/i386-linux-gnu -O0 -g3 -Wall -c -fmessage-l

我正在Ubuntu上使用Eclipse编写/编译/运行C代码。 我正在努力建立我的项目。 以下是Eclipse控制台中的输出

22:18:31 **** Build of configuration Debug for project Project1 ****
make all 
Building file: ../project1.c
Invoking: GCC C Compiler
gcc -I/lib/i386-linux-gnu -O0 -g3 -Wall -c -fmessage-length=0 -pthread -lm -MMD -MP -MF"project1.d" -MT"project1.d" -o "project1.o" "../project1.c"
../project1.c: In function ‘main’:
../project1.c:146:6: warning: unused variable ‘this_thread_id’ [-Wunused-variable]
../project1.c: In function ‘_pre_init’:
../project1.c:126:1: warning: control reaches end of non-void function [-Wreturn-type]
Finished building: ../project1.c

Building file: ../scheduler.c
Invoking: GCC C Compiler
gcc -I/lib/i386-linux-gnu -O0 -g3 -Wall -c -fmessage-length=0 -pthread -lm -MMD -MP -MF"scheduler.d" -MT"scheduler.d" -o "scheduler.o" "../scheduler.c"
Finished building: ../scheduler.c

Building target: Project1
Invoking: GCC C Linker
gcc -L/lib/i386-linux-gnu -lm -pthread -o "Project1"  ./project1.o ./scheduler.o   
./project1.o: In function `advance_global_time':
/home/akshay/Cworkspace/Project1/Debug/../project1.c:50: undefined reference to `floor'
collect2: ld returned 1 exit status
make: *** [Project1] Error 1

有人能帮我找出问题所在以及解决方法吗?

您需要链接数学库,即在链接行末尾添加
-lm
。抱歉,不知道如何在Eclipse中实现这一点。

注意,输出中的链接标志看起来有问题。可能您试图通过Eclipse中的链接器标志添加
-lm
。这会导致Eclipse中出现问题。我建议你试试

右键单击项目->属性->C/C++构建->设置 ->GCC链接器->库->添加“m”->应用->构建

或者,在这个列表中,确保在链接过程中,-L和-L参数位于.o文件之后


我今天刚刚被这个问题困扰了一段时间。你需要在对象文件之后链接库

你有:

gcc -L/lib/i386-linux-gnu -lm -pthread -o "Project1"  ./project1.o ./scheduler.o   
你需要:

gcc -L/lib/i386-linux-gnu -pthread -o "Project1"  ./project1.o ./scheduler.o -lm 
链接器的工作方式似乎发生了变化——在某些时候,可以在对象文件之前指定共享库(如数学库),所有这些都可以工作。然而,如今,如果共享库在扫描时不满足任何符号,则链接过程中会忽略它。确保在库修复此问题之前列出对象文件


另见;同样的问题,同样的解决方案。我怀疑这是否是唯一这样的问题。

你是如何添加数学库的?请参阅以获取可能的解决方案。右键单击项目->属性->C/C++构建->设置->GCC链接器->库->添加“m”->应用->构建”的可能重复项已工作。非常感谢!