dongliao6491
2019-06-17 14:52
浏览 172
已采纳

警告:未使用的变量“ _cgo_a”

What is the '_cgo_a' variable?

I'm trying to link a c++ static lib.

greeter.cpp

#include "greeter.h"
#include <iostream>

void
greet()
{
    std::cout << "Greetings
";
}

greeter.h

#ifndef GREETER_H_
#define GREETER_H_

#ifdef __cplusplus
extern "C" {
#endif

void
greet();

#ifdef __cplusplus
}
#endif

#endif

I compiled the above into a static library like so:

$ g++ -c greeter.cpp
$ ar vfx greeter.o -o libgreeter.a

and here's my main.go

package main

// #cgo CFLAGS: -g -Wall
// #cgo LDFLAGS: -L. -lgreeter
// #include "greeter.h"
import "C"

func main() {
    C.greet()
}

Then when I do go build that's what I get:

# error
cgo-gcc-prolog: In function ‘_cgo_261f55e693f4_Cfunc_greet’:
cgo-gcc-prolog:46:49: warning: unused variable ‘_cgo_a’ [-Wunused-variable]

My go version: go version go1.12.5 linux/amd64

EDIT: If I remove the -Wall from the CFLAGS it compiles fine. Still what is the _cgo_a variable and why is it give me an error?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dtbonklcs575884485 2019-06-17 21:15
    已采纳

    Do not use -Wall in cgo CFLAGS. This is a general issue in Go. Read more in the github thread: https://github.com/golang/go/issues/6883#issuecomment-383800123

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题