Calling C file in GO

when i run my code i am getting this error how to solve it.

add.c:3:1: warning: return type defaults to 'int' [-Wimplicit-int]

add.h file

#ifndef _GREETER_H
#define _GREETER_H

int greet(const char *name, int year, char *out);


add.c file

#include "add.h"
#include <stdio.h>

int greet(const char *name, int year, char *out) {
    int n;
    n = sprintf(out, "Greetings, %s from %d! We come in peace :)", name, year);

    return n;

when i compile(gcc -c add.c) it i get the above error.

How to solve it and what is that error.

Thanks in Advance

Hi. The error code is a warning that the function main() has no return type defined and defaults to int which isn’t really good. Better to be explicit about the return types. However the function isn’t at line 3 in the add.c listing you present here so either something wierd is happening or you don’t list the same version as the one you tried to compile.

I pasted the same code here. If i run some other code also it gives same error.

No, Object file is not getting created

I tried a sample code it was not calling c func at all.

package main

// #include <stdio.h>
// void sum(){
//  printf("hello world");
// }
import "C"

import "fmt"
func main() {
fmt.Println("this is before")
fmt.Println("this is after")

When i run the above code the output was:
go run hello.go
this is before
this is after

how to get an working gnu c/c++ toolchain

When i restarted the system it was working fine.Thanks

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.