我是C++和XML的新手,我正在使用cmake编译一些GEANT4代码。在命令"make“之后,链接CXX可执行文件似乎出现了问题
我在MacOSX10.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)发布于 2019-10-01 05:07:54
在正确链接Xerces库之后,这个问题似乎得到了解决。
target_link_libraries(mammactcone ${Geant4_LIBRARIES} ${MPI_LIBRARIES} ${XercesC_LIBRARIES})
https://stackoverflow.com/questions/57692191
复制相似问题