使用 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 然后制作),没有 log4cpp

任何帮助将不胜感激

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

相关内容

  • 没有找到相关文章

最新更新