簡體   English   中英

UNIX C中的gcc -lcrypt標志錯誤 - 未定義對crypt()的引用

[英]gcc -lcrypt flag error in UNIX C - Undefined Reference to crypt()

我使用crypt()函數和名為-lcrypt的編譯標志,問題是編譯器說對crypt()未定義引用。 誰能告訴我我做錯了什么?

Makefile文件

    CC = gcc
    CFLAGS=-Wall -lm -lcrypt
    OBJS = get_passwords_hashed.o
    PROG = get_passwords_hashed.exe

    #adicionar or mudar o OBJS se tiver outras files para o programa


    #GENERIC

    all:    ${PROG}

    clean:
            rm ${OBJS} *~ ${PROG}

    ${PROG}: ${OBJS}
            ${CC} ${OBJS} -o $@

    .c.o:
            ${CC} $< -c -o $@
    # $@ - turns .c into .o 
    ###################################
    #dependencias
    so_final.o: get_passwords_hashed.c get_passwords_hashed.h

main.c中

#include <stdio.h>
#include <string.h>
#include <crypt.h>

int testar_pass(char ant[],char (*pointer_hashes)[max_chars_string]){ // ponteiro para array de chars - char ** ant
     char * password ;
     char * encrypted;
     password = malloc(strlen(ant)*sizeof(char)); //password calculada recebida anteriror
     encrypted = malloc(strlen(ant)*sizeof(char));//hash
     strcpy(password,ant);
     encrypted = crypt(password,"10");
     if(strcmp(*pointer_hashes,encrypted) == 0){
         return 1;
         }
     else return 0;// devolve erro
}

在編譯行的末尾傳遞-lm -lcrypt

LIBS=-lm -lcrypt

${CC} ${OBJS} -o $@ ${LIBS}

編輯:

gcc 手冊解釋為什么它會產生影響(如評論中所要求的):

-llibrary

[...]

它在您編寫此選項的命令中有所不同; 鏈接器按照指定的順序搜索和處理庫和目標文件。

因此,'foo.o -lz bar.o'在文件'foo.o'之后但在'bar.o'之前搜索庫'z'。 如果'bar.o'引用'z'中的函數,則可能無法加載這些函數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM