linux下運行strlwr函數出錯:ld returned 1 exit status,strlwrreturned

來源:互聯網
上載者:User

linux下運行strlwr函數出錯:ld returned 1 exit status,strlwrreturned

運行strlwr函數時報錯,來源程式如下:

#include<stdio.h>#include<string.h>void main(){ char s[10]={"CHINA"}; printf("%s\n",strlwr(s)); return 0;}
報錯內容如下:
eg6527a.c: In function ‘main’:
eg6527a.c:8:2: warning: ‘return’ with a value, in function returning void [enabled by default]  return 0;  ^In file included from eg6527a.c:3:0:eg6527a.c: At top level:/usr/include/strlwr.h:1:14: warning: ‘strlwr’ used but never defined [enabled by default] static char *strlwr(char *s);              ^/tmp/cc6LXD8t.o: In function `main':eg6527a.c:(.text+0x79): undefined reference to `strlwr'collect2: error: ld returned 1 exit status
尋找一下原因,原來是相容性問題strlwr、strupr函數不是標準的C函數庫,只能在VC中使用,

linux gcc 下需要自己定義這些函數。

具體做法如下:

自己寫一個strlwr.h標頭檔,內容如下:

char *strlwr(char *s){ char *str; str = s; while(*str != '\0') {  if(*str >= 'A' && *str <= 'Z') {     *str += 'a'-'A'; } str++; } return s; }
將其儲存在/usr/include目錄下

再修改源檔案為:

#include<stdio.h>#include<string.h>#include<strlwr.h>void main(){ char s[10]={"CHINA"}; printf("%s\n",strlwr(s)); return 0;}


此時再次運行程式 gcc -o 6527a 6527a.c

產生可執行檔6527a

運行該檔案     ./6527a

結果為:china  

將字串“CHINA”轉換為:"china"




利用arm-linux-gcc編譯時間出現collect2: ld returned 1 exit status 錯誤:具體步驟如下:

沒找到連結庫啊。
你不會是抄教程的東西只抄了一半吧?

那個 libmylib.so 你弄好了沒?
 
C++出現錯誤 ld returned 1 exit status

沒有執行許可權

ld是dev c++裡面的一個程式(估計是連接器),這句意思是ld執行返回狀態1.至於為什麼光靠你給出的資訊是看不出來的
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.