
我在 VirtualBox 中運行 kubuntu 9.10,我用 C 編寫了最簡單的“hello world”程序,程式碼編譯,我通過調試器運行它,它似乎運行良好。唯一的問題是沒有任何內容實際打印到控制台......有什麼想法嗎?
繼承人的程式碼:
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char **argv) {
printf("hello world");
return 0;
}
我使用以下方法編譯它:
gcc -c test.c -o test.o
gcc test.o -o test
我沒有收到任何錯誤訊息。
答案1
你的路徑之前有 /usr/bin 。
嘗試將其運行為 ./test
/usr/bin/test 只是退出,沒有輸出
答案2
gcc -o helloWorld test.c
當編譯沒有錯誤時
./helloWorld
你的程式應該運行並顯示hello world
那應該可以正常工作。
編輯
儘管這“有效”,但真正的答案是使用 ./ 運行當前目錄中的可執行檔。在其他地方它會運行 /usr/bin/test。所有功勞都歸功於克雷格:)