我想为我当前正在编写的程序制作一个Makefile
,但在编译时遇到问题。到目前为止,我只是将源文件包含到 main
中并使用以下命令进行编译:
gcc main.c -lcrypto -lssl
我在我的程序中使用 openssl。但当我读到这不是一个好的做法时,我想编写一个 make 文件并将头文件包含在 main
中。但我有以下问题:
我想首先制作 .o
文件:
gcc -lcrypto -lssl -c read_and_send.c
但是对于这个,我遇到了很多错误(未知的类型名称),这些类型是在 OpenSSL 库中定义的。我不知道如何修复它,因为使用我会写的数学库:
gcc -lm -c read_and_send.c
我不会吗?
我期待收到您的来信。
亲切的问候
绿色环保
最佳答案
But for this one I get a lot of errors (unkown type name), the types that where defined in the openssl library.
您需要在 read_and_send.c
中包含 openssl header
您应该阅读有关 C 编程以及如何使用 header 以及如何编译和链接的基本教程。
I have no clue how to fix it as for using the math library I would write:
gcc -lm -c read_and_send.c
wouldn't I?
不,-c
选项意味着您只想将源代码编译为.o
文件,而不是链接,因此不使用库,并且任何 >-l
选项将被忽略。
将所有 .o
文件链接在一起以创建可执行文件时,需要使用 -l
选项。当您执行该链接步骤时,库应该位于命令的末尾,位于依赖它们的文件之后。
关于c - gcc -c 失败,尽管它已链接到所需的库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25308800/