【发布时间】:2020-05-24 20:00:36
【问题描述】:
我从 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 程序的详细步骤。
【问题讨论】:
-
如何设置包含路径和库路径?你在哪里设置库?我使用 Conan 和 CMake for Poco。它让您的生活更轻松。
-
你能告诉我怎么做吗?我是 C++ 库的新手,我不太了解
-
你用
-lgcc.gnu.org/onlinedocs/gcc-10.1.0/gcc/…列出库你必须找出你需要的库。正如我所说,使用柯南要容易得多。
标签: c++ linux installation poco poco-libraries