Aks*_*589 4 c gcc eclipse-cdt math.h ubuntu-12.04
我在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
Run Code Online (Sandbox Code Playgroud)
有谁能帮我弄清楚问题是什么以及如何解决?
您需要在目标文件之后链接库.
你有:
gcc -L/lib/i386-linux-gnu -lm -pthread -o "Project1" ./project1.o ./scheduler.o
Run Code Online (Sandbox Code Playgroud)
你需要:
gcc -L/lib/i386-linux-gnu -pthread -o "Project1" ./project1.o ./scheduler.o -lm
Run Code Online (Sandbox Code Playgroud)
链接器的工作方式似乎发生了变化 - 在某些时候,可以在目标文件之前指定共享库(例如数学库),并且一切都可以工作.但是,如今,如果共享库在扫描时不满足任何符号,则在链接过程中将其省略.确保在库修复之前列出目标文件.
另请参见对'pthread_create'的未定义引用 ; 同样的问题,相同的解决方 我怀疑这是否是SO中唯一的问题.