Created
April 1, 2015 15:17
-
-
Save k-takata/8f9f71445ad608941aa1 to your computer and use it in GitHub Desktop.
Golang cgo test on Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <iostream> | |
#include <windows.h> | |
class Foo { | |
public: | |
Foo() { | |
OutputDebugStringA("Foo::Foo()\n"); | |
//std::cout << "Foo::Foo()\n"; | |
//std::printf("Foo::Foo()\n"); | |
} | |
void bar() { | |
OutputDebugStringA("bar()\n"); | |
//std::cout << "bar()\n"; | |
//std::printf("bar()\n"); | |
} | |
}; | |
Foo foo; | |
extern "C" void bar() | |
{ | |
foo.bar(); | |
} | |
#if 0 | |
int main() | |
{ | |
std::cout << "Hello from C++\n"; | |
bar(); | |
} | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
/* | |
#cgo LDFLAGS: -lkernel32 | |
void bar(); | |
*/ | |
import "C" | |
import "fmt" | |
func main() { | |
fmt.Println("Hello from Go") | |
C.bar() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Foo::Foo()
is not called on Windows/Go 1.4.2.Crashes when using
std::cout
instead ofOutputDebugStringA
.Link error occurs when using
std::printf
.