Undefined reference to wpa_ctrl functions in my C++ OpenFrameworks project. Need help integrating this c library

独自空忆成欢 提交于 2019-12-11 13:30:40

问题


I'm working on a menu option to connect to wifi in my C++ application that is build using OpenFrameworks. I want to use the wpa_ctrl library but I can't get it to compile.

Code snippet:

NetworkWrapper.h:

#ifndef NETWORKWRAPPER_H_
#define NETWORKWRAPPER_H_

class NetworkWrapper {
public:
     NetworkWrapper():
private:
     struct wpa_ctrl* m_ctrl;
};
#endif

NetworkWrapper.cpp:

#include "NetworkWrapper.h"
extern "C" {
     #include "wpa_ctrl.h"
}

NetworkWrapper::NetworkWrapper() {
     m_ctrl = wpa_ctrl_open("wlan0");
}

Error:

***/NetworkWrapper.cpp:7: undefined reference to `wpa_ctrl_open'
collect2: error: ld returned 1 exit status

I've tried throwing around the include and using and not using extern "C" but it makes no difference seeing as wpa_ctrl.h is also enclosed in the extern "C" tag, albeit with #ifdef __cplusplus (which is defined, I double checked).

I'm pretty much out of ideas now. I should note that I tried enclosing wpa_ctrl.c in the extern "C" tags, which to my knowledge shouldn't compile(?). Which also gave the exact same result. This led me to manually compiling the wpa_ctrl library and copying to the obj directory but again: same result.

Thank you for taking the time to read my question, hope you can help!

* EDIT * As per request my linking options (I trimmed it down a bit):

g++ -o bin/application_debug obj/linux64/Debug/src/main.o [...] obj/linux64/Debug/src/libs/wpa_ctrl.o [...] obj/linux64/Debug/src/common/NetworkWrapper.o [...] -Wl,-rpath=./libs:./bin/libs -Wl,--as-needed -Wl,--gc-sections -Wl,-rpath=./libs -liw -L../../../libs/fmodex/lib/linux64/ -lfmodex -L ./bin/libs -lSDL -lSDL_mixer -lcurl ../../../libs/glfw/lib/linux64/libglfw3.a ../../../libs/kiss/lib/linux64/libkiss.a ../../../libs/rtAudio/lib/linux64/libRtAudio.a ../../../libs/tess2/lib/linux64/libtess2.a ../../../libs/poco/lib/linux64/libPocoNet.a ../../../libs/poco/lib/linux64/libPocoXML.a ../../../libs/poco/lib/linux64/libPocoUtil.a ../../../libs/poco/lib/linux64/libPocoFoundation.a ../../../libs/poco/lib/linux64/libPocoNetSSL.a ../../../libs/poco/lib/linux64/libPocoNet.a ../../../libs/poco/lib/linux64/libPocoCrypto.a ../../../libs/poco/lib/linux64/libPocoUtil.a ../../../libs/poco/lib/linux64/libPocoXML.a ../../../libs/poco/lib/linux64/libPocoFoundation.a -L/usr/lib64 -lz -lgstapp-0.10 -lgstvideo-0.10 -lgstbase-0.10 -lgstreamer-0.10 -lgmodule-2.0 -pthread -lgthread-2.0 -pthread -lxml2 -ludev -lsndfile -lopenal -lssl -lcrypto -lpulse-simple -lpulse -lasound -lGLEW -lGLU -lGL -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lfontconfig -lfreetype -lmpg123 -lglut -lX11 -lXrandr -lXxf86vm -lXi -lXcursor -ldl -lpthread -lfreeimage


回答1:


So I finally found what I was doing wrong. For future visitors:

I needed to add the following defines in my makefile:

-D CONFIG_CTRL_IFACE -D CONFIG_CTRL_IFACE_UNIX


来源:https://stackoverflow.com/questions/35366267/undefined-reference-to-wpa-ctrl-functions-in-my-c-openframeworks-project-need

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!