2017-01-06 83 views
3

我在編寫內核時使用James M tutorials。我使用GCC 6.2.0和Binutils在MacOS 10.12上爲elf-i386 arch編寫了一個交叉編譯器的代碼。無法編譯C代碼:錯誤:在'int'之前預計'=',',';','asm'或'__attribute__'

一切編譯除了main.c,它失敗,此錯誤:

Error: expected '=', ',', ';', 'asm' or '__attribute__' before 'int'.

但是,該文件是完全一樣的教程。任何人都可以幫我弄清楚爲什麼?

/* 
Sierra Kernel 
kernel.c -- Main kernel file 
Copyright (C) 2017 Jacobo Soffer <[email protected]> 

This program is free software: you can redistribute it and/or modify 
it under the terms of the GNU General Public License as published by 
the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version. 

This program is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
GNU General Public License for more details. 

You should have received a copy of the GNU General Public License 
along with this program. If not, see <http://www.gnu.org/licenses/>. 
*/ 

#include <os.h> 

int main(struct multiboot *mboot_ptr) 
{ 
    kprint("Welcome to the Sierra Kernel! \n"); // Test VGA Driver 
    kprint(BUILD_FULL); // Print version information 
    asm volatile ("int $0x3"); // Test interrupts 
    asm volatile ("int $0x4"); 
} 

公共回購所有的內核代碼,請訪問:https://gitlab.com/SierraKernel/Core/tree/master

+2

看起來您有一個額外的逗號:'int main(struct multiboot * mboot_ptr)' –

+1

請注意,您需要仔細考慮高度不標準的'結構multiboot *'參數'main()'將來自於。您必須在嵌入式系統上工作,但是如果您正在編寫內核,那麼將會如何初始化並將該結構傳遞給內核? –

回答

2
int main(struct multiboot, *mboot_ptr) 

有一個額外的 「」 它似乎

嘗試

int main(struct multiboot *mboot_ptr) 
+1

我刪除了逗號,但在嘗試編譯時仍然出現相同的錯誤。感謝您的幫助 –

2

可能是它的一個遲到的答案,但通常這個錯誤指向int中包含的文件中的某些東西不正確,在y中我們的情況是os.h,請嘗試查看此文件或其中包含的任何文件中是否有任何缺失的;

0

如果您嘗試使用c89 C方言進行編譯,您將會遇到該問題。嘗試c99 CFLAGS + = -std = c99

+0

我的意思是嘗試使用c99方言。 –

+0

CFLAGS + = -std = c99 –

相關問題