我正在使用 XCode 6 在 Mac OS X 上用 C 语言编写一个库。该库基本上是一个由X-Plane加载的插件,并通过 Web 套接字服务器提供数据。
反过来,该库使用libwebsockets库,该库是我使用开发人员存储库文档中的指南编译的,此处。简而言之,我检查了 libwebsockets 存储库,创建了一个构建目录并运行
cmake ..
make
我的插件 100% 工作,X-Plane 加载它没有任何抱怨......当优化开启时!
当我在 XCode 中禁用对我的库的优化时,将其禁用为None [-O0]时,废话击中了风扇,并且当调用 libwebsockets 函数libwebsocket_create_context()时,库崩溃了。
关闭优化时如何引入错误/崩溃?通常不是相反,打开优化可能会出错吗?
这是围绕故障点的库代码的摘录:
PLUGIN_API int XPluginStart(char *outName, char *outSig, char *outDesc) {
strcpy(outName, "XP Web Socket");
strcpy(outSig, "sparkbuzz.plugins.xpwebsocket");
strcpy(outDesc, "Web socket plugin for streaming data to the browser.");
struct lws_context_creation_info info;
info.port = port;
info.iface = NULL;
info.protocols = protocols;
info.extensions = libwebsocket_get_internal_extensions();
info.ssl_cert_filepath = NULL;
info.ssl_private_key_filepath = NULL;
info.gid = -1;
info.uid = -1;
info.options = opts;
context = libwebsocket_create_context(&info); // FAILS HERE WITH EXC_BAD_ACCESS
if (context == NULL) {
// libwebsockets initialization has failed!
return -1;
}
// Find XPlane datarefs
gIAS = XPLMFindDataRef("sim/cockpit2/gauges/indicators/airspeed_kts_pilot");
// Register flight loop callback
XPLMRegisterFlightLoopCallback(MyFlightLoopCallback, 1.0, NULL);
return 1;
}