1. 程式人生 > >C語言常見編譯錯誤與執行錯誤

C語言常見編譯錯誤與執行錯誤

hello: line 1: syntax error: unexpected word (expecting “)”)

編寫fasync_jni應用程式放在Tiny210開發板上跑會出現如下錯誤:
這裡寫圖片描述

然後編寫一個最簡單的hello world程式放在Tiny210開發板上跑也會出現類似這樣的錯誤:hello: line 1: syntax error: unexpected word (expecting “)”)

解決辦法:加上-static選項,arm-linux-gcc hello.c –static –o hello
貌似將庫檔案編譯到應用程式裡面之後就能執行。
另外放在哪個目錄去執行也比較重要,最好放在根目錄去執行。

/udisk # ./uevents /system/bin/sh: ./uevents: not found

問題解法同上,編譯的時候加上–static

error: unknown type name ‘uint32_t’

如果在自己的標頭檔案中有用到uint32_t,要在這些標頭檔案中包含stdint.h

cannot open shared object file: No such file or directory

具體錯誤如下:
./rts5401_ft2: error while loading shared libraries: librtcr.so.1: cannot open shared object file: No such file or directory
也就是執行缺少動態連結庫,在網上查了主要有3種方法:
1、用ln的方法將需要的so檔案連結到/usr/lib或者/lib這兩個預設的目錄下邊
ln -s /where/you/install/lib/*.so /usr/lib
sudo ldconfig
2、修改LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/where/you/install/lib:$LD_LIBRARY_PATH
sudo ldconfig
3、修改/etc/ld.so.conf
vim /etc/ld.so.conf
add [where you install lib]
sudo ldconfig

我採用第3種方法
在/etc/ld.so.conf.d目錄下新增檔案librtcr.conf,檔案librtcr.conf檔案中記錄librtcr連結庫檔案的路徑,新增完了之後使用sudo ldconfig來重新將庫檔案的路徑加到系統路徑下面。

make: * No rule to make target ` ‘, needed by xxx. Stop

基本上都是屬於找不到所依賴的檔案所導致的,所以應該去檢測確保所依賴的檔案是否真實存在。
很可能,很常見的一個現象就是,此處的,誤寫了多餘的空格,導致被視為依賴檔案,導致找不到,導致報此錯誤。
解決辦法就很簡單,去掉多餘的空格即可。

field has incomplete type

linux下編譯C++程式碼報錯,報錯資訊”field has incomplete type”。這種問題一般都是在標頭檔案對類或者結構體進行了前向宣告,後面使用了該類定義了物件,導致編譯報錯。
原因在於前向宣告類或者結構體,此時編譯器還不知道定義,無法知道類內部成員,所以無法構造例項物件,因此前向宣告的類或者結構體只能用來定義指標或者引用

function declaration isn’t a prototype

參考文章:function declaration isn’t a prototype
In C int foo() and int foo(void) are different functions. int foo() accepts an arbitrary number of arguments, while int foo(void) accepts 0 arguments. In C++ they mean the same thing. I suggest that you use void consistently when you mean no arguments.