netbeans log4cxx未定义对`log4cxx::Logger::getLogger(char const*)'的引用

ylamdve6  于 6个月前  发布在  其他
关注(0)|答案(1)|浏览(66)

我有两个,据我所知,在Ubuntu Netbeans下相同的cpp项目。

  1. LoggerTestProject
  2. Cpp应用程序2
    在这两个文件的主文件中,我集成了以下代码:
The result of compiling the first Project is:
#include "log4cxx/logger.h"
#include "log4cxx/basicconfigurator.h"
#include "log4cxx/propertyconfigurator.h"

#include "ratio.h" //only in LoggerTestProject

#include <cstdlib>

#define LOGCONF "./cfg/log4cxx.properties"

using namespace log4cxx;
using namespace log4cxx::helpers;

//extern LoggerPtr logger; //ahaha! AOP should be useful here
LoggerPtr logger(Logger::getLogger("LoggerTestProject"));

//using namespace std;

/*
 * 
 */
int main(int argc, char** argv)
{
    int inVar1 = 0;
LOG4CXX_INFO(logger, "Begin of LoggerTestProject");

字符串
编译第一个导致成功:

cd '/home/uwez/NetBeansProjects/LoggerTestProject'
/usr/bin/make -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/home/uwez/NetBeansProjects/LoggerTestProject'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/loggertestproject
make[2]: Entering directory '/home/uwez/NetBeansProjects/LoggerTestProject'
mkdir -p build/Debug/GNU-Linux/_ext/9bc1829f
rm -f "build/Debug/GNU-Linux/_ext/9bc1829f/ratio.o.d"
g++ -fpermissive   -c -g -I/usr/include/log4cxx -MMD -MP -MF "build/Debug/GNU-Linux/_ext/9bc1829f/ratio.o.d" -o build/Debug/GNU-Linux/_ext/9bc1829f/ratio.o /home/uwez/NetBeansProjects/LoggerTestProject/ratio.cpp
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/main.o.d"
g++ -fpermissive   -c -g -I/usr/include/log4cxx -MMD -MP -MF "build/Debug/GNU-Linux/main.o.d" -o build/Debug/GNU-Linux/main.o main.cpp
mkdir -p dist/Debug/GNU-Linux
g++ -fpermissive    -o dist/Debug/GNU-Linux/loggertestproject build/Debug/GNU-Linux/_ext/9bc1829f/ratio.o build/Debug/GNU-Linux/main.o -llog4cxx
make[2]: Leaving directory '/home/uwez/NetBeansProjects/LoggerTestProject'
make[1]: Leaving directory '/home/uwez/NetBeansProjects/LoggerTestProject'


whereelse编译第二个失败:

cd '/home/uwez/NetBeansProjects/CppApplication_2'
/usr/bin/make -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/home/uwez/NetBeansProjects/CppApplication_2'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/cppapplication_2
make[2]: Entering directory '/home/uwez/NetBeansProjects/CppApplication_2'
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/main.o.d"
g++    -c -g -MMD -MP -MF "build/Debug/GNU-Linux/main.o.d" -o build/Debug/GNU-Linux/main.o main.cpp
mkdir -p dist/Debug/GNU-Linux
g++     -o dist/Debug/GNU-Linux/cppapplication_2 build/Debug/GNU-Linux/main.o 
build/Debug/GNU-Linux/main.o: In function `__static_initialization_and_destruction_0(int, int)':
/home/uwez/NetBeansProjects/CppApplication_2/main.cpp:38: undefined reference to `log4cxx::Logger::getLogger(char const*)'
build/Debug/GNU-Linux/main.o: In function `log4cxx::helpers::ObjectPtrT<log4cxx::Logger>::~ObjectPtrT()':
/usr/include/log4cxx/helpers/objectptr.h:102: undefined reference to `log4cxx::helpers::ObjectPtrBase::~ObjectPtrBase()'
build/Debug/GNU-Linux/main.o:(.data.rel.ro._ZTIN7log4cxx7helpers10ObjectPtrTINS_6LoggerEEE[_ZTIN7log4cxx7helpers10ObjectPtrTINS_6LoggerEEE]+0x10): undefined reference to `typeinfo for log4cxx::helpers::ObjectPtrBase'
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:62: recipe for target 'dist/Debug/GNU-Linux/cppapplication_2' failed
make[2]: *** [dist/Debug/GNU-Linux/cppapplication_2] Error 1
make[2]: Leaving directory '/home/uwez/NetBeansProjects/CppApplication_2'
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/home/uwez/NetBeansProjects/CppApplication_2'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2


有没有人知道它可能是什么?/cfg -文件夹,其中包含log4cxx.properties文件在第二个项目中不存在,所以我手动复制它。但它没有帮助。

0ve6wy6x

0ve6wy6x1#

问题出在第二个项目中使用的Makefile。我猜它没有提到Log 4cxx(例如,没有-Llog 4cxx)。log4cxx.properties在你运行程序时使用,它在你构建程序时没有使用。

相关问题