2017-08-30 79 views
0

我已經通過相關鏈接庫到計算器AC文件多的問題消失了,當無法找到libary文件,我也跟着方法如下錯誤:試圖鏈接庫文件

注:我的圖書館文件位於.c文件的相同位置。

如何解決這些錯誤?

  1. 使用庫名與擴展

CC consoleDemo.c -L。 -lusbcan64.a

-L {文件路徑包含庫} -1- $ {庫名稱} 以下是編譯的

/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lUSBCAN64.a 
collect2: error: ld returned 1 exit status 
  • 錯誤使用沒有擴展名的庫名稱
  • cc consoleDemo.c -L。 -lusbcan64

    以下是編譯

    /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible ./libUSBCAN64.a when searching for -lUSBCAN64 
    /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible ./libUSBCAN64.a when searching for -lUSBCAN64 
    /tmp/ccTh3hGd.o:ConsoleDemo.c:(.text+0x2b9): undefined reference to `_kbhit' 
    /tmp/ccTh3hGd.o:ConsoleDemo.c:(.text+0x2b9): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `_kbhit' 
    /tmp/ccTh3hGd.o:ConsoleDemo.c:(.text+0x2c6): undefined reference to `_getch' 
    /tmp/ccTh3hGd.o:ConsoleDemo.c:(.text+0x2c6): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `_getch' 
    /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../lib/USBCAN64.lib(USBCAN64.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_UcanInitHardware' defined in .idata$5 section in /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../lib/USBCAN64.lib(USBCAN64.dll.b) 
    /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../lib/USBCAN64.lib(USBCAN64.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_UcanDeinitHardware' defined in .idata$5 section in /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../lib/USBCAN64.lib(USBCAN64.dll.b) 
    /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../lib/USBCAN64.lib(USBCAN64.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_UcanGetModuleTime' defined in .idata$5 section in /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../lib/USBCAN64.lib(USBCAN64.dll.b) 
    /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../lib/USBCAN64.lib(USBCAN64.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_UcanInitCanEx2' defined in .idata$5 section in /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../lib/USBCAN64.lib(USBCAN64.dll.b) 
    /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../lib/USBCAN64.lib(USBCAN64.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_UcanResetCanEx' defined in .idata$5 section in /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../lib/USBCAN64.lib(USBCAN64.dll.b) 
    /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../lib/USBCAN64.lib(USBCAN64.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_UcanReadCanMsgEx' defined in .idata$5 section in /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../lib/USBCAN64.lib(USBCAN64.dll.b) 
    /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../lib/USBCAN64.lib(USBCAN64.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_UcanWriteCanMsgEx' defined in .idata$5 section in /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../lib/USBCAN64.lib(USBCAN64.dll.b) 
    /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../lib/USBCAN64.lib(USBCAN64.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_UcanGetStatusEx' defined in .idata$5 section in /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../lib/USBCAN64.lib(USBCAN64.dll.b) 
    /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../lib/USBCAN64.lib(USBCAN64.dll.b):(.text+0x2): additional relocation overflows omitted from the output 
    collect2: error: ld returned 1 exit status 
    
    +1

    什麼問題? –

    +0

    將您的lib重命名爲libusbcan32.a,然後嘗試cc consoleDemo.c -L。 -lusbcan32 – Pras

    +0

    「.a」文件的實際名稱是什麼? –

    回答

    0

    的錯誤第一次嘗試作爲-l標誌和不能同時被指定。一個後綴根本無效。你的第二次嘗試暴露了三種問題。

    1. 一個不兼容的libUSBCAN64.a版本(可能是因爲錯誤的操作系統或CPU)。不是一個大問題,因爲你有最終發現的正確版本,但是一個惱人的警告。只要刪除該文件。
    2. kbhit和getch的未定義符號。這些是Microsoft產品特有的非標準功能。您需要鏈接到Microsoft庫(這可能會也可能不會),或者(更好地)完全避免使用這些函數,而是使用標準的C語言。
    3. 截斷的重定位。這可能意味着你的程序太大或者你使用了不合適的編譯標誌或內聯程序集。谷歌「重新定位被截斷爲適合:R_X86_64_32」和/或發佈有關這個特定問題的另一個問題以及您的完整源代碼和構建命令。