Jacobo Soffer
Jacobo Soffer

Reputation: 51

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

I'm using James M tutorials on 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.

Everything compiles except main.c, which fails with this error:

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

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 $0x3");  // Test interrupts
    asm volatile ("int $0x4");
}

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

Upvotes: 5

Views: 31239

Answers (4)

ninjaconcombre
ninjaconcombre

Reputation: 534

For, me, this error was due to a bad maccro definition with a space between the name and the first parenthesis:

       #define DEFINE_EQUAL_NUM (type) \
        maccro_body...

Should be

#define DEFINE_EQUAL_NUM(type) \
            maccro_body...

Hope this answer will help someone, I passed a lot of time in a complex maccro based module and was really sad when I saw it was just that :(

Upvotes: 0

Sujay goshal
Sujay goshal

Reputation: 11

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

Upvotes: 1

werber bang
werber bang

Reputation: 333

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.

Upvotes: 5

theCrow
theCrow

Reputation: 346

int main(struct multiboot, *mboot_ptr)

Has an extra "," it seems

try

int main(struct multiboot *mboot_ptr)

Upvotes: 2

Related Questions