如何修复“对于架构x86_64clang未找到ld:符号:错误:链接器命令失败,退出代码1(使用-v查看调用)”?

时间:2019-08-28 12:14:21

标签: cmake

我是C ++和XML的新手,我正在使用cmake来编译一些GEANT4代码。在“ make”命令之后,链接CXX可执行文件似乎存在问题

我正在Mac OSX10.14.6,geant4 10.5, C / CXX编译器标识为AppleClang 10.0.1.10010046

这是链接XML部分的代码。

XMLConfiguration* Cfg = new XMLConfiguration("mammact");
Cfg->readFile("mammact.xml");

当我从main.cc,include和src中删除与代码相关的所有XML部分时,我可以运行它。但是当我包含XML部分时,会出现以下错误;

[100%] Linking CXX executable mammactcone

Undefined symbols for architecture x86_64:
"xercesc_3_2::XMLPlatformUtils::Initialize(char const*, char const*, xercesc_3_2::PanicHandler*, xercesc_3_2::MemoryManager*)", referenced from:

XMLConfiguration::XMLConfiguration(char const*) in XMLConfiguration.cc.o
.
.
.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

由于我是编程的新手,所以我在编码时正在学习东西,因此,我恳请您提供比对编程人员更加清楚的解决方案/建议:)

这是我的CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.12)

project(SimulationMAMA)
find_package(MPI REQUIRED)

#-------------------------------------------------------------------------
# Find Geant4 package, activating all available UI and Vis drivers by default
# You can set WITH_GEANT4_UIVIS to OFF via the command line or ccmake/cmake-gui
# to build a batch mode only executable
#
option(WITH_GEANT4_UIVIS "Build example with Geant4 UI and Vis drivers" ON)
if(WITH_GEANT4_UIVIS)
  find_package(Geant4 REQUIRED ui_all vis_all)
else()
  find_package(Geant4 REQUIRED)
endif()

find_package(G4mpi REQUIRED)

#-------------------------------------------------------------------------
# Setup Geant4 include directories and compile definitions
# Setup include directory for this project
#
include(${Geant4_USE_FILE})
include_directories(${PROJECT_SOURCE_DIR}/include)


#-------------------------------------------------------------------------
# Locate sources and headers for this project
# NB: headers are included so they will show up in IDEs
#
file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc)
file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hh)


include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include
                              ${Geant4_INCLUDE_DIR}
                              ${G4mpi_INCLUDE_DIR}
                              ${Xerces_INCLUDE_DIR})

#-------------------------------------------------------------------------
# Add the executable, and link it to the Geant4 libraries
#
add_executable(mammactcone mammactcone.cc ${sources} ${headers})
target_link_libraries(mammactcone ${Geant4_LIBRARIES})


#-------------------------------------------------------------------------
# Copy scripts to the build directory of XRFCT.
#
set(MY_SCRIPTS
    mammact.xml init_vis.mac vis.mac run1.mac
  )

foreach(_script ${MY_SCRIPTS})
  configure_file(
    ${PROJECT_SOURCE_DIR}/${_script}
    ${PROJECT_BINARY_DIR}/${_script}
    COPYONLY
    )
endforeach()

#set(CMAKE_INCLUDE_CURRENT_DIR ON)
#set(CMAKE_AUTOMOC ON)

#find_package(Qt5Core)

#add_executable(${PROJECT_NAME} "mammactcone.cc")

#target_link_libraries(${PROJECT_NAME} Qt5::Core)

#-------------------------------------------------------------------------
# For internal Geant4 use - but has no effect if you build this
# example standalone
#
#add_custom_target(mammactcone DEPENDS mammactcone)
#-------------------------------------------------------------------------
# Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX

install(TARGETS mammactcone DESTINATION bin)

1 个答案:

答案 0 :(得分:0)

正确链接Xerces库后,该问题似乎已解决。

target_link_libraries(mammactcone ${Geant4_LIBRARIES} ${MPI_LIBRARIES} ${XercesC_LIBRARIES})