Python Raspberry Pi CEC代码的SWIG产生未定义的符号错误
我想在Python和Raspberry Pi的CEC代码之间创建一个接口(例如,)。我已经创建了一个小的C++文件来开始这个接口 mycec.cpp:Python Raspberry Pi CEC代码的SWIG产生未定义的符号错误,python,c++,linux,raspberry-pi,swig,Python,C++,Linux,Raspberry Pi,Swig,我想在Python和Raspberry Pi的CEC代码之间创建一个接口(例如,)。我已经创建了一个小的C++文件来开始这个接口 mycec.cpp: #include <cstdio> #include <interface/vmcs_host/vc_cecservice.h> #include <interface/vchiq_arm/vchiq_if.h> int openClose() { VCHI_INSTANCE_T vchiq_insta
#include <cstdio>
#include <interface/vmcs_host/vc_cecservice.h>
#include <interface/vchiq_arm/vchiq_if.h>
int openClose() {
VCHI_INSTANCE_T vchiq_instance;
int res = vchi_initialise(&vchiq_instance);
if (res != VCHIQ_SUCCESS) {
printf("failed to open vchiq instance\n");
return -1;
}
if (vchi_connect(NULL, 0, vchiq_instance) != 0) {
printf( "VCHI connection failed\n" );
return -1;
}
VCHI_CONNECTION_T *vchi_connection;
vc_vchi_cec_init(vchiq_instance, &vchi_connection, 1);
vc_vchi_cec_stop();
return 0;
}
我在Raspberry Pi上运行以下bash脚本来编译代码
build.sh:
#!/bin/bash
swig -python mycec.i
g++ -c -fpic -L=/opt/vc/lib \
-I=/usr/include/python2.7 \
-I=/opt/vc/include/interface/vcos/pthreads -I=/opt/vc/include \
mycec.cpp mycec_wrap.c
g++ -shared -Wl,--no-as-needed -L=/opt/vc/lib \
-I=/usr/include/python2.7 \
-I=/opt/vc/include/interface/vcos/pthreads -I=/opt/vc/include \
-o _mycec.so mycec.o mycec_wrap.o \
-lbcm_host -lvcos -lvchiq_arm
然后我尝试在python中加载它:
>>> import _mycec
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: ./_mycec.so: undefined symbol: _Z16vc_vchi_cec_initP29opaque_vchi_instance_handle_tPP17vchi_connection_tj
谢谢。我的
#includes
周围缺少外部“C”
。这项工作:
#include <cstdio>
extern "C" {
#include <interface/vmcs_host/vc_cecservice.h>
#include <interface/vchiq_arm/vchiq_if.h>
}
// rest of program...
#包括
外部“C”{
#包括
#包括
}
//程序的其余部分。。。
$ grep vc_vchi_cec_init /opt/vc/lib/libbcm_host.so
Binary file /opt/vc/lib/libbcm_host.so matches.
#include <cstdio>
extern "C" {
#include <interface/vmcs_host/vc_cecservice.h>
#include <interface/vchiq_arm/vchiq_if.h>
}
// rest of program...