看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) windows 7, gcc 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) crypt32 問題(Question): link時顯示undefined reference to 'crypt' 預期的正確結果(Expected Output): 希望能夠正確link! 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版) --------main.c-------- #include <stdio.h> #include "DES.h" int main() { char plain[100]; char salt[3]; char cipher[20]; DES(plain, salt, cipher); return 0; } ---------------------- --------DES.h--------- void DES(char plain[], char salt[], char cipher[]); ---------------------- --------DES.c--------- #include <unistd.h> void DES(char plain[], char salt[], char cipher[]) { sprintf(cipher, "%s", crypt(plain, salt)); return; } ---------------------- 補充說明(Supplement): gcc -c DES.c gcc -c main.c gcc -o main.exe main.o DES.o 會跳出link時顯示undefined reference to 'crypt', 但如果把DES.c的內容全部塞進DES.h就能正確compile、link, 請問是哪裡做錯了嗎?囧 還請各位高手多多指教,感激不盡。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.133.99.64 ※ 編輯: BigTora 來自: 220.133.99.64 (06/23 20:39)
firejox:gcc又不知道你的DES.h指向哪裡 06/23 20:42
firejox:加一個 -I your_header_path 06/23 20:43
BigTora:謝謝回覆,我之前有試過指定路徑給他,還是沒有辦法link囧 06/23 20:53
suhorng:try: gcc -o main.exe main.c DES.c 06/23 21:04
suhorng:推測是少link了什麼lib之類的... 06/23 21:04
pico2k:gcc -o main.exe main.o DES.o -lcrypt32 06/23 21:07
BigTora:感謝三位,可以link了,也run得很順利! 06/23 21:12
BigTora:後來發現還要再link libcrypt.dll.a這個library,感恩! 06/23 21:14