执行时:
gcc D:\project\c\test\collection -Wall -o test main.c -lfoo
它报告错误:
D:\project\c\test\collection>gcc D:\project\c\test\collection -Wall -o test main.c -lfoo
d:/gcc-9.2.0-no-debug/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
cannot find D:\project\c\test\collection: Permission denied
d:/gcc-9.2.0-no-debug/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
cannot find -lfoo
collect2.exe: error: ld returned 1 exit status
我按照此处找到的步骤操作:gcc example
我的操作系统是Windows 10,我使用具有管理员角色的cmd
。
更新1
我执行:
gcc -L D:\project\c\test\collection -Wall -o test main.c -lfoo
并得到错误:
gcc -L D:\project\c\test\collection -Wall -o test main.c -lfoo
d:/gcc-9.2.0-no-debug/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lfoo
collect2.exe: error: ld returned 1 exit status
我的收藏目录包含libfoo.so
文件:
2019/12/28 11:19 <DIR> .
2019/12/28 11:19 <DIR> ..
2019/12/28 10:55 3,262 a.exe
2019/12/28 10:38 87 foo.c
2019/12/28 10:37 80 foo.h
2019/12/28 10:38 838 foo.o
2019/12/28 10:38 47,372 libfoo.so
2019/12/28 10:38 134 main.c
更新2
我更改执行:
gcc -L / -Wall -o test main.c
并得到错误:
//libfoo.dll.a: Unrecognized file: File truncated,collect2.exe: error: ld returned 1 exit status
答案 0 :(得分:0)
gcc D:\project\c\test\collection -Wall -o test main.c -lfoo
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
不属于选项的文件(例如-o test
或-lfoo
)通常被认为是用于编译或链接的输入文件。
很有可能是定位foo
库的库位置,仅因为您所遵循的教程几乎完全相同:
gcc -L/home/username/foo -Wall -o test main.c -lfoo
如果是这种情况,那么您就缺少 -L
来告诉它应该将其添加到库搜索路径中,因此应通过以下方式对其进行修复:
gcc -L D:\project\c\test\collection -Wall -o test main.c -lfoo
在任何情况下,由于似乎所有文件都位于一个目录(源,库等)中,因此不需要来调整搜索路径。或者,如果您这样做,可以只使用-L.
指定当前目录,例如:
gcc -Wall -o test main.c -L. -lfoo