我从github克隆了poco库,并执行了repo中的文件build_cmake.sh。在执行build_cmake.sh file.It时没有出现任何问题,而是在/usr/local/file.It目录中创建了许多头文件。
#include "Poco/DateTime.h"
#include "Poco/Timespan.h"
#include<iostream>
using Poco::DateTime;
using Poco::Timespan;
using namespace std;
int main(int argc, char** argv)
{
// what is my age?
DateTime birthdate(1995, 02, 16, 2, 30); // 1973-09-12 02:30:00 //date of birth
//and time in following format YYYY, MM, DD, hh, mm, ss
DateTime now;
Timespan age = now - birthdate;
int days = age.days(); // in days
int hours = age.totalHours(); // in hours
int secs = age.totalSeconds(); // in seconds
cout << "iNDays: You are " << days << " days older." << endl;
cout << "iNHours: You are " << hours << " hours older. " << endl;
cout << "iNSeconds: You are " << secs << " seconds older" << endl;
return 0;
}现在,如果我使用
g++ filename.cpp我得到以下错误。
/usr/bin/ld: /tmp/cc187sFs.o: in function `main':
timeSpace.cpp:(.text+0x4c): undefined reference to `Poco::DateTime::DateTime(int, int, int, int, int, int, int, int)'
/usr/bin/ld: timeSpace.cpp:(.text+0x5c): undefined reference to `Poco::DateTime::DateTime()'
/usr/bin/ld: timeSpace.cpp:(.text+0x73): undefined reference to `Poco::DateTime::operator-(Poco::DateTime const&) const'
/usr/bin/ld: timeSpace.cpp:(.text+0x192): undefined reference to `Poco::DateTime::~DateTime()'
/usr/bin/ld: timeSpace.cpp:(.text+0x19e): undefined reference to `Poco::DateTime::~DateTime()'
/usr/bin/ld: timeSpace.cpp:(.text+0x1d1): undefined reference to `Poco::DateTime::~DateTime()'
/usr/bin/ld: timeSpace.cpp:(.text+0x1e2): undefined reference to `Poco::DateTime::~DateTime()'
/usr/bin/ld: /tmp/cc187sFs.o: in function `Poco::Timespan::days() const':
timeSpace.cpp:(.text._ZNK4Poco8Timespan4daysEv[_ZNK4Poco8Timespan4daysEv]+0x12): undefined reference to `Poco::Timespan::DAYS'
/usr/bin/ld: /tmp/cc187sFs.o: in function `Poco::Timespan::totalHours() const':
timeSpace.cpp:(.text._ZNK4Poco8Timespan10totalHoursEv[_ZNK4Poco8Timespan10totalHoursEv]+0x12): undefined reference to `Poco::Timespan::HOURS'
/usr/bin/ld: /tmp/cc187sFs.o: in function `Poco::Timespan::totalSeconds() const':
timeSpace.cpp:(.text._ZNK4Poco8Timespan12totalSecondsEv[_ZNK4Poco8Timespan12totalSecondsEv]+0x12): undefined reference to `Poco::Timespan::SECONDS'
collect2: error: ld returned 1 exit status谁能给出详细的步骤如何安装poco库和运行poco程序。
发布于 2020-06-11 00:22:49
由于您已经生成了POCO库,所以可以包括如下所示的标题:
#include <Poco/DateTime.h>您应该像这样链接所需的POCO库:
g++ filename.cpp -lPocoFoundation -lPocoUtilhttps://stackoverflow.com/questions/61991737
复制相似问题