C语言 编译 C 代码时遇到问题:错误:在“int”之前应为“=”、“、”、“;”、“asm”或“__attribute__”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41499380/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 10:33:36  来源:igfitidea点击:

Trouble compiling C code: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'int'

cgcc

提问by Jacobo Soffer

I'm using James M tutorialson writing a kernel. I writing the code with a cross compiler for the elf-i386 arch on macOS 10.12 with GCC 6.2.0 and Binutils.

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

Everything compiles exceptmain.c, which fails with this error:

一切编译除外main.c,它失败,此错误:

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

错误:在 'int' 之前应为 '=', ',', ';', 'asm' 或 '__attribute__'

However, the file is exactly as it is in the tutorial. Can anyone help me figure out why?

但是,该文件与教程中的完全相同。谁能帮我弄清楚为什么?

/*
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 
int main(struct multiboot, *mboot_ptr)
x3"); // Test interrupts asm volatile ("int
int main(struct multiboot *mboot_ptr)
x4"); }

A public repo with all the kernel code is available at: https://gitlab.com/SierraKernel/Core/tree/master

包含所有内核代码的公共存储库位于:https: //gitlab.com/SierraKernel/Core/tree/master

回答by werber bang

May be it's a late answer , but generally the error is pointing to something not right in the file included just before int , in your case it's os.h,try to spot if there are any missing ;in this file or any file that it includes.

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

回答by Sebu Elias

##代码##

Has an extra "," it seems

似乎有一个额外的“,”

try

尝试

##代码##

回答by Sujay goshal

If you are trying to compile with c89 C dialect you will get that problem. try to c99 CFLAGS+ = -std=c99

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