希望有人可以帮我解决我的构建问题我正在尝试使用此C++ Application Project Template创建一个新项目,但我无法正确构建,因为我遇到了log4cxx的问题。见下文
make[1]: Entering directory `/home/user/Downloads/cpp-project-template/build'
make[2]: Entering directory `/home/user/Downloads/cpp-project-template/build'
make[3]: Entering directory `/home/user/Downloads/cpp-project-template/build'
make[3]: Leaving directory `/home/user/Downloads/cpp-project-template/build'
make[3]: Entering directory `/home/user/Downloads/cpp-project-template/build'
Linking CXX executable ../../bin/projectname
CMakeFiles/projectname.dir/app.cpp.o: In function `App::App(int&, char**)':
app.cpp:(.text+0x32c): undefined reference to `log4cxx::Logger::getRootLogger()'
app.cpp:(.text+0x38c): undefined reference to `log4cxx::PatternLayout::PatternLayout(std::string const&)'
app.cpp:(.text+0x3b7): undefined reference to `log4cxx::ConsoleAppender::ConsoleAppender(log4cxx::helpers::ObjectPtrT<log4cxx::Layout> const&)'
app.cpp:(.text+0x6d2): undefined reference to `log4cxx::Logger::isFatalEnabled() const'
app.cpp:(.text+0x6e6): undefined reference to `log4cxx::helpers::MessageBuffer::MessageBuffer()'
app.cpp:(.text+0x701): undefined reference to `log4cxx::spi::LocationInfo::LocationInfo(char const*, char const*, int)'
app.cpp:(.text+0x712): undefined reference to `log4cxx::helpers::MessageBuffer::operator<<(char const*)'
app.cpp:(.text+0x743): undefined reference to `log4cxx::helpers::MessageBuffer::str(std::ostream&)'
app.cpp:(.text+0x755): undefined reference to `log4cxx::Level::getFatal()'
app.cpp:(.text+0x778): undefined reference to `log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT<log4cxx::Level> const&, std::string const&, log4cxx::spi::LocationInfo const&) const'
app.cpp:(.text+0x793): undefined reference to `log4cxx::helpers::MessageBuffer::~MessageBuffer()'
app.cpp:(.text+0x92f): undefined reference to `log4cxx::Logger::isFatalEnabled() const'
app.cpp:(.text+0x943): undefined reference to `log4cxx::helpers::MessageBuffer::MessageBuffer()'
app.cpp:(.text+0x95e): undefined reference to `log4cxx::spi::LocationInfo::LocationInfo(char const*, char const*, int)'
app.cpp:(.text+0x96f): undefined reference to `log4cxx::helpers::MessageBuffer::operator<<(char const*)'
app.cpp:(.text+0x9a0): undefined reference to `log4cxx::helpers::MessageBuffer::str(std::ostream&)'
app.cpp:(.text+0x9b2): undefined reference to `log4cxx::Level::getFatal()'
app.cpp:(.text+0x9d5): undefined reference to `log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT<log4cxx::Level> const&, std::string const&, log4cxx::spi::LocationInfo const&) const'
app.cpp:(.text+0x9f0): undefined reference to `log4cxx::helpers::MessageBuffer::~MessageBuffer()'
app.cpp:(.text+0xb54): undefined reference to `log4cxx::Logger::isFatalEnabled() const'
app.cpp:(.text+0xb68): undefined reference to `log4cxx::helpers::MessageBuffer::MessageBuffer()'
app.cpp:(.text+0xb83): undefined reference to `log4cxx::spi::LocationInfo::LocationInfo(char const*, char const*, int)'
app.cpp:(.text+0xb94): undefined reference to `log4cxx::helpers::MessageBuffer::operator<<(char const*)'
app.cpp:(.text+0xbc5): undefined reference to `log4cxx::helpers::MessageBuffer::str(std::ostream&)'
app.cpp:(.text+0xbd7): undefined reference to `log4cxx::Level::getFatal()'
app.cpp:(.text+0xbfa): undefined reference to `log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT<log4cxx::Level> const&, std::string const&, log4cxx::spi::LocationInfo const&) const'
app.cpp:(.text+0xc15): undefined reference to `log4cxx::helpers::MessageBuffer::~MessageBuffer()'
app.cpp:(.text+0xd15): undefined reference to `log4cxx::Logger::isFatalEnabled() const'
app.cpp:(.text+0xd29): undefined reference to `log4cxx::helpers::MessageBuffer::MessageBuffer()'
app.cpp:(.text+0xd44): undefined reference to `log4cxx::spi::LocationInfo::LocationInfo(char const*, char const*, int)'
app.cpp:(.text+0xd55): undefined reference to `log4cxx::helpers::MessageBuffer::operator<<(char const*)'
app.cpp:(.text+0xd86): undefined reference to `log4cxx::helpers::MessageBuffer::str(std::ostream&)'
app.cpp:(.text+0xd98): undefined reference to `log4cxx::Level::getFatal()'
app.cpp:(.text+0xdbb): undefined reference to `log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT<log4cxx::Level> const&, std::string const&, log4cxx::spi::LocationInfo const&) const'
app.cpp:(.text+0xdd6): undefined reference to `log4cxx::helpers::MessageBuffer::~MessageBuffer()'
app.cpp:(.text+0x1084): undefined reference to `log4cxx::Logger::isFatalEnabled() const'
app.cpp:(.text+0x1098): undefined reference to `log4cxx::helpers::MessageBuffer::MessageBuffer()'
app.cpp:(.text+0x10b3): undefined reference to `log4cxx::spi::LocationInfo::LocationInfo(char const*, char const*, int)'
app.cpp:(.text+0x10c4): undefined reference to `log4cxx::helpers::MessageBuffer::operator<<(char const*)'
app.cpp:(.text+0x10d6): undefined reference to `log4cxx::helpers::MessageBuffer::str(log4cxx::helpers::CharMessageBuffer&)'
app.cpp:(.text+0x10e8): undefined reference to `log4cxx::Level::getFatal()'
app.cpp:(.text+0x110b): undefined reference to `log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT<log4cxx::Level> const&, std::string const&, log4cxx::spi::LocationInfo const&) const'
app.cpp:(.text+0x1126): undefined reference to `log4cxx::helpers::MessageBuffer::~MessageBuffer()'
app.cpp:(.text+0x1155): undefined reference to `log4cxx::Logger::isWarnEnabled() const'
app.cpp:(.text+0x1169): undefined reference to `log4cxx::helpers::MessageBuffer::MessageBuffer()'
app.cpp:(.text+0x1184): undefined reference to `log4cxx::spi::LocationInfo::LocationInfo(char const*, char const*, int)'
app.cpp:(.text+0x1195): undefined reference to `log4cxx::helpers::MessageBuffer::operator<<(char const*)'
app.cpp:(.text+0x11c6): undefined reference to `log4cxx::helpers::MessageBuffer::str(std::ostream&)'
app.cpp:(.text+0x11d8): undefined reference to `log4cxx::Level::getWarn()'
app.cpp:(.text+0x11fb): undefined reference to `log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT<log4cxx::Level> const&, std::string const&, log4cxx::spi::LocationInfo const&) const'
app.cpp:(.text+0x1216): undefined reference to `log4cxx::helpers::MessageBuffer::~MessageBuffer()'
app.cpp:(.text+0x1298): undefined reference to `log4cxx::Logger::isFatalEnabled() const'
app.cpp:(.text+0x12ac): undefined reference to `log4cxx::helpers::MessageBuffer::MessageBuffer()'
app.cpp:(.text+0x12c7): undefined reference to `log4cxx::spi::LocationInfo::LocationInfo(char const*, char const*, int)'
app.cpp:(.text+0x12d8): undefined reference to `log4cxx::helpers::MessageBuffer::operator<<(char const*)'
app.cpp:(.text+0x12ea): undefined reference to `log4cxx::helpers::MessageBuffer::str(log4cxx::helpers::CharMessageBuffer&)'
app.cpp:(.text+0x12fc): undefined reference to `log4cxx::Level::getFatal()'
app.cpp:(.text+0x131f): undefined reference to `log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT<log4cxx::Level> const&, std::string const&, log4cxx::spi::LocationInfo const&) const'
app.cpp:(.text+0x133a): undefined reference to `log4cxx::helpers::MessageBuffer::~MessageBuffer()'
app.cpp:(.text+0x1369): undefined reference to `log4cxx::Logger::isWarnEnabled() const'
app.cpp:(.text+0x137d): undefined reference to `log4cxx::helpers::MessageBuffer::MessageBuffer()'
app.cpp:(.text+0x1398): undefined reference to `log4cxx::spi::LocationInfo::LocationInfo(char const*, char const*, int)'
app.cpp:(.text+0x13a9): undefined reference to `log4cxx::helpers::MessageBuffer::operator<<(char const*)'
app.cpp:(.text+0x13da): undefined reference to `log4cxx::helpers::MessageBuffer::str(std::ostream&)'
app.cpp:(.text+0x13e9): undefined reference to `log4cxx::Level::getWarn()'
app.cpp:(.text+0x1409): undefined reference to `log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT<log4cxx::Level> const&, std::string const&, log4cxx::spi::LocationInfo const&) const'
app.cpp:(.text+0x1421): undefined reference to `log4cxx::helpers::MessageBuffer::~MessageBuffer()'
app.cpp:(.text+0x1443): undefined reference to `log4cxx::Logger::isWarnEnabled() const'
app.cpp:(.text+0x1457): undefined reference to `log4cxx::helpers::MessageBuffer::MessageBuffer()'
app.cpp:(.text+0x1472): undefined reference to `log4cxx::spi::LocationInfo::LocationInfo(char const*, char const*, int)'
app.cpp:(.text+0x1483): undefined reference to `log4cxx::helpers::MessageBuffer::operator<<(char const*)'
app.cpp:(.text+0x14b4): undefined reference to `log4cxx::helpers::MessageBuffer::str(std::ostream&)'
app.cpp:(.text+0x14c3): undefined reference to `log4cxx::Level::getWarn()'
app.cpp:(.text+0x14e3): undefined reference to `log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT<log4cxx::Level> const&, std::string const&, log4cxx::spi::LocationInfo const&) const'
app.cpp:(.text+0x14fb): undefined reference to `log4cxx::helpers::MessageBuffer::~MessageBuffer()'
app.cpp:(.text+0x177e): undefined reference to `log4cxx::helpers::MessageBuffer::~MessageBuffer()'
app.cpp:(.text+0x1821): undefined reference to `log4cxx::helpers::MessageBuffer::~MessageBuffer()'
app.cpp:(.text+0x18b1): undefined reference to `log4cxx::helpers::MessageBuffer::~MessageBuffer()'
app.cpp:(.text+0x192a): undefined reference to `log4cxx::helpers::MessageBuffer::~MessageBuffer()'
CMakeFiles/projectname.dir/app.cpp.o:app.cpp:(.text+0x1a2c): more undefined references to `log4cxx::helpers::MessageBuffer::~MessageBuffer()' follow
CMakeFiles/projectname.dir/app.cpp.o: In function `App::setLogLevel(std::string const&, std::string const&)':
app.cpp:(.text+0x31d6): undefined reference to `log4cxx::Logger::getRootLogger()'
app.cpp:(.text+0x31f1): undefined reference to `log4cxx::Logger::getLogger(std::string const&)'
app.cpp:(.text+0x32c3): undefined reference to `log4cxx::Level::getAll()'
app.cpp:(.text+0x332a): undefined reference to `log4cxx::Level::getTrace()'
app.cpp:(.text+0x3391): undefined reference to `log4cxx::Level::getDebug()'
app.cpp:(.text+0x33f8): undefined reference to `log4cxx::Level::getInfo()'
app.cpp:(.text+0x345c): undefined reference to `log4cxx::Level::getWarn()'
app.cpp:(.text+0x34ba): undefined reference to `log4cxx::Level::getError()'
app.cpp:(.text+0x3518): undefined reference to `log4cxx::Level::getFatal()'
app.cpp:(.text+0x359e): undefined reference to `log4cxx::Level::getOff()'
app.cpp:(.text+0x35ce): undefined reference to `log4cxx::Logger::isFatalEnabled() const'
app.cpp:(.text+0x35e2): undefined reference to `log4cxx::helpers::MessageBuffer::MessageBuffer()'
app.cpp:(.text+0x35fd): undefined reference to `log4cxx::spi::LocationInfo::LocationInfo(char const*, char const*, int)'
app.cpp:(.text+0x360e): undefined reference to `log4cxx::helpers::MessageBuffer::operator<<(char const*)'
app.cpp:(.text+0x3620): undefined reference to `log4cxx::helpers::CharMessageBuffer::operator<<(std::string const&)'
app.cpp:(.text+0x362d): undefined reference to `log4cxx::helpers::CharMessageBuffer::operator<<(char const*)'
app.cpp:(.text+0x363f): undefined reference to `log4cxx::helpers::MessageBuffer::str(log4cxx::helpers::CharMessageBuffer&)'
app.cpp:(.text+0x364e): undefined reference to `log4cxx::Level::getFatal()'
app.cpp:(.text+0x366e): undefined reference to `log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT<log4cxx::Level> const&, std::string const&, log4cxx::spi::LocationInfo const&) const'
app.cpp:(.text+0x3686): undefined reference to `log4cxx::helpers::MessageBuffer::~MessageBuffer()'
app.cpp:(.text+0x3778): undefined reference to `log4cxx::helpers::MessageBuffer::~MessageBuffer()'
CMakeFiles/projectname.dir/app.cpp.o: In function `__static_initialization_and_destruction_0(int, int)':
app.cpp:(.text+0x38ec): undefined reference to `log4cxx::Logger::getLogger(char const*)'
CMakeFiles/projectname.dir/app.cpp.o: In function `log4cxx::helpers::ObjectPtrT<log4cxx::Level>::~ObjectPtrT()':
app.cpp:(.text._ZN7log4cxx7helpers10ObjectPtrTINS_5LevelEED2Ev[_ZN7log4cxx7helpers10ObjectPtrTINS_5LevelEED5Ev]+0x4c): undefined reference to `log4cxx::helpers::ObjectPtrBase::~ObjectPtrBase()'
app.cpp:(.text._ZN7log4cxx7helpers10ObjectPtrTINS_5LevelEED2Ev[_ZN7log4cxx7helpers10ObjectPtrTINS_5LevelEED5Ev]+0x75): undefined reference to `log4cxx::helpers::ObjectPtrBase::~ObjectPtrBase()'
CMakeFiles/projectname.dir/app.cpp.o: In function `log4cxx::helpers::ObjectPtrT<log4cxx::Layout>::~ObjectPtrT()':
app.cpp:(.text._ZN7log4cxx7helpers10ObjectPtrTINS_6LayoutEED2Ev[_ZN7log4cxx7helpers10ObjectPtrTINS_6LayoutEED5Ev]+0x4c): undefined reference to `log4cxx::helpers::ObjectPtrBase::~ObjectPtrBase()'
app.cpp:(.text._ZN7log4cxx7helpers10ObjectPtrTINS_6LayoutEED2Ev[_ZN7log4cxx7helpers10ObjectPtrTINS_6LayoutEED5Ev]+0x75): undefined reference to `log4cxx::helpers::ObjectPtrBase::~ObjectPtrBase()'
CMakeFiles/projectname.dir/app.cpp.o: In function `log4cxx::helpers::ObjectPtrT<log4cxx::Logger>::~ObjectPtrT()':
app.cpp:(.text._ZN7log4cxx7helpers10ObjectPtrTINS_6LoggerEED2Ev[_ZN7log4cxx7helpers10ObjectPtrTINS_6LoggerEED5Ev]+0x4c): undefined reference to `log4cxx::helpers::ObjectPtrBase::~ObjectPtrBase()'
CMakeFiles/projectname.dir/app.cpp.o:app.cpp:(.text._ZN7log4cxx7helpers10ObjectPtrTINS_6LoggerEED2Ev[_ZN7log4cxx7helpers10ObjectPtrTINS_6LoggerEED5Ev]+0x75): more undefined references to `log4cxx::helpers::ObjectPtrBase::~ObjectPtrBase()' follow
CMakeFiles/projectname.dir/app.cpp.o: In function `log4cxx::helpers::ObjectPtrT<log4cxx::Layout>::ObjectPtrT(log4cxx::Layout*)':
app.cpp:(.text._ZN7log4cxx7helpers10ObjectPtrTINS_6LayoutEEC2EPS2_[_ZN7log4cxx7helpers10ObjectPtrTINS_6LayoutEEC5EPS2_]+0x19): undefined reference to `log4cxx::helpers::ObjectPtrBase::ObjectPtrBase()'
app.cpp:(.text._ZN7log4cxx7helpers10ObjectPtrTINS_6LayoutEEC2EPS2_[_ZN7log4cxx7helpers10ObjectPtrTINS_6LayoutEEC5EPS2_]+0x6d): undefined reference to `log4cxx::helpers::ObjectPtrBase::~ObjectPtrBase()'
CMakeFiles/projectname.dir/app.cpp.o: In function `log4cxx::helpers::ObjectPtrT<log4cxx::Appender>::ObjectPtrT(log4cxx::Appender*)':
app.cpp:(.text._ZN7log4cxx7helpers10ObjectPtrTINS_8AppenderEEC2EPS2_[_ZN7log4cxx7helpers10ObjectPtrTINS_8AppenderEEC5EPS2_]+0x19): undefined reference to `log4cxx::helpers::ObjectPtrBase::ObjectPtrBase()'
app.cpp:(.text._ZN7log4cxx7helpers10ObjectPtrTINS_8AppenderEEC2EPS2_[_ZN7log4cxx7helpers10ObjectPtrTINS_8AppenderEEC5EPS2_]+0x97): undefined reference to `log4cxx::helpers::ObjectPtrBase::~ObjectPtrBase()'
CMakeFiles/projectname.dir/app.cpp.o: In function `log4cxx::helpers::ObjectPtrT<log4cxx::Appender>::~ObjectPtrT()':
app.cpp:(.text._ZN7log4cxx7helpers10ObjectPtrTINS_8AppenderEED2Ev[_ZN7log4cxx7helpers10ObjectPtrTINS_8AppenderEED5Ev]+0x76): undefined reference to `log4cxx::helpers::ObjectPtrBase::~ObjectPtrBase()'
app.cpp:(.text._ZN7log4cxx7helpers10ObjectPtrTINS_8AppenderEED2Ev[_ZN7log4cxx7helpers10ObjectPtrTINS_8AppenderEED5Ev]+0x9f): undefined reference to `log4cxx::helpers::ObjectPtrBase::~ObjectPtrBase()'
CMakeFiles/projectname.dir/app.cpp.o: In function `std::ostream& log4cxx::helpers::operator<< <QString>(log4cxx::helpers::CharMessageBuffer&, QString const&)':
app.cpp:(.text._ZN7log4cxx7helperslsI7QStringEERSoRNS0_17CharMessageBufferERKT_[_ZN7log4cxx7helperslsI7QStringEERSoRNS0_17CharMessageBufferERKT_]+0x18): undefined reference to `log4cxx::helpers::CharMessageBuffer::operator std::ostream&()'
CMakeFiles/projectname.dir/app.cpp.o:(.rodata._ZTIN7log4cxx7helpers10ObjectPtrTINS_8AppenderEEE[_ZTIN7log4cxx7helpers10ObjectPtrTINS_8AppenderEEE]+0x10): undefined reference to `typeinfo for log4cxx::helpers::ObjectPtrBase'
CMakeFiles/projectname.dir/app.cpp.o:(.rodata._ZTIN7log4cxx7helpers10ObjectPtrTINS_6LayoutEEE[_ZTIN7log4cxx7helpers10ObjectPtrTINS_6LayoutEEE]+0x10): undefined reference to `typeinfo for log4cxx::helpers::ObjectPtrBase'
CMakeFiles/projectname.dir/app.cpp.o:(.rodata._ZTIN7log4cxx7helpers10ObjectPtrTINS_6LoggerEEE[_ZTIN7log4cxx7helpers10ObjectPtrTINS_6LoggerEEE]+0x10): undefined reference to `typeinfo for log4cxx::helpers::ObjectPtrBase'
CMakeFiles/projectname.dir/app.cpp.o:(.rodata._ZTIN7log4cxx7helpers10ObjectPtrTINS_5LevelEEE[_ZTIN7log4cxx7helpers10ObjectPtrTINS_5LevelEEE]+0x10): undefined reference to `typeinfo for log4cxx::helpers::ObjectPtrBase'
collect2: error: ld returned 1 exit status
make[3]: *** [../bin/projectname-2.0] Error 1
make[3]: Leaving directory `/home/user/Downloads/cpp-project-template/build'
make[2]: *** [src/CMakeFiles/projectname.dir/all] Error 2
make[2]: Leaving directory `/home/user/Downloads/cpp-project-template/build'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/user/Downloads/cpp-project-template/build'
make: *** [all] Error 2
BUILD FAILED (exit value 2, total time: 339ms)
我已经单独测试了log4cxx,只是使用g ++编译一个例子并执行-llog4cxx标志。我不确定我是否需要为这个项目指定那个标志?我试过谷歌搜索错误,但让很多人问类似的问题,没有解决问题的答案。希望有人能够对此有所了解,我们将非常感激。
答案 0 :(得分:0)
在我看来,在这个项目中你还没有定义log4cxx includepath。 我猜你正在使用cmake来生成makefile,所以要添加log4cxx include路径在你的CMakeLists中尝试这个:
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/'navigate to log4cxx include path here')