编译时出现Cmake ld错误

时间:2014-09-18 11:49:47

标签: c++ reference cmake undefined exit

您好我正在尝试使用cmake编译程序。但是,当我运行make install时。它给出了这个错误。我从来没有和Cmake合作过,所以对我来说这是全新的。请帮助我。

libstructure.so: undefined reference to `AptamerTree::~AptamerTree()'
libparserfastq.so: undefined reference to `ParserMain::ProcessLaneInParallel(std::string, std::string, std::string, std::string, std::string, int)'
libstructure.so: undefined reference to `AptamerTree::GetRoot()'
libparserfastq.so: undefined reference to `ParserMain::ParserMain(Parameters*, std::vector<AptamerPool*, std::allocator<AptamerPool*> >*, _win_st*)'
libparserfastq.so: undefined reference to `ParserMain::StoreStatistics()'
libparserfastq.so: undefined reference to `ParserMain::IsGZipped(std::string)'
libparserfastq.so: undefined reference to `ParserMain::StoreConsensusSizes()'
libparserfastq.so: undefined reference to `ParserMain::ProcessLaneInParallel(std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string, std::string, int, int, int)'
libparserfastq.so: undefined reference to `ParserMain::~ParserMain()'
libstructure.so: undefined reference to `AptamerTree::AptamerTree()'
libstructure.so: undefined reference to `AptamerTree::InsertEdge(Node*, Node*)'
libparserfastq.so: undefined reference to `ParserMain::SetStatus(std::string, int, int)'
libparserfastq.so: undefined reference to `ParserMain::StoreQualities()'
libstructure.so: undefined reference to `AptamerTree::begin()'
libparserfastq.so: undefined reference to `ParserMain::StoreFrequencies()'
libparserfastq.so: undefined reference to `ParserMain::StoreRandomizedRegionSizes()'
libstructure.so: undefined reference to `AptamerTree::end()'
libstructure.so: undefined reference to `AptamerTree::CreateNode()'
libparserfastq.so: undefined reference to `ParserMain::LogStatistics()'
collect2: error: ld returned 1 exit status
make[2]: *** [src/htsaptamotiftest] Error 1
make[1]: *** [src/CMakeFiles/htsaptamotiftest.dir/all] Error 2
make: *** [all] Error 2

这是Cmakelist.txt

#this is just a basic CMakeLists.txt, for more information see the cmake manpage
MESSAGE("CONFIGURING HTSAptamotif")

# set variables required for build
get_filename_component(PROJECT_ROOT ${CMAKE_CURRENT_SOURCE_DIR} PATH)
SET(INSTALL_PATH ${CMAKE_INSTALL_PREFIX})
SET(EXTERNAL_INCLUDE_PATH ${INSTALL_PATH}/include/)
SET(EXTERNAL_LIB_PATH ${INSTALL_PATH}/lib/)


# use, i.e. don't skip the full RPATH for the build tree
SET(CMAKE_SKIP_BUILD_RPATH  FALSE)

# when building, don't use the install RPATH already
# (but later on when installing)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) 

SET(CMAKE_INSTALL_RPATH "${INSTALL_PATH}/lib")

# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)


# the RPATH to be used when installing, but only if it's not a system directory
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${INSTALL_PATH}/lib" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
   SET(CMAKE_INSTALL_RPATH "${INSTALL_PATH}/lib")
ENDIF("${isSystemDir}" STREQUAL "-1")


# we need openMP 
INCLUDE(FindOpenMP)
IF(OPENMP_FOUND)
    MESSAGE("  FOUND OPENMP")
    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
    SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
ENDIF()

#and ncurses
FIND_LIBRARY(NCURSRS_PANEL_LIBRARY NAMES panel DOC "The ncureses panel library")
INCLUDE(FindCurses)
IF(CURSES_FOUND)
    MESSAGE("  FOUND CURSES")
#   add panels to the library path
    SET(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${NCURSRS_PANEL_LIBRARY})
ENDIF()




#add definitions, compiler switches, etc.
#-g is with debugging info. disable this for production code
#-lprofiler uses google cpu profiler. disable for production
# debugging flags
ADD_DEFINITIONS(-Wall -lmysqlcppconn -std=gnu++0x -ltcmalloc -lncurses -lpanel -O2 -g -lprofiler )
# productions flags
# ADD_DEFINITIONS(-Wall -lmysqlcppconn -std=gnu++0x -ltcmalloc -lncurses -lpanel -O2)
#OLD  ADD_DEFINITIONS(-Wall -lncurses -lpanel -lmysqlcppconn -std=gnu++0x -O2 -g -ltcmalloc -lprofiler)
#ADD_DEFINITIONS(-Wno-sign-compare)

# define include and link directories
INCLUDE_DIRECTORIES(
    ${EXTERNAL_INCLUDE_PATH}
#   /usr/local/google-perftools/1.8.2/include
)

LINK_DIRECTORIES(
    ${EXTERNAL_LIB_PATH}
#   /usr/local/google-perftools/1.8.2/lib
)


#Define non-header libs here
MESSAGE("  Boost_LIBRARIES: ${Boost_LIBRARIES}") 
MESSAGE("  Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}") 

SET(MySQL_LIBRARIES 
    ${EXTERNAL_LIB_PATH}libmysqlcppconn.so
)
MESSAGE("  MySQL_LIBRARIES: ${MySQL_LIBRARIES}")

SET(ViennaRNA_LIBRARIES 
    ${EXTERNAL_LIB_PATH}libRNA.a
)
MESSAGE("  ViennaRNA_LIBRARIES: ${ViennaRNA_LIBRARIES}")

SET(GPTOOLS_LIBRARIES 
    ${EXTERNAL_LIB_PATH}libprofiler.so
    ${EXTERNAL_LIB_PATH}libtcmalloc.so
)
MESSAGE("  GooglePrefTools_LIBRARIES: ${GPTOOLS_LIBRARIES}")

MESSAGE("  Curses_LIBRARIES: ${CURSES_LIBRARIES}") 



#build the shared libraries
ADD_LIBRARY(htsaptamotif SHARED htsaptamotif.cpp)
ADD_LIBRARY(parameters SHARED parameters.cpp)
ADD_LIBRARY(aptamer SHARED aptamer.cpp)
ADD_LIBRARY(aptamertree SHARED aptamertree.cpp)
ADD_LIBRARY(databasesocket SHARED databasesocket.cpp)
ADD_LIBRARY(aptamerpool SHARED aptamerpool.cpp)
ADD_LIBRARY(structure SHARED structure.cpp)
ADD_LIBRARY(substructure SHARED substructure.cpp)
ADD_LIBRARY(substructureensemble SHARED substructureensemble.cpp)
# ADD_LIBRARY(aptagraph SHARED aptagraph.cpp) #templates
ADD_LIBRARY(numericalintegrator SHARED numericalintegrator.cpp)
# ADD_LIBRARY(mstprims SHARED mstprims.cpp) #templates
ADD_LIBRARY(aptamotif SHARED aptamotif.cpp)
ADD_LIBRARY(poolgenerator SHARED poolgenerator.cpp)
ADD_LIBRARY(lshcluster SHARED lshcluster.cpp)
ADD_LIBRARY(dnacompressor SHARED dnacompressor.cpp)
ADD_LIBRARY(aptamercluster SHARED aptamercluster.cpp)
ADD_LIBRARY(parsermain SHARED parsermain.cpp)
ADD_LIBRARY(parserfastq SHARED parserfastq.cpp)
ADD_LIBRARY(parserfasta SHARED parserfasta.cpp)
ADD_LIBRARY(parsertext SHARED parsertext.cpp)
#external alignment library
ADD_LIBRARY(nwaligner SHARED ssw.c)
ADD_LIBRARY(nwalignerwrapper SHARED ssw_cpp.cpp)

#for testing the shared library you probably need some test app too
ADD_EXECUTABLE(htsaptamotiftest htsaptamotiftest.cpp)

#need to link to some other libraries ? just add them here
TARGET_LINK_LIBRARIES(parameters ${Boost_LIBRARIES} ${GPTOOLS_LIBRARIES} ${CURSES_LIBRARIES})
TARGET_LINK_LIBRARIES(databasesocket ${MySQL_LIBRARIES})
TARGET_LINK_LIBRARIES(aptamer ${ViennaRNA_LIBRARIES})
TARGET_LINK_LIBRARIES(htsaptamotiftest htsaptamotif parameters databasesocket aptamerpool aptamer aptamertree aptamotif structure substructure substructureensemble numericalintegrator poolgenerator parsermain parserfastq parserfasta parsertext lshcluster dnacompressor aptamercluster nwaligner nwalignerwrapper ${GPTOOLS_LIBRARIES}  ${CURSES_LIBRARIES}) #aptagraph mstprims are templates


# compile the socket program for gui comunication
ADD_EXECUTABLE(guisocket guisocket.cpp)
TARGET_LINK_LIBRARIES(guisocket ${Boost_LIBRARIES} parameters)

#add and install target here
INSTALL(TARGETS htsaptamotiftest htsaptamotif parameters databasesocket aptamerpool aptamer aptamertree structure substructure substructureensemble numericalintegrator aptamotif poolgenerator parsermain parserfastq parsertext parserfasta lshcluster dnacompressor aptamercluster nwaligner nwalignerwrapper guisocket 
    RUNTIME DESTINATION ${INSTALL_PATH}/bin
    LIBRARY DESTINATION ${INSTALL_PATH}/lib
    ARCHIVE DESTINATION ${INSTALL_PATH}/lib
)

任何想法如何解决这个问题?

1 个答案:

答案 0 :(得分:3)

您需要将所有二进制文件链接到他们使用的所有库。您的libstructurelibparserfastq很可能与包含错误中提到的符号的库无关。您需要为这些库添加适当的TARGET_LINK_LIBRARIES命令。