skip to Main Content

I’ve got 2, according to me, identical cpp projects under Ubuntu Netbeans.

  1. LoggerTestProject
  2. CppApplication2

In the mainfiles of both I’ve integrated the following code:

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");

Compiling the first one leads to a success:

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'

wherelse compiling the second one to a failure:

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

Has anyone got an idea what it could be? The /cfg – folder, which contains the log4cxx.properties file was not present in the second project, so I copied it manually. But it didn’t help.

2

Answers


  1. Chosen as BEST ANSWER

    In netbeans 8.2 in the menue open File/project properties.

    click on C++ Compiler and add the path of the log4cxx library to the include Directories. In this case its /usr/include/log4cxx, but it wasn't actually necessary for building the project.

    For building the project it's absolutely necessary to go to linker/libraries and add log4cxx. In the browse window I had to open the folder /usr/lib32 and type log4cxx.so. This is the includefile that is needed to build the project.


  2. The problem is with the Makefile used in the second project. My guess is that it does not mention Log4cxx (e.g. does not have a -Llog4cxx).
    The log4cxx.properties is used when you run the program, it does not get used when you build the program.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search