类成员函数找不到undefined reference to
定义了一个类,有一个函数时返回一个vector。
------
StaAgent.h
------
using Ssid_t = struct {
std::string ssid;
};
class StaAgent {
public:
vector<Ssid_t> scanSsid();
...
}
在StaAgent.cpp里定义了此函数的实现
------
StaAgent.cpp
------
vector<Ssid_t> StaAgent::scanSsid()
{
...
}
在另一个文件里调用这个
#include "StaAgent.h"
...
void StaDialog::cn_scanSsidBt_clicked()
{
auto _sa = new StaAgent();
auto ssids = _sa->scanSsid();
...
}
链接的时候显示undefined reference to StaAgent::scanSsid()
g++ -Wl,-O1 -Wl,-rpath,/opt/Qt5.1.0/5.1.0/gcc_64 -Wl,-rpath,/opt/Qt5.1.0/5.1.0/gcc_64/lib -o StaTest main.o StaAgent.o StaDialog.o moc_StaDialog.o -L/opt/Qt5.1.0//5.1.0/gcc_64/lib -lQt5Gui -lQt5Widgets -lQt5Core -lGL -lpthread
StaDialog.o: In function `StaDialog::cn_scanSsidBt_clicked()':
StaDialog.cpp:(.text+0x1d2): undefined reference to `StaAgent::scanSsid()'
collect2: error: ld returned 1 exit status
----------------------------------
首先,链接文件里能找到StaAgent.o
然后使用nm -C StaAgent.o
在输出里,找不到StaAgent::scanSsid()这个符号。
------
StaAgent.h
------
using Ssid_t = struct {
std::string ssid;
};
class StaAgent {
public:
vector<Ssid_t> scanSsid();
...
}
在StaAgent.cpp里定义了此函数的实现
------
StaAgent.cpp
------
vector<Ssid_t> StaAgent::scanSsid()
{
...
}
在另一个文件里调用这个
#include "StaAgent.h"
...
void StaDialog::cn_scanSsidBt_clicked()
{
auto _sa = new StaAgent();
auto ssids = _sa->scanSsid();
...
}
链接的时候显示undefined reference to StaAgent::scanSsid()
g++ -Wl,-O1 -Wl,-rpath,/opt/Qt5.1.0/5.1.0/gcc_64 -Wl,-rpath,/opt/Qt5.1.0/5.1.0/gcc_64/lib -o StaTest main.o StaAgent.o StaDialog.o moc_StaDialog.o -L/opt/Qt5.1.0//5.1.0/gcc_64/lib -lQt5Gui -lQt5Widgets -lQt5Core -lGL -lpthread
StaDialog.o: In function `StaDialog::cn_scanSsidBt_clicked()':
StaDialog.cpp:(.text+0x1d2): undefined reference to `StaAgent::scanSsid()'
collect2: error: ld returned 1 exit status
----------------------------------
首先,链接文件里能找到StaAgent.o
然后使用nm -C StaAgent.o
在输出里,找不到StaAgent::scanSsid()这个符号。
...全文
相关推荐
c++出错提示英汉对照表
**Undefined reference to 'xxx'** - 对'xxx'的未定义引用:链接时找不到符号。确保所有使用的库和符号都被正确链接。70.
undefined reference to 'pthread_create'的解决方法
当出现“undefined reference to 'pthread_create'”错误时,意味着在编译链接阶段,编译器没有找到这个函数的实现。
undefined reference to `SetPduPowerConsumptionCnt'错误的解决方法
在编程过程中,我们时常会遇到“undefined reference to”这样的链接错误,这通常意味着在编译期间,链接器找不到代码中引用的某个函数或变量的定义。
undefined reference to ‘pthread_create’的解决方法
在GUN/Linux编程过程中,遇到"undefined reference to 'pthread_create'和'pthread_join'"这类错误,通常是由于编译过程中没有正确链接到pthr
undefined reference to `SetPduPowerConsumptionCnt’错误的解决方法
在编程过程中,遇到“undefined reference to `SetPduPowerConsumptionCnt’”这样的错误,通常意味着链接阶段找不到该函数的定义。


