Qt c++中对库方法的未定义引用
Undefined reference to library method in Qt C++
我正在尝试在c++程序中使用C库。我想链接图书馆libcoap。我的程序是A。我已经在Qt中做了一个巨大的程序,所以它不能通过使用make而不是qmake来解决。
作为一个简单的例子,我编写了以下代码:connection.h:
#include <string>
#include "coap.h"
void sendData(std::string);
connection.cpp:
#include "connection.h"
#include "coap.h"
coap_uri_t uri;
void sendData(std::string ip){
coap_split_uri((unsigned char *)ip.c_str(), strlen(ip.c_str()), &uri );
}
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
尝试使用(in connection.h)
extern "C" {
#include "coap.h"
}
此外,在connection.h
和connection.cpp
中都包含coap.h
是多余的(如果在coap.h
中没有包含检查,则可执行文件的尺寸将无用地更大),因此将其从.cpp中删除。
相关文章:
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- 使用mysql c++连接器的未定义引用
- 对 Scalar ::Scalar() 的未定义引用
- 对复制 CTOR 和 CTOR 的未定义引用
- 对显式实例化的模板函数的未定义引用
- TensorRT (C++ API) 对"createNvOnnxParser_INTERNAL"的未定义引用
- 2个模板化类的非模板友元函数未定义引用错误
- 编译 libfluid 样本控制器时对"event_base_del_virtual"的未定义引用
- 获取对function_name的未定义引用
- 对 'std::thread::_M_start_thread CMake 的未定义引用进行基准测试
- 对结构方法的未定义引用
- 使用内联函数 c++ 的未定义引用
- 对 CMake 中'cudaRegisterLinkedBinary'链接错误的未定义引用?
- 对 DLOPEN 的未定义引用
- QT C++中对全局变量的未定义引用
- 快速数学导致对"__pow_finite"的未定义引用
- 对 boost::system::d etail::system_category_instance 的未定义引用,从
- OpenCV 3.4.3 中对 'cv::String::d eallocate()' 错误的未定义引用