Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use cgo error #2915

Open
Topthinking opened this issue Oct 22, 2021 · 2 comments
Open

use cgo error #2915

Topthinking opened this issue Oct 22, 2021 · 2 comments

Comments

@Topthinking
Copy link

Topthinking commented Oct 22, 2021

Description

gin + cgo = error

How to reproduce

package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

/*
int Add(int a, int b){
	return a + b;
}
 */
import "C"

func main()  {
	R := gin.Default()

	R.GET("/", func(context *gin.Context) {
		fmt.Println(C.Add(1,2))
		context.String(http.StatusOK,"hello world")
	})

	R.Run(":8080")
}

Expectations

Actual result

image

Environment

  • go version: go1.17.2 darwin/amd64
  • gin version (or commit ref):
  • operating system:
@Topthinking
Copy link
Author

Topthinking commented Oct 22, 2021

Use native http module is normal

package main

import (
	"fmt"
	"net/http"
)

/*
int Add(int a, int b){
	return a + b;
}
 */
import "C"

func main()  {
	http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
		fmt.Println(C.Add(1,2),request.RequestURI)
		writer.Write([]byte("hello world"))
	})

	http.ListenAndServe(":8080",nil)
}

@Crushla
Copy link

Crushla commented Nov 8, 2021

I have no this mistake here
选区_006

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants