Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xiabo0816 committed Jun 18, 2019
1 parent 71e3671 commit bedd838
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 0 deletions.
26 changes: 26 additions & 0 deletions win-c++g++-go/CWord.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <vector>

using namespace::std;

/////////////////////////////////////////
//CWord
/////////////////////////////////////////
class CWord
{
public:
int m_nID;
char* m_psWord;
public:
CWord();
~CWord();
};

CWord::CWord()
{
m_psWord = NULL;
m_nID = -1;
}

CWord::~CWord()
{
}
20 changes: 20 additions & 0 deletions win-c++g++-go/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 使用g++编译dll给go调用

```
Windows 10
go version go1.12 windows/amd64
g++ (tdm64-1) 5.1.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```

> mingw32-make.exe
> go build
7 changes: 7 additions & 0 deletions win-c++g++-go/cwrap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "cwrap.h"
#include "test.h"

void call() {
Test ctx;
ctx.call();
}
13 changes: 13 additions & 0 deletions win-c++g++-go/cwrap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef __CWRAP_H__
#define __CWRAP_H__

#ifdef __cplusplus
extern "C" {
#endif
void call();

#ifdef __cplusplus
}
#endif

#endif
12 changes: 12 additions & 0 deletions win-c++g++-go/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

/*
#cgo CFLAGS: -Icpp
#cgo LDFLAGS: -L. -lgotest
#include "cwrap.h"
*/
import "C"

func main() {
C.call()
}
5 changes: 5 additions & 0 deletions win-c++g++-go/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build:
rm -f test.o
gcc -c test.cpp -o test.o
gcc -shared -o libgotest.dll test.o
rm -f test.o
5 changes: 5 additions & 0 deletions win-c++g++-go/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "test.h"

void Test::call() {
printf("call from c++ language\n");
}
11 changes: 11 additions & 0 deletions win-c++g++-go/test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef __TEST_H__
#define __TEST_H__

#include <stdio.h>

class Test {
public:
void call();
};

#endif
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit bedd838

Please sign in to comment.