我想在我的C ++程序中使用libmpdclient-dev
。我在系统上安装了它。
在/usr/include/mpd
下,我找到了所有头文件。
我的测试程序如下:
#include<iostream>
#include<mpd/client.h>
using namespace std;
struct mpd_connection *conn;
int main() {
conn = mpd_connection_new("192.168.1.151", 6600, 0);
if(conn == NULL) {
cout << "Not connected \n";
}
else {
cout << "Connected \n";
}
return 0;
}
它可以正常编译:
g++ -g -Wfatal-errors -std=c++11 main.cpp -c -o main.o
但是,按以下方式运行链接器:
g++ -g -Wfatal-errors -std=c++11 main.o -o run
给出此错误:
main.o: In Function `main':
~/mpd/main.cpp:13: undefined reference to `mpd_connection_new'
collect2: error: ld returned 1 exit status
要成功链接,我需要添加或更改什么?