我正在尝试在C ++的debian系统上使用Wireless Tools for Linux。
make
进行了编译,并用make install
进行了安装当我尝试编译我的代码时:
#include <iwlib.h>
#include <string>
void connect(const char* ssid, const char* pw, const char* interface) {
wireless_scan_head head;
wireless_scan* result;
iwrange range;
int sock;
// Open kernel socket:
sock = iw_sockets_open();
// Get scan metadata:
if (iw_get_range_info(sock, interface, &range)) {
// log_error(LOGGER_PREFIX + "Failed to get range info!");
exit(1);
}
// Scan:
if (iw_scan(sock, const_cast<char*>(interface), range.we_version_compiled, &head) < 0) {
// log_error(LOGGER_PREFIX + "Failed to perform iw_scan!");
exit(2);
}
// Print results:
result = head.result;
printf("SSIDS:\n");
while (NULL != result) {
printf("%s\n", result->b.essid);
result = result->next;
}
}
使用g++
会导致:
undefined reference to 'iw_scan'
collect2: error: ld returned 1 exit status
我无法用以下问题的答案解决问题:What is an undefined reference/unresolved external symbol error and how do I fix it?