-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
cmd/cgo: link failure when referencing standard COM GUID (non-function external symbol in a DLL) #9916
Comments
The same/a similar thing happens if the reference to package main
import "fmt"
// #cgo LDFLAGS: -luuid
// extern void *getIUnknown(void);
import "C"
func main() {
fmt.Printf("IID_IUnknown is at %p", C.getIUnknown())
} #define CINTERFACE
#include <windows.h>
void *getIUnknown(void)
{
return (void *) (&IID_IUnknown);
}
|
You need to set INITGUID before include. package main
import "fmt"
// #define INITGUID
// #include <objidl.h>
// #cgo LDFLAGS: -luuid
import "C"
func main() {
fmt.Printf("IID_IUnknown is at %p", &C.IID_IUnknown)
} Btw, If you want to call COM/OLE from go, see also https://github.com/mattn/go-ole |
Well that fixed the build; thanks. What exactly does I don't need to use COM from Go; I wrote a new Table control for package ui and its accessibility code uses COM (as that's how accessibility is exposed on Windows) but that's all on the C side. |
Wait, so is this really the only scenario in which the above error will happen? |
@andlabs when you use gcc, you have to play by its rules. If you have a problem will reopen this issue. Alex |
IID_IUnknown is imported from dll. So it shouldn't be specified as cgo_import_static. |
Anyone, could you please re-open this? |
Sorry, I updated CL. |
@alexbrainman I'm sorry, could you explain what you mean? @mattn ah, thanks for the clarification :) |
@andlabs gcc is not part of Go. gcc is another big world. If you want to go there, you need to understand how it works. I don't know how it works. Your original issue was about IID_IUnknown structure. You don't really need to use gcc to access IID_IUnknown. |
I know that; I don't know how my question was about gcc, as this happens with cgo and it clearly happens at the 8l step, not at gcc... |
I think #4069 should fix also fix this. Please try again after that issue
is closed.
(Should be soon, as I just need to address one last comment in the CL
series.)
|
I'm not sure, but if you didn't fix link phase for external library to use |
package main
/*
#include <stdio.h>
#include <objbase.h>
#cgo LDFLAGS: -luuid
int ccc = 3;
*/
import "C"
import "log"
import "os"
func test9916(t *log.Logger) {
v := C.IID_IUnknown
log.Println(v)
if v.Data1 != 0 {
t.Fatalf("Data1 %v", v)
}
if v.Data2 != 0 {
t.Fatalf("Data2 %v", v)
}
if v.Data3 != 0 {
t.Fatalf("Data3 %v", v)
}
if v.Data4[0] != 192 {
t.Fatalf("Data4[0] %v", v)
}
if v.Data4[7] != 70 {
t.Fatalf("Data4[7] %v", v)
}
println(C.ccc)
}
func main() {
test9916(log.New(os.Stdout, "", 0))
}
See https://go-review.googlesource.com/#/c/5253/3/src/cmd/go/build.go On windows, |
#4069 has been fixed on tip, please retry this.
|
Thanks for confirmation! |
IID_IUnknown
is a GUID that COM uses to refer to theIUnknown
interface (IUnknown
is to COM asinterface{}
is to Go). These GUIDs are defined in uuid.dll, a system DLL that you link against programs that want to use COM. This confuses Go's linker:I'm not sure if this specifically happens for these UUIDs or for any symbol in a DLL (or other shared object) hat isn't a function.
The text was updated successfully, but these errors were encountered: