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

时间:2015-10-13 23:57:27

标签: c gcc makefile cygwin gnu-make

我在此源代码中运行命令“ 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.so 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

有人会知道如何解决这个错误吗?

谢谢!

2 个答案:

答案 0 :(得分:2)

正如@missimer所建议的那样,你的makefile中没有为链接器选项'-Wl'指定选项字段。

通常,为了创建共享库,以下语法与'-Wl'一起使用:

gcc -shared -Wl,-export-dynamic 

希望这会对你有所帮助。

答案 1 :(得分:0)

代码的另一个分支处理Cygwin并且具有不同的Makefile。

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

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