1

编辑:我找到了插件库未定义的原因:它根本无法编译。也就是说,我仍然很难找到根本原因。

CMakeError.log 输出以下内容:

    Determining if the pthread_create exist failed with the following output:
Change Dir: /home/gamemaid/wow/dev/TrinityCore/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTryCompileExec4168097918/fast"
/usr/bin/make -f CMakeFiles/cmTryCompileExec4168097918.dir/build.make CMakeFiles/cmTryCompileExec4168097918.dir/build
make[1]: Entering directory '/home/gamemaid/wow/dev/TrinityCore/build/CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /home/gamemaid/wow/dev/TrinityCore/build/CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object CMakeFiles/cmTryCompileExec4168097918.dir/CheckSymbolExists.c.o
/usr/bin/cc   -std=gnu99 -W -Wall -Wextra -Winit-self -Winvalid-pch -Wfatal-errors    -o CMakeFiles/cmTryCompileExec4168097918.dir/CheckSymbolExists.c.o   -c /home/gamemaid/wow/dev/TrinityCore/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c
Linking C executable cmTryCompileExec4168097918
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTryCompileExec4168097918.dir/link.txt --verbose=1
/usr/bin/cc   -std=gnu99 -W -Wall -Wextra -Winit-self -Winvalid-pch -Wfatal-errors     CMakeFiles/cmTryCompileExec4168097918.dir/CheckSymbolExists.c.o  -o cmTryCompileExec4168097918 -rdynamic 

CMakeFiles/cmTryCompileExec4168097918.dir/CheckSymbolExists.c.o: In function `main':
CheckSymbolExists.c:(.text+0x16): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTryCompileExec4168097918.dir/build.make:88: recipe for target 'cmTryCompileExec4168097918' failed
make[1]: *** [cmTryCompileExec4168097918] Error 1
make[1]: Leaving directory '/home/gamemaid/wow/dev/TrinityCore/build/CMakeFiles/CMakeTmp'
Makefile:118: recipe for target 'cmTryCompileExec4168097918/fast' failed
make: *** [cmTryCompileExec4168097918/fast] Error 2

File /home/gamemaid/wow/dev/TrinityCore/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */
#include <pthread.h>

int main(int argc, char** argv)
{
  (void)argv;
#ifndef pthread_create
  return ((int*)(&pthread_create))[argc];
#else
  (void)argc;
  return 0;
#endif
}

Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /home/gamemaid/wow/dev/TrinityCore/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTryCompileExec1876865723/fast"
/usr/bin/make -f CMakeFiles/cmTryCompileExec1876865723.dir/build.make CMakeFiles/cmTryCompileExec1876865723.dir/build
make[1]: Entering directory '/home/gamemaid/wow/dev/TrinityCore/build/CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /home/gamemaid/wow/dev/TrinityCore/build/CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object CMakeFiles/cmTryCompileExec1876865723.dir/CheckFunctionExists.c.o
/usr/bin/cc   -std=gnu99 -W -Wall -Wextra -Winit-self -Winvalid-pch -Wfatal-errors -DCHECK_FUNCTION_EXISTS=pthread_create   -o CMakeFiles/cmTryCompileExec1876865723.dir/CheckFunctionExists.c.o   -c /usr/share/cmake-3.0/Modules/CheckFunctionExists.c
Linking C executable cmTryCompileExec1876865723
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTryCompileExec1876865723.dir/link.txt --verbose=1
/usr/bin/cc   -std=gnu99 -W -Wall -Wextra -Winit-self -Winvalid-pch -Wfatal-errors -DCHECK_FUNCTION_EXISTS=pthread_create    CMakeFiles/cmTryCompileExec1876865723.dir/CheckFunctionExists.c.o  -o cmTryCompileExec1876865723 -rdynamic -lpthreads 
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
CMakeFiles/cmTryCompileExec1876865723.dir/build.make:88: recipe for target 'cmTryCompileExec1876865723' failed

此行以下的所有内容都留作积压,不再是问题的一部分。

几天来,我一直在研究这个 CMake 代码,但无济于事。出于某种原因,当我调用它时

if (USE_COREPCH) add_cxx_pch(plugins ${plugins_STAT_PCH_HDR} ${plugins_STAT_PCH_SRC}) endif()

变量“plugins”未定义,该方法失败。我似乎无法理解为什么会这样,因为我用 add_library 方法清楚地定义了它。

    CollectSourceFiles(
  ${CMAKE_CURRENT_SOURCE_DIR}
  PRIVATE_SOURCES
  # Exclude
  ${CMAKE_CURRENT_SOURCE_DIR}/pch)


if (USE_COREPCH)
  set(plugins_STAT_PCH_HDR pch/pch.h)
  set(plugins_STAT_PCH_SRC pch/pch.cpp)
endif ()

GroupSources(${CMAKE_CURRENT_SOURCE_DIR})

add_library(plugins STATIC
  ${plugins_STAT_PCH_SRC}
  ${PRIVATE_SOURCES}
)

CollectIncludeDirectories(
  ${CMAKE_CURRENT_SOURCE_DIR}
  PUBLIC_INCLUDES
  # Exclude
  ${CMAKE_CURRENT_SOURCE_DIR}/pch)

target_include_directories(plugins
  PUBLIC
    ${PUBLIC_INCLUDES}
  PRIVATE
    ${CMAKE_CURRENT_BINARY_DIR})

add_dependencies(plugins revision_data.h)

if( WIN32 )
  if ( MSVC )
  add_custom_command(TARGET plugins
      POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/playerbot/aiplayerbot.conf.dist.in

${CMAKE_BINARY_DIR}/bin/$(ConfigurationName)/ ) add_custom_command(TARGET plugins POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/ahbot/ahbot.conf.dist.in ${CMAKE_BINARY_DIR}/bin/$(ConfigurationName )/ ) elseif ( MINGW )

   add_custom_command(TARGET plugins
      POST_BUILD
      COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}playerbot/aiplayerbot.conf.dist.in

${CMAKE_BINARY_DIR}/bin/ ) add_custom_command(TARGET plugins POST_BUILD COMMAND ${CMAKE_COMMAND} -E 复制 ${CMAKE_CURRENT_SOURCE_DIR}ahbot/ahbot.conf.dist.in ${CMAKE_BINARY_DIR}/bin/ ) endif() endif()

if( UNIX )
  install(TARGETS plugins DESTINATION bin)
  install(FILES playerbot/aiplayerbot.conf.dist.in DESTINATION ${CONF_DIR})
  install(FILES ahbot/ahbot.conf.dist.in DESTINATION ${CONF_DIR})
elseif( WIN32 )
  install(TARGETS plugins DESTINATION "${CMAKE_INSTALL_PREFIX}")
  install(FILES playerbot/aiplayerbot.conf.dist.in DESTINATION "${CMAKE_INSTALL_PREFIX}")
  install(FILES ahbot/ahbot.conf.dist.in DESTINATION "${CMAKE_INSTALL_PREFIX}")
endif()


# DEBUG CODE
if (DEFINED plugins)
MESSAGE("PLUGINS IS DEFINED")
endif()
MESSAGE(${plugins_STAT_PCH_SRC})
MESSAGE(${CMAKE_CURRENT_SOURCE_DIR})
MESSAGE(${PRIVATE_SOURCES})
# DEBUG

if (USE_COREPCH)
  add_cxx_pch(plugins ${plugins_STAT_PCH_HDR} ${plugins_STAT_PCH_SRC})
endif()

编辑:我已经确认在 add_library(plugins [..]) 调用 plugins 之后立即仍未定义。这真的很奇怪,我不知道该怎么办。

4

0 回答 0