我从github克隆了poco库,并执行了仓库中存在的文件build_cmake.sh。在执行[[build_cmake.sh文件的过程中没有任何问题。它在/ usr / local / include目录中创建了许多头文件。
#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程序的详细步骤。
包括