gpt4 book ai didi

c++ - log4cpp 给出 `unresolved external` 错误

转载 作者:太空宇宙 更新时间:2023-11-04 12:28:26 25 4
gpt4 key购买 nike

我正在努力使库工作并在 Borland Codegear 2007 上运行最新版本的 log4cpp 提供的测试,其中包含一个 Bpr 项目用于 Borland C++ Builder 5,这意味着能够构建和运行不同的测试。问题是我试图用2007版本打开这个项目,它必须进行项目转换。我遇到了奇怪的“ Unresolved external ”错误。然后我尝试自己构建项目而不进行任何转换,但陷入了同样的困境。

我正在尝试运行以下测试:

#include <stdio.h>
#include "log4cpp/Portability.hh"
#ifdef LOG4CPP_HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <iostream>
#include "log4cpp/Category.hh"
#include "log4cpp/Appender.hh"
#include "log4cpp/FileAppender.hh"
#include "log4cpp/OstreamAppender.hh"
#ifdef LOG4CPP_HAVE_SYSLOG
#include "log4cpp/SyslogAppender.hh"
#endif
#include "log4cpp/Layout.hh"
#include "log4cpp/BasicLayout.hh"
#include "log4cpp/Priority.hh"
#include "log4cpp/NDC.hh"

int main(int argc, char** argv) {
log4cpp::Appender* appender;
#ifdef LOG4CPP_HAVE_SYSLOG
log4cpp::SyslogAppender* syslogAppender;

syslogAppender = new log4cpp::SyslogAppender("syslog", "log4cpp");
#else
log4cpp::Appender* syslogAppender;

syslogAppender = new log4cpp::OstreamAppender("syslogdummy", &std::cout);
#endif

if (argc < 2) {
appender = new log4cpp::OstreamAppender("default", &std::cout);
} else {
appender = new log4cpp::FileAppender("default", argv[1]);
}

syslogAppender->setLayout(new log4cpp::BasicLayout());
appender->setLayout(new log4cpp::BasicLayout());

log4cpp::Category& root = log4cpp::Category::getRoot();
root.addAppender(syslogAppender);
root.setPriority(log4cpp::Priority::ERROR);

log4cpp::Category& sub1 = log4cpp::Category::getInstance(std::string("sub1"));
sub1.addAppender(appender);

log4cpp::Category& sub2 = log4cpp::Category::getInstance(std::string("sub1.sub2"));

log4cpp::NDC::push(std::string("ndc1"));

std::cout << " root prio = " << root.getPriority() << std::endl;
std::cout << " sub1 prio = " << sub1.getPriority() << std::endl;
std::cout << " sub2 prio = " << sub2.getPriority() << std::endl;

root.error("root error");
root.warn("root warn");
sub1.error("sub1 error");
sub1.warn("sub1 warn");
sub2.error("sub2 error");
sub2.warn("sub2 warn");

sub1.setPriority(log4cpp::Priority::INFO);
std::cout << " root prio = " << root.getPriority() << std::endl;
std::cout << " sub1 prio = " << sub1.getPriority() << std::endl;
std::cout << " sub2 prio = " << sub2.getPriority() << std::endl;

std::cout << "priority info" << std::endl;
root.error("root error");
root.warn("root warn");
sub1.error("sub1 error");
sub1.warn("sub1 warn");
sub2.error("sub2 error");
sub2.warn("sub2 warn");

sub2.warnStream() << "streamed warn";

sub2 << log4cpp::Priority::WARN << "warn2" << " warn3"
<< log4cpp::eol << " warn4";

{
for(int i = 0; i < 10000; i++) {
char ndc2[20];
sprintf(ndc2, "i=%d", i);
log4cpp::NDC::push(ndc2);
sub1.info("%s%d", "i = ", i);
if ((i % 10) == 0) {
sub1.log(log4cpp::Priority::NOTICE, "reopen log");
if (log4cpp::Appender::reopenAll()) {
sub1.info("log reopened");
} else {
sub1.warn("could not reopen log");
}
}
#ifndef WIN32
sleep(1);
#endif
log4cpp::NDC::pop();
}
}

return 0;
}

错误都是关于“ Unresolved external ”,例如:

[ILINK32 Error] Error: Unresolved external 'log4cpp::Category::warn(const char *, ...)' referenced from C:\DOCUMENTS AND SETTINGS\MLERMA\MIS DOCUMENTOS\RAD STUDIO\PROJECTS\DEBUG\TESTMAIN.OBJ

每次调用 log4cpp 函数时,我都会遇到这种错误,所有调用都指向 TESTMAIN.OBJ 。

对此有什么想法吗?有没有人在 Borland 上使用过 log4cpp?

最佳答案

您是否在 log4cpp 库 (.LIB) 中进行链接?我不熟悉 BCB5 或 Codegear,但请检查项目设置中的链接库并确保包含 log4cpp 库。

如果是,那么您可能对编译器查找库的位置有疑问。通常 IDE 会有一个项目级别或全局设置,说明编译器将在何处查找 .lib 文件。检查该设置并确保其中一个目录包含您的 log4cpp .lib 文件。

迈克

关于c++ - log4cpp 给出 `unresolved external` 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/686300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com