无法编译C代码:错误:在'int'之前预期'=',',',';','asm'或'__attribute__'

时间:2017-01-06 05:19:33

标签: c gcc

我在编写内核时使用James M tutorials。我使用交叉编译器在macOS 10.12上使用GCC 6.2.0和Binutils为elf-i386 arch编写代码。

除了 main.c之外,所有内容都会编译,但是失败并出现此错误:

  

错误:预期'=',',',';','asm'或'__attribute__'之前   'INT'即可。

但是,该文件与教程中的完全相同。任何人都可以帮我找出原因吗?

/*
Sierra Kernel
kernel.c -- Main kernel file
Copyright (C) 2017  Jacobo Soffer <sofferjacob@gmail.com>

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

4 个答案:

答案 0 :(得分:3)

可能是一个迟到的答案,但通常错误指向int之前包含的文件中的某些内容,在您的情况下是os.h,尝试发现是否有任何遗漏{{1}在此文件或其包含的任何文件中。

答案 1 :(得分:2)

int main(struct multiboot, *mboot_ptr)

有一个额外的“,”似乎

int main(struct multiboot *mboot_ptr)

答案 2 :(得分:0)

如果您尝试使用c89 C方言进行编译,则会遇到该问题。试试c99 CFLAGS + = - std = c99

答案 3 :(得分:0)

对于我来说,此错误是由于宏定义不正确而导致名称与第一个括号之间有空格的原因:

       #define DEFINE_EQUAL_NUM (type) \
        maccro_body...

应该是

#define DEFINE_EQUAL_NUM(type) \
            maccro_body...

希望这个答案对某人有帮助,我在一个复杂的基于maccro的模块中花费了很多时间,当我看到那仅仅是:(