How to import static lib with golang

Hey guys,
I created c++ static lib on window via Visual Code.
I built this lib and see it not have any error
But when import with golang on window with cgo, it got errror
I check and see all of them use 64 architect
Please help me import c++ static lib built by Visual Code with golang CGO

This is error receive

PS C:\Users\Administrator\Desktop\static_lib\window> go run .\main.go
# command-line-arguments
C:\Program Files\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\ADMINI~1\AppData\Local\Temp\2\go-link-1866661389\000001.o: in function `_cgo_4edeb0dd26e3_Cfunc_hello_world':
/tmp/go-build/main.cgo2.c:49: undefined reference to `__imp_hello_world'
collect2.exe: error: ld returned 1 exit status

This is my c++ code:

#ifndef PCH_H
#define PCH_H

#ifdef MY_WINDOW_EXPORTS
#define MY_API __declspec(dllexport)
#else
#define MY_API __declspec(dllimport)
#endif

// add headers that you want to pre-compile here
#include "framework.h"


#ifdef __cplusplus
extern "C" {
#endif
	// Your prototype or Definition 
	MY_API const char* hello_world();
#ifdef __cplusplus
}
#endif


#endif //PCH_H
// pch.cpp: source file corresponding to the pre-compiled header

#include "pch.h"

// When you are using pre-compiled headers, this source file is necessary for compilation to succeed.


const char* hello_world()
{
    const char *message = "hello world";
    return message;
}

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