使用cmake将log4cpp库链接到项目

时间:2012-05-14 09:37:42

标签: c++ cmake log4cpp

我正在尝试将log4cpp链接到我的项目。我使用CMake,我无法找到一种方法。

Log4cpp安装在projectfolder / log4cpp /上(包含bin / include / lib / ...)

我使用以下Findlog4cpp.cmake:

IF (LOG4CPP_FOUND)
    SET(LOG4CPP_FIND_QUIETLY TRUE)
ENDIF (LOG4CPP_FOUND)

FIND_PATH(LOG4CPP_INCLUDE_DIR log4cpp/FileAppender.hh
    "./log4cpp/include/"
)

FIND_LIBRARY(LOG4CPP_LIBRARIES
  NAMES liblog4cpp.so
  PATHS "./log4cpp/lib"
)

SET(LOG4CPP_FOUND 0)
IF(LOG4CPP_INCLUDE_DIR)
  IF(LOG4CPP_LIBRARIES)
    SET(LOG4CPP_FOUND 1 CACHE INTERNAL "log4cpp found")
    IF (NOT LOG4CPP_FIND_QUIETLY)
      MESSAGE(STATUS "Found Log4CPP")
    ENDIF (NOT LOG4CPP_FIND_QUIETLY)
  ENDIF(LOG4CPP_LIBRARIES)
ENDIF(LOG4CPP_INCLUDE_DIR)

MARK_AS_ADVANCED(
  LOG4CPP_INCLUDE_DIR
  LOG4CPP_LIBRARIES
) 

在我的CMakeLists.txt中我称之为:

...
FIND_PACKAGE(log4cpp REQUIRED)
INCLUDE_DIRECTORIES(${LOG4CPP_INCLUDE_DIR})
SET(LIBS ${LOG4CPP_LIBRARIES} ${LIBS})

MESSAGE("############################# ${LOG4CPP_LIBRARIES}")
MESSAGE("############################# ${LOG4CPP_INCLUDE_DIR}")
...

输出:

-- Found Log4CPP
############################# /SOMEPATH/projectfolder/log4cpp/lib/liblog4cpp.so
############################# /SOMEPATH/projectfolder/log4cpp/include
-- Configuring done
-- Generating done
-- Build files have been written to: /SOMEPATH/projectfolder/

然后当我运行make我有以下错误:

/SOMEPATH/projectfolder/common/Common.h:24:31: error: log4cpp/Category.hh: No such file or directory
/SOMEPATH/projectfolder/common/Common.h:25:35: error: log4cpp/FileAppender.hh: No such file or directory
/SOMEPATH/projectfolder/common/Common.h:26:34: error: log4cpp/BasicLayout.hh: No such file or directory

我只是在common.h中包含了标题(#include“log4cpp / xxx.hh”)

我添加了所有构建和编译工作正常(使用cmake然后make)没有log4cpp

非常感谢任何帮助

1 个答案:

答案 0 :(得分:2)

如果您要将公共目录添加为具有自己的CMakeLists.txt的子目录,则在调用INCLUDE_DIRECTORIES之前,如果希望传递已包含的目录,则需要调用ADD_SUBDIRECTORY