\u5927\u90e8\u5206\u4eba\u5b66\u4e60\u6216\u8005\u4f7f\u7528\u67d0\u6837\u4e1c\u897f\uff0c\u559c\u6b22\u5728\u76f4\u89c2\u4e0a\u770b\u5230\u52a8\u624b\u540e\u7684\u7ed3\u679c\uff0c\u624d\u4f1a\u6709\u7ee7\u7eed\u4e0b\u53bb\u7684\u5174\u8da3\u3002<\/h4> \n \u524d\u8a00\uff1a<\/h3> \n
Golang \u8c03\u7528 C\/C++<\/a> \u7684\u6559\u7a0b\u7f51\u4e0a\u5f88\u591a\uff0c\u5c31\u6211\u76ee\u524d\u6240\u770b\u5230\u7684\uff0c\u4e2a\u4eba\u89c1\u89e3\u5c31\u662f\u6bd4\u8f83\u4e71\uff0c\u5751\u4e5f\u5f88\u591a\u3002\u5e0c\u671b\u672c\u6587\u80fd\u5728\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\uff0c\u505a\u5230\u66f4\u901a\u4fd7\u660e\u4e86\u3002<\/p> \n \u7b2c\u4e09\u4e2a \u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u76f4\u63a5\u62f7\u8d1d\u8fd0\u884c\u5c31\u80fd\u8f93\u51fa\u7ed3\u679c\uff1a3<\/p> \n \u4f8b\u5982\uff1a \u628a\u52a8\u6001\u5e93\u653e\u5230\u4e00\u4e2a\u4f60\u559c\u6b22\u7684\u76ee\u5f55\uff0c\u4e5f\u53ef\u4ee5\u653e\u5230\u5f53\u524d\u9879\u76ee\u91cc\u9762\uff0c\u50cf\u4e0a\u9762\u5217\u51fa\u7684\u4f8b\u5b50\u4e00\u6837\u3002\u518d\u5f15\u7528<\/p> \n \u7b2c\u4e09\u79cd\u65b9\u5f0f\u4fbf\u662f\u5982\u6b64 \u6700\u540e\uff0c\u8865\u5145\u4e00\u4e0b\uff0c\u4e00\u822c\u9700\u8981 go \u8c03\u7528 c\/c++ \u7684\uff0c\u4e3b\u8981\u662f\u4f7f\u7528\u4e00\u4e9b\u8457\u540d\u7684\u5f00\u6e90\u5e93\uff0c\u4f8b\u5982 \u4e0b\u9762 golang<\/a> \u7b80\u79f0 go , \u4e00\u5982\u65e2\u5f80\uff0c\u5c11\u8bf4\u5e9f\u8bdd\uff0c\u6211\u4eec\u73b0\u5728\u5f00\u59cb\u3002<\/h4> \n
\n go \u8c03\u7528 c\/c++ \u51fd\u6570\u7684\u5b9e\u73b0\u65b9\u5f0f\u6709\uff1a<\/h2> \n
\n
\u5d4c\u5957<\/code>\u5728go\u6587\u4ef6\u4e2d\u4f7f\u7528\uff0c\u6700\u7b80\u5355\u76f4\u89c2\u7684<\/li> \n
\u52a8\u6001\u5e93 .so \u6216 dll<\/code> \u7684\u5f62\u5f0f\uff0c\u6700\u5b89\u5168\u4f46\u662f\u5f88\u4e0d\u723d\u4e5f\u6bd4\u8f83\u6162\u7684<\/li> \n
\u76f4\u63a5\u5f15\u7528 c\/c++ \u6587\u4ef6\u7684\u5f62\u5f0f<\/code> \u662f\u6211\u8981\u4ecb\u7ecd\u7684\u91cd\u70b9\u3002<\/strong><\/p> \n
\u9700\u8981\u7684\u73af\u5883\u652f\u6301<\/h2> \n
\n
cannot find -lmingwex<\/code><\/li> \n
1\uff0c\u76f4\u63a5\u5d4c\u5957\u5728go\u6587\u4ef6<\/h2> \n
package main\r\n\/* \/\/ C \u6807\u5fd7io\u5934\u6587\u4ef6\uff0c\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528\u91cc\u9762\u63d0\u4f9b\u7684\u51fd\u6570 #include <stdio.h> void pri(){ printf("hey"); } int add(int a,int b){ return a+b; } *\/ import "C" \/\/ \u5207\u52ff\u6362\u884c\u518d\u5199\u8fd9\u4e2a import "fmt" func main() { fmt.Println(C.add(2, 1)) }<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/pre> \n
\u7ed3\u8bba\uff1a<\/h4> \n
\n
\u6ce8\u91ca<\/code>\u91cc\u9762<\/li> \n
import "C"<\/code> \u8fd9\u53e5\u8bdd\u8981\u7d27\u968f\uff0c\u6ce8\u91ca\u540e\uff0c\u4e0d\u8981\u6362\u884c\uff0c\u5426\u5219\u62a5\u9519<\/li> \n
C.xxx()<\/code>\uff0c\u4f8b\u5982 C.add(2, 1)<\/li> \n <\/ul> \n
2\uff0c\u5bfc\u5165\u52a8\u6001\u5e93 .so \u6216 .dll \u7684\u5f62\u5f0f<\/h2> \n
\u5047\u8bbe\u9879\u76ee\u76ee\u5f55\u5982\u4e0b<\/h4> \n
|-project | |-lib | | |-libvideo.dll | | |-libvideo.so | |-include | | |-video.h | |-src | | |-main.go<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/pre> \n
\u5934\u6587\u4ef6 .h \u5982\u4e0b\u9762\u8fd9\u6837<\/h4> \n
\/\/video.h\r\n#ifndef VIDEO_H\r\n#define VIDEO_H\r\nvoid exeFFmpegCmd(char* cmd); \/\/ \u58f0\u660e #endif<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/pre> \n
\u6e90\u6587\u4ef6 .c \u5982\u4e0b\u9762\u8fd9\u6837<\/h4> \n
#include <stdio.h> #include "video.h" void exeFFmpegCmd(char* cmd){ \/\/ \u5b9e\u73b0 \/\/ .... printf("finish"); }<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/pre> \n
\u4f7f\u7528 gcc \u6216 g++ \u751f\u6210 .so\u5e93\uff0c\u6216 win \u4e0b\u751f\u6210 dll<\/h4> \n
gcc video.c -fPIC -shared -o libvideo.so<\/code><\/p> \n
\u6700\u540e main.go<\/h4> \n
package main\r\n\r\n\/* #cgo CFLAGS: -Iinclude #cgo LDFLAGS: -Llib -llibvideo #include "video.h" *\/ import "C" import "fmt" func main() { cmd := C.CString("ffmpeg -i .\/xxx\/*.png .\/xxx\/yyy.mp4") C.exeFFmpegCmd(&cmd) }<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/pre> \n
\u5148\u56de\u7b54\u4e3a\u4ec0\u4e48\u8bf4\u8fd9\u79cd\u662f\u6700\u5b89\u5168\u7684\u548c\u6700\u4e0d\u723d\u7684\uff1f\u539f\u56e0\u5982\u4e0b\uff1a<\/h4> \n
\n
\u7ed3\u8bba<\/h4> \n
\n
CFLAGS: -I\u8def\u5f84<\/code> \u8fd9\u53e5\u8bdd\u6307\u660e\u5934\u6587\u4ef6\u6240\u5728\u8def\u5f84\uff0c-Iinclude \u6307\u660e \u5f53\u524d\u9879\u76ee\u6839\u76ee\u5f55\u7684 include \u6587\u4ef6\u5939<\/li> \n
LDFLAGS: -L\u8def\u5f84 -l\u540d\u5b57<\/code> \u6307\u660e\u52a8\u6001\u5e93\u7684\u6240\u5728\u8def\u5f84\uff0c-Llib -llibvideo\uff0c\u6307\u660e\u5728 lib \u4e0b\u9762\u4ee5\u53ca\u5b83\u7684\u540d\u5b57 video<\/li> \n
\u627e\u4e0d\u5230\u5b9a\u4e49\u4e4b\u7c7b<\/code>\u7684\u9519\u8bef\u4fe1\u606f<\/li> \n <\/ul> \n
3\uff0c\u76f4\u63a5\u5f15\u7528 c\/c++ \u6587\u4ef6\u7684\u5f62\u5f0f
\uff08\u91cd\u70b9\uff09<\/code><\/h2> \n
\u5047\u8bbe\u9879\u76ee\u76ee\u5f55\u5982\u4e0b<\/h4> \n
|-util | |-util.h | |-util.c | |-util.go<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/pre> \n
util.h<\/h4> \n
int sum(int a,int b);<\/span><\/span><\/span><\/span><\/span><\/pre> \n
util.c<\/h4> \n
#include "util.h"\r\nint sum(int a,int b){ return (a+b); }<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/pre> \n
util.go<\/h4> \n
package util\r\n\r\n\/* #include "util.c" *\/ import "C" import "fmt" func GoSum(a,b int) int { s := C.sum(C.int(a),C.int(b)) fmt.Println(s) }<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/pre> \n
\u8fd9\u6837\u8c03\u7528 main.go<\/h4> \n
package main\r\n\r\nfunc main(){ util.GoSum(4,5) }<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/pre> \n
\u7b80\u6d01\u660e\u4e86<\/code>\u3002<\/p> \n
ffmpeg<\/code>\uff0c
opencv<\/code>\uff0c\u7b49\u8fd9\u4e9b\u6e90\u7801\u662f\u57fa\u4e8e c\/c++ \u8bed\u8a00\u7684\uff0c\u9664\u6b64\u4e4b\u5916\u8fd8\u6709\u4e00\u4e2a\u5f88\u91cd\u8981\u7684\u70b9\uff0c\u4fbf\u662f\u8fd0\u884c\u901f\u5ea6\uff01<\/p> \n
\u5b8c<\/h1> \n<\/div>","orderid":"0","title":"Golang \u8c03\u7528 C\/C++\uff0c\u4f8b\u5b50\u5f0f\u6559\u7a0b","smalltitle":"","mid":"0","fname":"GO","special_id":"0","bak_id":"0","info":"0","hits":"68","pages":"1","comments":"0","posttime":"2019-09-17 19:10:27","list":"1568718627","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"Golang<\/A> \u8c03\u7528<\/A> C\/C<\/A> \u4f8b\u5b50<\/A> \u6559\u7a0b<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"14.17.22.35","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"Golang \u8c03\u7528 C\/C++\uff0c\u4f8b\u5b50\u5f0f\u6559\u7a0b","lastview":"1711878016","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}