c语言 - gcc:错误:Makfile 中'-Wl'无法识别的命令行选项



我在源代码中运行"make test"命令:

https://github.com/sanandrea/CSecretKey

但是它给了我这个错误:

gcc: error: unrecognized command line option '-Wl'
Makefile:18: recipe for target 'lib_plain' failed
make: *** [lib_plain] Error 1

这是makefile中的第18行gcc -shared -Wl -o libhmacenc。所以hmac_256_plain。用户o sha2。o lc

这是文件列表:

  • Android.mk
  • hmac_sha256.c
  • hmac_sha256.h
  • reverse_test.py
  • sha2.c
  • sha2.h
  • test.c

这是完整的"makefile":

all: lib test
test: clean lib_plain
    gcc -o test test.c -lhmacenc -L.
production: clean lib
    gcc -o test test.c -lhmacenc -L.
hmac_256.o: hmac_sha256.c hmac_sha256.h
    $(CC) -Wall -c hmac_sha256.c -o hmac_256.o
hmac_256_plain.o: hmac_sha256.c hmac_sha256.h
    $(CC) -Wall -DSHOW_PASS -c hmac_sha256.c -o hmac_256_plain.o
lib: hmac_256.o sha2.o
    gcc -shared -Wl -o libhmacenc.so hmac_256.o sha2.o -lc
lib_plain: hmac_256_plain.o sha2.o
    gcc -shared -Wl -o libhmacenc.so hmac_256_plain.o sha2.o -lc
sha2.o: sha2.c sha2.h
    $(CC) -c sha2.c -o sha2.o
clean:
    - rm -rf *.o hmac *.so

有人会知道我怎么能修复这个错误?

谢谢!

根据@missimer的建议,在makefile中没有为链接器选项'-Wl'指定选项字段。

通常,对于创建共享库,使用'-Wl'使用以下语法:

gcc -shared -Wl,-export-dynamic 

还有一个处理Cygwin的代码分支,它有一个不同的Makefile。

https://github.com/sanandrea/CSecretKey/tree/cygwin

总是尝试使用GNU-Linux环境来编译纯c语言的程序。避免Cygwin,因为它们在Makefile中的行为是不同的。

最新更新