Qt C+中对库方法的未定义引用+; 我试图在C++程序中使用C库。 我想将libcoap.a库链接到我的程序。我已经在Qt中制作了一个巨大的程序,所以不能用make代替qmake来解决它
作为一个简单的示例,我编写了以下代码 连接.h:Qt C+中对库方法的未定义引用+; 我试图在C++程序中使用C库。 我想将libcoap.a库链接到我的程序。我已经在Qt中制作了一个巨大的程序,所以不能用make代替qmake来解决它,c++,c,qt,linker,C++,C,Qt,Linker,作为一个简单的示例,我编写了以下代码 连接.h: #include <string> #include "coap.h" void sendData(std::string); main.cpp: #include "connection.h" using namespace std; int main() { sendData("[aaaa::c30c:0:0:2]/sen/lt"); return 0; } coaptester.pro: TEMP
#include <string>
#include "coap.h"
void sendData(std::string);
main.cpp:
#include "connection.h"
using namespace std;
int main()
{
sendData("[aaaa::c30c:0:0:2]/sen/lt");
return 0;
}
coaptester.pro:
TEMPLATE = app
CONFIG += console
CONFIG -= qt
unix:!macx:!symbian: LIBS += -L$$PWD/../commTest/commTest/libcoap-4.0.1/ -lcoap
INCLUDEPATH += $$PWD/../commTest/commTest/libcoap-4.0.1
DEPENDPATH += $$PWD/../commTest/commTest/libcoap-4.0.1
unix:!macx:!symbian: PRE_TARGETDEPS += $$PWD/../commTest/commTest/libcoap-4.0.1/libcoap.a
SOURCES += main.cpp \
connection.cpp
HEADERS += \
connection.h
我总是会遇到同样的错误:
undefined reference to `coap_split_uri(unsigned char*, unsigned int, coap_uri_t*)'
collect2: ld returned 1 exit status
提前感谢。尝试使用(在connection.h中)
此外,在connection.h
和connection.cpp
中都包含coap.h
是多余的(如果在coap.h
中没有包含检查,则可执行文件的维度将毫无意义地增大),因此将其从.cpp中删除。在#include“coap.h”周围加上外部“C”怎么样?请参阅精彩的解释
undefined reference to `coap_split_uri(unsigned char*, unsigned int, coap_uri_t*)'
collect2: ld returned 1 exit status
extern "C" {
#include "coap.h"
}