Cmake ld error while compiling - c++

Hello i am trying to compile a program with cmake. but when ever i run make install. its gives this error. I have never worked with Cmake before so its all new to me. plz help me.
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
Here is the 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
)
any idea's how to solve this problem?

You need to link all yout binaries with all libraries they use. Your libstructure and libparserfastq are most likely not linked with libraries containing symbols mentioned in the errors. You need to add appropriate TARGET_LINK_LIBRARIES commands for those libraries.

Related

Building gRPC and openssl as dependency with cmake for msys2/mingw64 fails with undefined references

I'm trying to build the grpc helloworld example with changed file tree structure and my own CMakeLists.txt with msys2/mingw64. I want to build grpc from sources as a static library using add_subdirectory and build grpc's dependencies recursevily from sources as well.
Doing that I was getting linking errors with undefined references. After some research it seems that boringssl has problems with building in msys2/mingw64 or at least the way boringssl is included in grpc's repo isn't compatible with msys2/mingw64.
Since the grpc package in msys2 is built using openssl as dependency I decided to build openssl from sources during the build and let grpc statically link to that. I hope it is enough to just clone grpc without the boringssl submodule.
I was able to succesfully link and run the example when openssl was linked dynamically to libssl.dll.a. However when I try to link to static openssl build I'm getting undefined references errors again.`grpc_test2_server.exe
This are the linking errors I'm getting:
cmd.exe /C "cd . && C:\msys64\mingw64\bin\c++.exe -g #CMakeFiles\grpc_test2_server.rsp -o grpc_test2_server.exe -Wl,--out-implib,libgrpc_test2_server.dll.a -Wl,--major-image-version,0,--minor-image-version,0 && cd ."
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: third-party/openssl/lib/libcrypto.a(b_addr.o): in function `addr_strings':
C:\Users\PatVax\Workspace\cpp\grpc_test2\build-debug\third-party\openssl_build/../../../third-party/openssl/crypto/bio/b_addr.c:208: undefined reference to `__imp_getnameinfo'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\PatVax\Workspace\cpp\grpc_test2\build-debug\third-party\openssl_build/../../../third-party/openssl/crypto/bio/b_addr.c:220: undefined reference to `gai_strerrorW'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: third-party/openssl/lib/libcrypto.a(b_addr.o): in function `BIO_lookup_ex':
C:\Users\PatVax\Workspace\cpp\grpc_test2\build-debug\third-party\openssl_build/../../../third-party/openssl/crypto/bio/b_addr.c:731: undefined reference to `gai_strerrorW'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: third-party/openssl/lib/libcrypto.a(b_sock.o): in function `BIO_sock_error':
C:\Users\PatVax\Workspace\cpp\grpc_test2\build-debug\third-party\openssl_build/../../../third-party/openssl/crypto/bio/b_sock.c:99: undefined reference to `__imp_getsockopt'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: third-party/openssl/lib/libcrypto.a(b_sock.o): in function `BIO_gethostbyname':
C:\Users\PatVax\Workspace\cpp\grpc_test2\build-debug\third-party\openssl_build/../../../third-party/openssl/crypto/bio/b_sock.c:113: undefined reference to `__imp_gethostbyname'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: third-party/openssl/lib/libcrypto.a(b_sock2.o): in function `BIO_listen':
C:\Users\PatVax\Workspace\cpp\grpc_test2\build-debug\third-party\openssl_build/../../../third-party/openssl/crypto/bio/b_sock2.c:217: undefined reference to `__imp_getsockopt'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: third-party/openssl/lib/libcrypto.a(b_sock2.o): in function `BIO_accept_ex':
C:\Users\PatVax\Workspace\cpp\grpc_test2\build-debug\third-party\openssl_build/../../../third-party/openssl/crypto/bio/b_sock2.c:290: undefined reference to `__imp_accept'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: third-party/openssl/lib/libcrypto.a(e_capi.o): in function `capi_get_prov_info':
C:\Users\PatVax\Workspace\cpp\grpc_test2\build-debug\third-party\openssl_build/../../../third-party/openssl/engines/e_capi.c:1281: undefined reference to `__imp_CertGetCertificateContextProperty'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\PatVax\Workspace\cpp\grpc_test2\build-debug\third-party\openssl_build/../../../third-party/openssl/engines/e_capi.c:1289: undefined reference to `__imp_CertGetCertificateContextProperty'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: third-party/openssl/lib/libcrypto.a(e_capi.o): in function `capi_cert_get_fname':
C:\Users\PatVax\Workspace\cpp\grpc_test2\build-debug\third-party\openssl_build/../../../third-party/openssl/engines/e_capi.c:1329: undefined reference to `__imp_CertGetCertificateContextProperty'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\PatVax\Workspace\cpp\grpc_test2\build-debug\third-party\openssl_build/../../../third-party/openssl/engines/e_capi.c:1335: undefined reference to `__imp_CertGetCertificateContextProperty'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: third-party/openssl/lib/libcrypto.a(e_capi.o): in function `capi_open_store':
C:\Users\PatVax\Workspace\cpp\grpc_test2\build-debug\third-party\openssl_build/../../../third-party/openssl/engines/e_capi.c:1400: undefined reference to `__imp_CertOpenStore'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: third-party/openssl/lib/libcrypto.a(e_capi.o): in function `capi_list_certs':
C:\Users\PatVax\Workspace\cpp\grpc_test2\build-debug\third-party\openssl_build/../../../third-party/openssl/engines/e_capi.c:1432: undefined reference to `__imp_CertFreeCertificateContext'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\PatVax\Workspace\cpp\grpc_test2\build-debug\third-party\openssl_build/../../../third-party/openssl/engines/e_capi.c:1435: undefined reference to `__imp_CertEnumCertificatesInStore'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\PatVax\Workspace\cpp\grpc_test2\build-debug\third-party\openssl_build/../../../third-party/openssl/engines/e_capi.c:1443: undefined reference to `__imp_CertCloseStore'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: third-party/openssl/lib/libcrypto.a(e_capi.o): in function `capi_find_cert':
C:\Users\PatVax\Workspace\cpp\grpc_test2\build-debug\third-party\openssl_build/../../../third-party/openssl/engines/e_capi.c:1455: undefined reference to `__imp_CertFindCertificateInStore'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\PatVax\Workspace\cpp\grpc_test2\build-debug\third-party\openssl_build/../../../third-party/openssl/engines/e_capi.c:1459: undefined reference to `__imp_CertEnumCertificatesInStore'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: third-party/openssl/lib/libcrypto.a(e_capi.o): in function `capi_find_key':
C:\Users\PatVax\Workspace\cpp\grpc_test2\build-debug\third-party\openssl_build/../../../third-party/openssl/engines/e_capi.c:1559: undefined reference to `__imp_CertFreeCertificateContext'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\PatVax\Workspace\cpp\grpc_test2\build-debug\third-party\openssl_build/../../../third-party/openssl/engines/e_capi.c:1561: undefined reference to `__imp_CertCloseStore'
C:\Users\PatVax\Workspace\cpp\grpc_test2\build-debug\third-party\openssl_build/../../../third-party/openssl/engines/e_capi.c:1593: undefined reference to `__imp_CertFreeCertificateC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: third-party/openssl/lib/libcrypto.a(e_capi.o): in function `capi_load_ssl_client_cert':
C:\Users\PatVax\Workspace\cpp\grpc_test2\build-debug\third-party\openssl_build/../../../third-party/openssl/engines/e_capi.c:1720: undefined reference to `__imp_CertEnumCertificatesInStore'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\PatVax\Workspace\cpp\grpc_test2\build-debug\third-party\openssl_build/../../../third-party/openssl/engines/e_capi.c:1740: undefined reference to `__imp_CertDuplicateCertificateContext'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\PatVax\Workspace\cpp\grpc_test2\build-debug\third-party\openssl_build/../../../third-party/openssl/engines/e_capi.c:1754: undefined reference to `__imp_CertFreeCertificateContext'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\PatVax\Workspace\cpp\grpc_test2\build-debug\third-party\openssl_build/../../../third-party/openssl/engines/e_capi.c:1756: undefined reference to `__imp_CertCloseStore'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.`
And this is my CMakeLists.txt that I'm currently using:
cmake_minimum_required(VERSION 3.24)
project(grpc_test2 C CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_C_STANDARD 17)
set(BUILD_SHARED_LIBS OFF)
set(gRPC_BUILD_SHARED_LIBS OFF)
set(gRPC_BUILD_GRPC_CSHARP_EXT OFF)
set(gRPC_BUILD_GRPC_PHP_EXT OFF)
set(gRPC_BUILD_GRPC_PYTHON_EXT OFF)
set(gRPC_BUILD_GRPC_NODE_EXT OFF)
set(gRPC_BUILD_GRPC_RUBY_EXT OFF)
set(gRPC_BUILD_GRPC_OBJC_EXT OFF)
set(gRPC_BUILD_GRPC_OBJC_PLUGIN OFF)
set(_gRPC_BASELIB_LIBRARIES libws2_32 libcrypt32)
include(ProcessorCount)
ProcessorCount(N)
set(OPENSSL_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third-party/openssl)
set(OPENSSL_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/third-party/openssl_build)
set(OPENSSL_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/third-party/openssl)
set(OPENSSL_INCLUDE_DIR ${OPENSSL_INSTALL_DIR}/include)
set(MSYS_SHELL ${MSYS2_ROOT}/msys2_shell.cmd)
if(CMAKE_BUILD_TYPE STREQUAL "Release")
set(OPENSSL_CONFIGURE_COMMAND ${MSYS_SHELL} -mingw64 -no-start -here -defterm -c
"${OPENSSL_SOURCE_DIR}/Configure --prefix=${OPENSSL_INSTALL_DIR} --openssldir=${OPENSSL_INSTALL_DIR} --release -static no-shared mingw64")
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(OPENSSL_CONFIGURE_COMMAND ${MSYS_SHELL} -mingw64 -no-start -here -defterm -c
"${OPENSSL_SOURCE_DIR}/Configure --prefix=${OPENSSL_INSTALL_DIR} --openssldir=${OPENSSL_INSTALL_DIR} --debug -static no-shared mingw64")
else()
set(OPENSSL_CONFIGURE_COMMAND ${MSYS_SHELL} -mingw64 -no-start -here -defterm -c
"${OPENSSL_SOURCE_DIR}/Configure --prefix=${OPENSSL_INSTALL_DIR} --openssldir=${OPENSSL_INSTALL_DIR} -static no-shared mingw64")
endif()
add_custom_target(OpenSSL_Configured
COMMAND ${OPENSSL_CONFIGURE_COMMAND}
WORKING_DIRECTORY ${OPENSSL_BINARY_DIR}
BYPRODUCTS ${OPENSSL_BINARY_DIR}/Makefile
DEPENDS ${OPENSSL_SOURCE_DIR}/Configure
COMMENT "OpenSSL is configuring")
add_custom_target(OpenSSL_Built
COMMAND ${MSYS_SHELL} -mingw64 -no-start -here -defterm -c "make -j${N}"
WORKING_DIRECTORY ${OPENSSL_BINARY_DIR}
BYPRODUCTS ${OPENSSL_BINARY_DIR}/libssl.a ${OPENSSL_BINARY_DIR}/libcrypto.a
DEPENDS OpenSSL_Configured
COMMENT "OpenSSL is building")
add_custom_target(OpenSSL_Installed
COMMAND ${MSYS_SHELL} -mingw64 -no-start -here -defterm -c "make install"
WORKING_DIRECTORY ${OPENSSL_BINARY_DIR}
BYPRODUCTS ${OPENSSL_INSTALL_DIR}/lib/libssl.a ${OPENSSL_INSTALL_DIR}/lib/libcrypto.a ${OPENSSL_INSTALL_DIR}/lib/libssl.dll.a ${OPENSSL_INSTALL_DIR}/lib/libcrypto.dll.a ${OPENSSL_INSTALL_DIR}/lib/libssl.dll ${OPENSSL_INSTALL_DIR}/lib/libcrypto.dll
DEPENDS OpenSSL_Built
COMMENT "OpenSSL is installing")
add_custom_target(OpenSSL DEPENDS OpenSSL_Installed COMMENT "OpenSSL is ready")
file(MAKE_DIRECTORY ${OPENSSL_INCLUDE_DIR})
add_library(OpenSSL::SSL STATIC IMPORTED GLOBAL)
set_property(TARGET OpenSSL::SSL PROPERTY IMPORTED_LOCATION ${OPENSSL_INSTALL_DIR}/lib/libssl.a)
set_property(TARGET OpenSSL::SSL PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${OPENSSL_INCLUDE_DIR})
add_dependencies(OpenSSL::SSL OpenSSL)
add_library(OpenSSL::Crypto STATIC IMPORTED GLOBAL)
set_property(TARGET OpenSSL::Crypto PROPERTY IMPORTED_LOCATION ${OPENSSL_INSTALL_DIR}/lib/libcrypto.a)
set_property(TARGET OpenSSL::Crypto PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${OPENSSL_INCLUDE_DIR})
add_dependencies(OpenSSL::Crypto OpenSSL)
add_library(ssl STATIC IMPORTED GLOBAL)
set_property(TARGET ssl PROPERTY IMPORTED_LOCATION ${OPENSSL_INSTALL_DIR}/lib/libssl.a)
set_property(TARGET ssl PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${OPENSSL_INCLUDE_DIR})
add_dependencies(ssl OpenSSL)
add_library(crypto STATIC IMPORTED GLOBAL)
set_property(TARGET crypto PROPERTY IMPORTED_LOCATION ${OPENSSL_INSTALL_DIR}/lib/libcrypto.a)
set_property(TARGET crypto PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${OPENSSL_INCLUDE_DIR})
add_dependencies(crypto OpenSSL)
set(_gRPC_SSL_LIBRARIES ssl crypto)
set(_gRPC_SSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR})
add_subdirectory(third-party/grpc ${CMAKE_CURRENT_BINARY_DIR}/third-party/grpc)
get_filename_component(hw_proto "${CMAKE_CURRENT_SOURCE_DIR}/protobufs/helloworld.proto" ABSOLUTE)
get_filename_component(hw_proto_path "${hw_proto}" PATH)
find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin)
set(hw_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.pb.cc")
set(hw_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.pb.h")
set(hw_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.grpc.pb.cc")
set(hw_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.grpc.pb.h")
add_custom_command(
OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}"
COMMAND protobuf::protoc
ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
-I "${hw_proto_path}"
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
"${hw_proto}"
DEPENDS "${hw_proto}")
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
add_library(hw_grpc_proto
${hw_grpc_srcs}
${hw_grpc_hdrs}
${hw_proto_srcs}
${hw_proto_hdrs})
target_link_libraries(hw_grpc_proto grpc++ grpc++_reflection libprotobuf)
add_executable(${CMAKE_PROJECT_NAME}_server server.cpp)
add_executable(${CMAKE_PROJECT_NAME}_client client.cpp)
target_link_libraries(${CMAKE_PROJECT_NAME}_server grpc++ grpc++_reflection libprotobuf hw_grpc_proto)
target_link_libraries(${CMAKE_PROJECT_NAME}_client grpc++ grpc++_reflection libprotobuf hw_grpc_proto)
My directory structure looks like the following:
grpc is cloned with all submodules without boringssl
openssl is cloned with all submodules
protobufs contains the .proto files that are being compiled during the build process
Contents of the .cpp files are identical to those in the helloworld example in the grpc repo
What could be the reason of my problems? Am I missing something? Thanks in advance.
EDIT3: I've actually realized a big blunder here. You can't link against the ws2_32.lib as it was built with MSVC and not MinGW. However the issue to your problem stems from here.
I feel like a donkey, but apparently newer versions of MSYS2/MinGW should be able to link against these static libraries. So the following solution is worth a try.
EDIT: After some digging in I think I found the reason why MSVC is supported and mingw is not. The reason why you're having issues is because they are most likely using #pragma to link their libraries (this is a MSVC specific feature).
Try additionaly linking to this library: ws2_32 (maybe the 64 bit version is called ws2_64) - (more precisely you want to link against winsock2 64 bit version)
EDIT2: They are all named ws2_32 and the #pragma picks the right one for you, i.e. the only thing different is the path to the correct SDK
Based on this official github issue. The GRPC team does not support MinGW for Windows builds.
They describe the same issue that you are describing and they also have a suggestion on how to fix boringssl to work i.e.
By applying this patch and
by building boringssl with the following define OPENSSL_NO_ASM.
Long story short, I would switch to MSVC on Windows if I were you - I don't see a reason why not to use it if your target platform is Windows anyway.
EDIT: However if you are still persistent on using MinGW then maybe to maybe get you closer to how to fix your issue I would maybe point out that gai_strerrorW is a function defined in ws2tcpip.h

Undefined reference when linking libpq in C++ project

I am trying to use libpqxx (and implicitly libpq) in a C++ project.
I use vcpkg as a submodule to get my libs by setting CMAKE_TOOLCHAIN_FILE.
When I try to build, I get the following errors:
/usr/bin/ld: /home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/lib/libpq.a(fe-auth.o): in function `pg_fe_sendauth':
fe-auth.c:(.text+0x4fe): undefined reference to `pg_md5_encrypt'
/usr/bin/ld: fe-auth.c:(.text+0x51b): undefined reference to `pg_md5_encrypt'
/usr/bin/ld: /home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/lib/libpq.a(fe-auth.o): in function `pg_fe_getauthname':
fe-auth.c:(.text+0x838): undefined reference to `pqGetpwuid'
/usr/bin/ld: fe-auth.c:(.text+0x8a4): undefined reference to `pg_strerror_r'
/usr/bin/ld: /home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/lib/libpq.a(fe-auth.o): in function `PQencryptPassword':
fe-auth.c:(.text+0x936): undefined reference to `pg_md5_encrypt'
/usr/bin/ld: /home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/lib/libpq.a(fe-auth.o): in function `PQencryptPasswordConn':
fe-auth.c:(.text+0x9ed): undefined reference to `pg_md5_encrypt'
/usr/bin/ld: /home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/lib/libpq.a(fe-auth-scram.o): in function `build_client_final_message':
fe-auth-scram.c:(.text+0xdb): undefined reference to `scram_SaltedPassword'
/usr/bin/ld: fe-auth-scram.c:(.text+0xee): undefined reference to `scram_ClientKey'
/usr/bin/ld: fe-auth-scram.c:(.text+0xfe): undefined reference to `scram_H'
/usr/bin/ld: fe-auth-scram.c:(.text+0x113): undefined reference to `scram_HMAC_init'
/usr/bin/ld: fe-auth-scram.c:(.text+0x12d): undefined reference to `scram_HMAC_update'
/usr/bin/ld: fe-auth-scram.c:(.text+0x141): undefined reference to `scram_HMAC_update'
/usr/bin/ld: fe-auth-scram.c:(.text+0x15b): undefined reference to `scram_HMAC_update'
/usr/bin/ld: fe-auth-scram.c:(.text+0x16f): undefined reference to `scram_HMAC_update'
/usr/bin/ld: fe-auth-scram.c:(.text+0x185): undefined reference to `scram_HMAC_update'
/usr/bin/ld: fe-auth-scram.c:(.text+0x195): undefined reference to `scram_HMAC_final'
/usr/bin/ld: fe-auth-scram.c:(.text+0x1e4): undefined reference to `pg_b64_enc_len'
/usr/bin/ld: fe-auth-scram.c:(.text+0x213): undefined reference to `pg_b64_encode'
/usr/bin/ld: fe-auth-scram.c:(.text+0x344): undefined reference to `pg_b64_enc_len'
/usr/bin/ld: fe-auth-scram.c:(.text+0x368): undefined reference to `pg_b64_encode'
...
I have broken down the linking command here:
/usr/bin/cmake -E cmake_link_script CMakeFiles/hello-pq.dir/link.txt --verbose=1
/usr/bin/c++ CMakeFiles/hello-pq.dir/CMakeFiles/3.16.3/CompilerIdCXX/CMakeCXXCompilerId.cpp.o CMakeFiles/hello-pq.dir/main.cpp.o
-o ../bin/hello-pq
/home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/debug/lib/libssl.a
/home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/debug/lib/libcrypto.a
/home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/debug/lib/libpqxx-7.3.a
-lpthread
/home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/lib/libpq.a -ldl
My CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 3.16)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../../third-party/vcpkg/scripts/buildsystems/vcpkg.cmake
CACHE STRING "Vcpkg toolchain file")
project(hello-pq)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin)
find_package(OpenSSL REQUIRED)
find_package(libpqxx CONFIG REQUIRED)
file(GLOB_RECURSE PROJECT_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
add_executable(${PROJECT_NAME} ${PROJECT_SOURCES})
target_link_libraries(${PROJECT_NAME}
PRIVATE OpenSSL::SSL
PRIVATE OpenSSL::Crypto
PRIVATE libpqxx::pqxx)
I looked at the libpq.a from vcpkg installed dir with nm and I can see that for example, pg_md5_encrypt appears as undefined:
U pg_md5_encrypt
I don't get it, where are these missing functions like pg_md5_encrypt?
Is there another libpq... that I need to link or maybe a different version?
After some more digging around and testing I found that there are 2 more postgres static libraries that I need to link:
libpqcommon.a
libpgport.a
Additionally, the link order is also important and altough I was expecting to have to pass libs that are needed before the libs that need them, this is not the case here and it feels backwards.
Here is a working linker command:
usr/bin/c++ CMakeFiles/hello-pq.dir/src/main.cpp.o \
-o ../bin/hello-pq \
/home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/debug/lib/libpqxx-7.3.a \
/home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/lib/libpq.a \
/home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/lib/libpgcommon.a \
/home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/lib/libpgport.a \
/home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/debug/lib/libssl.a \
/home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/debug/lib/libcrypto.a \
-lpthread \
-ldl
In order to link the extra 2 static libs and also to achieve the order above, I updated the CMakeLists.txt like so:
cmake_minimum_required(VERSION 3.16)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../../third-party/vcpkg/scripts/buildsystems/vcpkg.cmake
CACHE STRING "Vcpkg toolchain file")
project(hello-pq)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin)
find_package(OpenSSL REQUIRED)
#find_package(PostgreSQL REQUIRED) # Not needed (it will duplicate the libs)
find_package(libpqxx CONFIG REQUIRED)
file(GLOB_RECURSE PROJECT_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
add_executable(${PROJECT_NAME} ${PROJECT_SOURCES})
target_link_libraries(${PROJECT_NAME}
PRIVATE libpqxx::pqxx
PRIVATE PostgreSQL::PostgreSQL
PRIVATE OpenSSL::SSL
PRIVATE OpenSSL::Crypto)
This translates into the following linker command:
/usr/bin/c++ \
CMakeFiles/hello-pq.dir/src/main.cpp.o \
-o ../bin/hello-pq \
/home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/debug/lib/libpqxx-7.3.a \
/home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/debug/lib/libpq.a \
/home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/debug/lib/libssl.a \
/home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/debug/lib/libcrypto.a \
/home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/lib/libpq.a \
/home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/lib/libpgport.a \
/home/user/work/cxx-playground/third-party/vcpkg/installed/x64-linux/lib/libpgcommon.a \
-ldl \
-lpthread
We can see that libpq.a appears twice in the link arguments:
once due to libpqxx::pqxx target (I assume)
once due to PostgreSQL::PostgreSQL target
which also contains the 2 missing static libs that need to be linked (libpgport.a and libpgcommon.a).
My conclusion is that this is a libpqxx bug, which should also link those 2 static libs with target_link_libraries(PUBLIC...) in the only target that it exposes (libpqxx::pqxx)

C++ undefined reference for libtins library

I installed the libtins package for C++, by building it as described and adding #include <tins/tins.h> to the header of the example file. I ran ldconfig but building always throws a Undefined reference error:
CMakeFiles/lts.dir/main.cpp.o: In function `main':
/home/patrick/ClionProjects/lts/main.cpp:6: undefined reference to `Tins::EthernetII::EthernetII(Tins::HWAddress<6ul, unsigned char> const&, Tins::HWAddress<6ul, unsigned char> const&)'
/home/patrick/ClionProjects/lts/main.cpp:7: undefined reference to `Tins::IPv4Address::IPv4Address(char const*)'
/home/patrick/ClionProjects/lts/main.cpp:7: undefined reference to `Tins::IPv4Address::IPv4Address(char const*)'
/home/patrick/ClionProjects/lts/main.cpp:7: undefined reference to `Tins::IP::IP(Tins::IPv4Address, Tins::IPv4Address)'
/home/patrick/ClionProjects/lts/main.cpp:8: undefined reference to `Tins::TCP::TCP(unsigned short, unsigned short)'
/home/patrick/ClionProjects/lts/main.cpp:10: undefined reference to `Tins::PDU::inner_pdu(Tins::PDU*)'
/home/patrick/ClionProjects/lts/main.cpp:12: undefined reference to `Tins::PDU::inner_pdu(Tins::PDU*)'
CMakeFiles/lts.dir/main.cpp.o: In function `Tins::EthernetII::~EthernetII()':
/usr/local/include/tins/ethernetII.h:46: undefined reference to `vtable for Tins::EthernetII'
/usr/local/include/tins/ethernetII.h:46: undefined reference to `Tins::PDU::~PDU()'
collect2: error: ld returned 1 exit status
make[3]: *** [lts] Error 1
I am using CLion as IDE and the following cmake file:
cmake_minimum_required(VERSION 3.5)
project(lts)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -ltins")
set(SOURCE_FILES main.cpp)
add_executable(lts ${SOURCE_FILES})
Any Idea what could be the problem?
There's a couple of things to address in your question. First, let CMake find the location of the libtins library for you, then use target_link_libraries() to add it to your lts executable. In the CMake sample in your question, you are specifying library options in the compiler flags variable (CMAKE_CXX_FLAGS). The other thing is to also let CMake handle setting the appropriate compiler flags for C++11 instead of manually adding them to CMAKE_CXX_FLAGS (which would only take care of the compiler part but not the linker). The following should do what you want in a robust, platform independent way:
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(lts)
find_library(TINS_LIBRARY tins)
set(SOURCE_FILES main.cpp)
add_executable(lts ${SOURCE_FILES})
target_link_libraries(lts "${TINS_LIBRARY}")
I recommend you read the CMake docs for find_library() and target_link_libraries() to understand what those commands do. For the C++11 stuff, I recommend this blog article for a more cohesive explanation than what the CMake docs give you (disclosure: I wrote the article).
The CMake variable CMAKE_CXX_FLAGS is for the compiler flags, not for libraries.
To add a library you should use target_link_libraries:
target_link_libraries(lts tins)
If you want all targets to link to the same library, you should add it to the list CMAKE_STANDARD_LIBRARIES.
A small tip on debugging these kind of things: Either set CMAKE_VERBOSE_MAKEFILE or use make VERBOSE=1 to inhibit the normal CMake build output, and instead display the normal make output, which will show you all commands make runs, and all flags and options used for each and every program. That way you will be able to see the -ltins flag being passed as a compiler flag, but not as a linker flag or library.
The compiler should -ltins. Refer to CMake manual on how to add library dependencies.
From the Download page of libtins:
In order to link your application with libtins on GCC or clang, use the -ltins flag
Simply add the following line in your CMake file:
target_link_libraries(PROJECT_NAME -ltins)

Bundling opencv as a static library gives thousands of undefined references

I have a library that I am trying to link with openCV (and I think I did successfully) into one big dynamic library. I then try and add an executable and link everything together to test the library and I get 2000-3000 errors each saying
In function `________________`: undefined reference to `________`
some examples are:
/path/to/libs/libopencv_features2d.a(matchers.cpp.o): In function `cv::FlannBasedMatcher::read(cv::FileNode const&)':
matchers.cpp:(.text._ZN2cv17FlannBasedMatcher4readERKNS_8FileNodeE+0x227): undefined reference to `cv::flann::IndexParams::setAlgorithm(int)'
/path/to/libs/libopencv_videoio.a(cap_gstreamer.cpp.o)` In function `CvCapture_GStreamer::getProperty(int) const':
cap_gstreamer.cpp:(.text._ZNK19CvCapture_GStreamer11getPropertyEi+0x8b): undefined reference to `gst_element_query_position'
/path/to/lib/libopencv_core.a(stat.cpp.o): In function `cv::norm(cv::_InputArray const&, int, cv::_InputArray const&)':
stat.cpp:(.text._ZN2cv4normERKNS_11_InputArrayEiS2_+0x1d27): undefined reference to `ippicviNorm_L1_32f_C1MR'
stat.cpp:(.text._ZN2cv4normERKNS_11_InputArrayEiS2_+0x1dab): undefined reference to `ippicviNorm_L1_8u_C1MR'
My cmake file which runs:
project(SDK-build)
cmake_minimum_required(VERSION 2.8)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(MYLIB_SRC
file1.cpp
file2.cpp
file3.cpp
)
add_library(gesture SHARED ${MYLIB_SRC})
cmake_policy(SET CMP0015 NEW)
link_directories(./opencvlib-wgstreamer)
set(OPENCV_LIBS
libopencv_calib3d.a
libopencv_core.a
libopencv_features2d.a
libopencv_highgui.a
libopencv_imgcodecs.a
libopencv_imgproc.a
libopencv_ml.a
libopencv_objdetect.a
libopencv_photo.a
libopencv_video.a
libopencv_videoio.a
)
set(TEST_SRC
test.cpp
)
add_executable(gesture_test ${TEST_SRC})
#build library
#target_link_libraries(gesture -Wl,-whole-archive ${OPENCV_LIBS} -Wl,--no-whole-archive)
#build library with executable
target_link_libraries(gesture_test gesture -Wl,-whole-archive ${OPENCV_LIBS} -Wl,--no-whole-archive)
When I use the first target_link_libraries, everything builds and make has no problem executing, but linking with the file with main() causes the massive confusion. Any suggestions I've been banging my head over this for hours. I also tried several combinations of compiling opencv, using both WITH_IPP=ON, WITH_IPP=OFF, and WITH_GSTREAMER_ON
You have to specify the libraries in the correct order.
See here for more information.
Edit I see you are using -Wl-whole-archive which I believe is an other possible way to fix the problem, so maybe I'm wrong

FLTK 1.3 Linking errors

I update my FLTK from 1.1 to 1.3, then I can't compile my code which is worked well before update.
...
[100%] Building CXX object CMakeFiles/PROSTVIEW.dir/include/nifti/vtkznzlib.cxx.o
Linking CXX executable PROSTVIEW
/usr/local/lib/libfltk.a(fl_font.cxx.o): In function `fontopen(char const*, int, bool, int)':
fl_font.cxx:(.text+0x298): undefined reference to `FcPatternCreate'
fl_font.cxx:(.text+0x362): undefined reference to `FcPatternAddString'
fl_font.cxx:(.text+0x3e3): undefined reference to `FcPatternAddString'
fl_font.cxx:(.text+0x3f7): undefined reference to `FcPatternAddInteger'
fl_font.cxx:(.text+0x40b): undefined reference to `FcPatternAddInteger'
fl_font.cxx:(.text+0x424): undefined reference to `FcPatternAddDouble'
fl_font.cxx:(.text+0x43c): undefined reference to `FcPatternAddString'
fl_font.cxx:(.text+0x4df): undefined reference to `FcMatrixRotate'
fl_font.cxx:(.text+0x4f7): undefined reference to `FcPatternAddMatrix'
fl_font.cxx:(.text+0x516): undefined reference to `FcPatternAddBool'
fl_font.cxx:(.text+0x52c): undefined reference to `FcPatternAddBool'
fl_font.cxx:(.text+0x549): undefined reference to `XftFontMatch'
fl_font.cxx:(.text+0x5a0): undefined reference to `XftFontOpen'
fl_font.cxx:(.text+0x5b0): undefined reference to `FcPatternDestroy'
fl_font.cxx:(.text+0x5f3): undefined reference to `XftFontOpenPattern'
fl_font.cxx:(.text+0x603): undefined reference to `FcPatternDestroy'
fl_font.cxx:(.text+0x659): undefined reference to `XftFontOpenXlfd'
/usr/local/lib/libfltk.a(fl_font.cxx.o): In function `utf8extents(Fl_Font_Descriptor*, char const*, int, _XGlyphInfo*)':
fl_font.cxx:(.text+0x84b): undefined reference to `XftTextExtents32'
/usr/local/lib/libfltk.a(fl_font.cxx.o): In function `fl_xft_width(Fl_Font_Descriptor*, unsigned int*, int)':
fl_font.cxx:(.text+0x98a): undefined reference to `XftTextExtents32'
/usr/local/lib/libfltk.a(fl_font.cxx.o): In function `fl_destroy_xft_draw(unsigned long)':
fl_font.cxx:(.text+0x102e): undefined reference to `XftDrawChange'
/usr/local/lib/libfltk.a(fl_font.cxx.o): In function `Fl_Xlib_Graphics_Driver::draw(char const*, int, int, int)':
fl_font.cxx:(.text+0x10c6): undefined reference to `XftDrawCreate'
fl_font.cxx:(.text+0x10f6): undefined reference to `XftDrawChange'
fl_font.cxx:(.text+0x1140): undefined reference to `XftDrawSetClip'
fl_font.cxx:(.text+0x1202): undefined reference to `XftDrawString32'
/usr/local/lib/libfltk.a(fl_font.cxx.o): In function `fl_drawUCS4(Fl_Graphics_Driver*, unsigned int const*, int, int, int)':
fl_font.cxx:(.text+0x1313): undefined reference to `XftDrawCreate'
fl_font.cxx:(.text+0x1343): undefined reference to `XftDrawChange'
fl_font.cxx:(.text+0x138d): undefined reference to `XftDrawSetClip'
fl_font.cxx:(.text+0x1433): undefined reference to `XftDrawString32'
/usr/local/lib/libfltk.a(fl_font.cxx.o): In function `Fl_Xlib_Graphics_Driver::rtl_draw(char const*, int, int, int)':
fl_font.cxx:(.text+0x1480): undefined reference to `FcUtf8Len'
fl_font.cxx:(.text+0x14ff): undefined reference to `FcUtf8ToUcs4'
collect2: ld returned 1 exit status
make[2]: *** [PROSTVIEW] Error 1
make[1]: *** [CMakeFiles/PROSTVIEW.dir/all] Error 2
make: *** [all] Error 2
Here's my CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
PROJECT(PROSTVIEW)
SET(CMAKE_BUILD_TYPE DEBUG)
SET(CMAKE_CXX__FLAGS -O3 -pipe -ffast-math -Wno-deprecated)
# Chargement Package
# FLTK
FIND_PACKAGE ( FLTK )
IF ( FLTK_FOUND )
INCLUDE_DIRECTORIES( ${FLTK_INCLUDE_DIR} )
ENDIF ( FLTK_FOUND )
# ITK
FIND_PACKAGE ( ITK )
IF ( ITK_FOUND )
INCLUDE( ${USE_ITK_FILE} )
ENDIF( ITK_FOUND )
# VTK
FIND_PACKAGE ( VTK )
IF ( VTK_FOUND )
INCLUDE( ${USE_VTK_FILE} )
ENDIF( VTK_FOUND )
SET(VTK_LIBRARIES vtkCommon vtkRendering vtkWidgets vtkGraphics vtkGenericFiltering vtkzlib)
# vtkFlRenderWindowInteractor
SET(VTKFL_INCLUDE_DIR "include/vtkfl")
SET(VTKFL_CPP
${VTKFL_INCLUDE_DIR}/vtkFlRenderWindowInteractor.cxx)
# Auxiliary_Tools
SET(AT_DIR "include/Auxiliary_Tools")
SET(AT_INCLUDE_DIR ${AT_DIR}/include)
SET(AT_LIBRARY_DIR ${AT_DIR}/lib)
#Nifty
SET(NII_DIR "include/nifti")
SET(NII_SRC
${NII_DIR}/vtkNIfTIReader.cxx
${NII_DIR}/vtkNIfTIWriter.cxx
${NII_DIR}/vtkAnalyzeReader.cxx
${NII_DIR}/vtkAnalyzeWriter.cxx
${NII_DIR}/vtknifti1_io.cxx
${NII_DIR}/vtkznzlib.cxx)
#Other include
SET(PROSTVIEW_INCLUDE_DIR "include")
SET(PROSTVIEW_SRC
${PROSTVIEW_INCLUDE_DIR}/ContourTmt.cpp
${PROSTVIEW_INCLUDE_DIR}/conversion.cpp
${PROSTVIEW_INCLUDE_DIR}/TmtMatrix.cpp)
# VOLUME Widget
SET(VOLUME_WIDGET_DIR "include/GUI")
SET(VOLUME_WIDGET
${VOLUME_WIDGET_DIR}/VOLUME_Loader.cpp
${VOLUME_WIDGET_DIR}/VOLUME_Widget.cpp
${VOLUME_WIDGET_DIR}/VOLUME_Mouse_Widget.cpp
${VOLUME_WIDGET_DIR}/VOLUME_3DView.cpp
${VOLUME_WIDGET_DIR}/CONTOUR_Loader.cpp
${VOLUME_WIDGET_DIR}/ProstView.cpp)
# MODULES
SET(MODULE_DIR "Module")
# SEGMENTATION
SET(SEGMENTATION_DIR "Module/Segmentation")
SET(SEGMENTATION
${SEGMENTATION_DIR}/DDC2D.cpp
${SEGMENTATION_DIR}/DDC3D.cpp
${SEGMENTATION_DIR}/DDC3DHu.cpp
${SEGMENTATION_DIR}/DDC3DPlus.cpp
${SEGMENTATION_DIR}/DDC3DBal.cpp
${SEGMENTATION_DIR}/IMAGE_ENERGY.cpp
${SEGMENTATION_DIR}/REGULARIZATION.cpp
${SEGMENTATION_DIR}/OPTIMAL_SURFACE_DETECTION.cpp
${SEGMENTATION_DIR}/OPTIMAL_MULTIPLE_SURFACES_DETECTION.cpp
${SEGMENTATION_DIR}/RESAMPLE_From_Prostate.cpp
${SEGMENTATION_DIR}/RECTAL_WALL_US.cpp
${SEGMENTATION_DIR}/BLADDER_MRI.cpp
${SEGMENTATION_DIR}/RECTUM_MRI.cpp
${SEGMENTATION_DIR}/REGION_GROWING.tpp )
#MESH
SET(MESH_DIR "Module/Mesh")
SET(MESH
${MESH_DIR}/GENERIC_MESH.cpp
${MESH_DIR}/ELLIPSOID_MESH.cpp
${MESH_DIR}/PROSTATE_MESH.cpp
${MESH_DIR}/TUBULAR_MESH.cpp
${MESH_DIR}/OPEN_MESH.cpp
${MESH_DIR}/QUADRIC_MESH.cpp
${MESH_DIR}/ELLIPTICAL_CYLINDER_MESH.cpp
${MESH_DIR}/CONTOURS_MAN_MESH.cpp)
#STUDY
SET(STUDY_DIR "Module/Statistics")
SET(STUDY
${STUDY_DIR}/PROFILE.cpp
${STUDY_DIR}/Histogram.cpp
${STUDY_DIR}/HISTOGRAM_FROM_MESH.cpp
${STUDY_DIR}/TRAINING_SET_ALIGNMENT.cpp
${STUDY_DIR}/APPEARANCE_MODEL.cpp)
# MOMENTS
SET(MOMENTS_DIR "Module/Moments")
SET(MOMENTS
${MOMENTS_DIR}/KRAWTCHOUK_Moments.tpp
${MOMENTS_DIR}/TCHEBICHEF_Moments.tpp
${MOMENTS_DIR}/GEOMETRIC_Moments.tpp)
#VALIDATION
SET(VALIDATION_DIR "Module/Evaluation")
SET(VALIDATION
${VALIDATION_DIR}/Metrics.cpp)
# Include et Link Directories
INCLUDE_DIRECTORIES(${FLTK_INCLUDE_DIR} ${VTK_INCLUDE_DIRS} ${VTKFL_INCLUDE_DIR} ${AT_INCLUDE_DIR} ${NII_DIR} ${PROSTVIEW_INCLUDE_DIR} ${VOLUME_WIDGET_DIR} ${MODULE_DIR})
LINK_DIRECTORIES(${FLTK_LIBRARY_DIR} ${VTK_LIBRARY_DIRS} ${AT_LIBRARY_DIR} ${PROSTVIEW_INCLUDE_DIR} ${VOLUME_WIDGET_DIR} ${MODULE_DIR})
# Sources
SET(SRC main.cpp)
# Executables and "stand-alone " librairies
ADD_EXECUTABLE(PROSTVIEW ${SRC} ${PROSTVIEW_SRC} ${VTKFL_CPP} ${VOLUME_WIDGET} ${SEGMENTATION} ${MESH} ${STUDY} ${MOMENTS} ${VALIDATION} ${NII_SRC})
# Linkage
TARGET_LINK_LIBRARIES(PROSTVIEW ${FLTK_LIBRARIES} ${VTK_LIBRARIES} ${ITK_LIBRARIES})
I tried to add some libs in my CMakeLists.txt, but it's not work. Who can tell me what’s the problem?
From FLTK 1.3's README.CMake.txt:
USING CMAKE WITH FLTK
This howto assumes that you have FLTK libraries which were built using
CMake, installed. Building them with CMake generates some CMake
helper files which are installed in standard locations, making FLTK
easy to find and use.
Here is a basic CMakeLists.txt file using FLTK.
cmake_minimum_required(VERSION 2.6)
project(hello)
find_package(FLTK REQUIRED NO_MODULE) include(${FLTK_USE_FILE})
add_executable(hello WIN32 hello.cxx)
target_link_libraries(hello fltk)
The find_package command tells CMake to find the package FLTK,
REQUIRED means that it is an error if it's not found. NO_MODULE tells
it to search only for the FLTKConfig file, not using the
FindFLTK.cmake supplied with CMake, which doesn't work with this
version of FLTK.
Once the package is found we include the ${FLTK_USE_FILE} which adds
the FLTK include directories and library link information to its
knowledge base. After that your programs will be able to find FLTK
headers and when you link the fltk library, it automatically links the
libraries fltk depends on.
It seems that from FLTK 1.1 to 1.3 they changed the method needed to find the library, maybe for comparability/testing reasons?
I got hung up on the same issue, hope someone finds this useful. :)