链接器错误"找不到-l / some / path / libfilename"

时间:2014-06-07 10:09:14

标签: c linker-errors

我在windows中设置了eclipse,并试图编译一个与POS设备相关的简单代码,但我得到错误的代码是:

#include <posapi.h>
#include <printer.h>
#include <stdio.h>
#include <stdlib.h>

int main(void) {

printf ("Beeping...");
beep(100,2000);
printf("Stop Beeping.");

return 0;
}

,错误是:

cannot find -l/cygdrive/d/Docs/SDK/SDK/Windows/sdk-new8210-1.0.0/sdk/lib/libpos.so

[评论更新]

这是命令行:

/cygdrive/c/glibc-oabi-toolchain-arm-generic/bin/arm-unknown-linux-gnu-gcc -I"C:\cygwin\usr\include" -I"D:\Docs\SDK\SDK\Windows\sdk-new8210-1.0.0\sdk\include" -I"D:\Docs\SDK\SDK\Windows\sdk-new8210-1.0.0\sdk\include\directfb" -O0 -g3 -Wall -c -fmessage-length=0 -Wundef -Wstrict-prototypes -Werror-implicit-function-declaration -Wdeclaration-after-statement -fsigned-char -marm -mapcs -mno-sched-prolog -mabi=apcs-gnu -mlittle-endian -mno-thumb-interwork -msoft-float -MMD -MP -MF"src/DemoApp5.d" -MT"src/DemoApp5.d" -o "src/DemoApp5.o" "../src/DemoApp5.c" 

2 个答案:

答案 0 :(得分:1)

链接器选项-l未通过“path / filename”指定libray,而是仅通过其名称指定。这是带有前导“lib”的文件名。在你的情况下,它将是

-lpos

要另外指定搜索路径,请使用选项-L(在引用-l选项之前)。所以在你的情况下,这可能是:

-Ld/Docs/SDK/SDK/Windows/sdk-new8210-1.0.0/sdk/lib/ -lpos

-L-l可以多次使用)

答案 1 :(得分:0)

您滥用-l标志来指定要链接的库。使用:

-L /cygdrive/d/Docs/SDK/SDK/Windows/sdk-new8210-1.0.0/sdk/lib/ -lpos

代替。 -L指定了查找库的其他位置,-l指定了库的名称(没有初始lib...)。