undefined reference to `vtable in custom lib created with cmake - cmake

I'm getting the error: lib/libhrlLib.so: undefined reference to `hrlQseqDev::waiting(bool, int)' and some more ...
I'm trying to build my project with cmake (3.7.2) instead of with qmake (Qt5)
CMakeLists.txt:
project(${TARGET_NAME})
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 14)
set(POSITION_INDEPENDENT_CODE FALSE)
macro(NAMELIST erg in)
set(os "")
set(srcs ${in})
separate_arguments(srcs)
foreach(is ${srcs})
set(os ${os} ${is})
endforeach(is)
set(${erg} ${os})
endmacro(NAMELIST)
macro(FINDMODULES erg in)
set(os "")
set(srcs ${in})
separate_arguments(srcs)
foreach(is ${srcs})
find_package(Qt5${is} REQUIRED)
set(os ${os} Qt5::${is})
endforeach(is)
set(${erg} ${os})
endmacro(FINDMODULES)
NAMELIST(SRCS ${TARGET_SRCS})
FINDMODULES(QLIBS ${QMODULES})
if(INC_PATH)
NAMELIST(INCS ${INC_PATH})
set(INCLUDES ${INCS})
endif(INC_PATH)
if(TARGET_EXTLIBS)
NAMELIST(EXTRA_LIBS ${EXTRA_LIBS} "${TARGET_EXTLIBS}")
endif(TARGET_EXTLIBS)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
include_directories(${INCLUDES})
if(BUILD_LIB)
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-shared")
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "-shared")
add_library(${TARGET_NAME} SHARED ${SRCS})
target_link_libraries(${TARGET_NAME} ${QLIBS} ${EXTRA_LIBS})
set_property(TARGET ${TARGET_NAME} PROPERTY VERSION "1.0.0")
set_property(TARGET ${TARGET_NAME} PROPERTY SOVERSION 1 )
install(TARGETS ${TARGET_NAME} LIBRARY DESTINATION lib)
install(TARGETS ${TARGET_NAME} LIBRARY DESTINATION lib NAMELINK_ONLY)
else()
if(USE_LIB_PATH)
add_executable(${TARGET_NAME} ${SRCS})
target_link_libraries(${TARGET_NAME} -L${OUT_PATH}/lib lib${USE_LIB}.so.1
${QLIBS} ${EXTRA_LIBS})
else()
add_executable(${TARGET_NAME} ${SRCS})
target_link_libraries(${TARGET_NAME} ${QLIBS} ${EXTRA_LIBS})
endif(USE_LIB_PATH)
install(TARGETS ${TARGET_NAME} RUNTIME DESTINATION bin)
endif(BUILD_LIB)
The shared library is built with:
cmake -G "Unix Makefiles" -DINC_PATH:STRING="some includes" -DTARGET_EXTLIBS:STRING="sys libs" -DTARGET_NAME:STRING=LibName -DBUILD_LIB:BOOL=1 -DTARGET_SRCS:STRING="cpp- and c-file" -DQMODULES:STRING="Core Gui Widgets PrintSupport" -DOUT_PATH:STRING=InstallPath .. -DCMAKE_INSTALL_PREFIX=InstallPath >> /dev/null
When I try to build a program against this shared library with:
cmake -G "Unix Makefiles" -DINC_PATH:STRING="some includes" -DTARGET_EXTLIBS:STRING="sys libs" -DTARGET_NAME:STRING=ProgName -DBUILD_LIB:BOOL=0 -DTARGET_SRCS:STRING="cpp-file" -DQMODULES:STRING="Core Gui Widgets PrintSupport" -DOUT_PATH=InstallPath -DUSE_LIB:STRING="LibName" -DUSE_LIB_PATH:STRING="BuildPath of LibName" .. -DCMAKE_INSTALL_PREFIX=InstallPath >> /dev/null
I get the error 'lib/libhrlLib.so: undefined reference to ...'.
I do not get this error when the library was built with qmake.
How can I fix this?

Related

How to make sure correct include and linking paths are set for downstream projects when making library with cmake?

I've been trying to follow the following link to make sure that I'm doing things completely/correctly, and also so that I might expand on what I'm doing later by e.g. adding components, adding different version requirements for some libraries, etc. In short, I'm trying to be on the road to knowing what I'm doing with CMake instead of cobbling things together with tidbits I find on the Internet. The problem is, that after following along with this tutorial in the documentation, I've apparently broken my stuff such that my downstream projects that include this library can't build or link to it (I presume the appropriate include and linker paths aren't getting set).
The link: cmake guide: adding export configuration
In doing so, I've added a minimal Config.cmake.in, *ConfigVersion.cmake, *Targets.cmake, and automagically exported a *Config.cmake file per what you see in that guide.
Prior to making these changes, what I had looked like this: (effectively only used the exported targets)
install(TARGETS ${PROJECT_NAME} ${INTERFACES}
EXPORT ${PROJECT_NAME}Config
Library
DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rms
INCLUDES
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
export(
TARGETS ${PROJECT_NAME} ${INTERFACES}
FILE ${PROJECT_NAME}Config.cmake
NAMESPACE ${PROJECT_NAME}::
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
)
install(
EXPORT ${PROJECT_NAME}Config
DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake"
)
After following that document (as best I could anyway), what I've got is
install(TARGETS ${PROJECT_NAME} ${INTERFACES}
EXPORT ${PROJECT_NAME}Targets
Library
DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rms
INCLUDES
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
EXPORT ${PROJECT_NAME}Targets
FILE "${PROJECT_NAME}Targets.cmake"
DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake"
NAMESPACE ${PROJECT_NAME}::
)
include(CMakePackageConfigHelpers)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake"
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION "${PROJ_VERSION}"
COMPATIBILITY AnyNewerVersion
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake"
)
Before I made the changes outlined above, downstream projects would link to this library fine, after they do not. To be abundantly clear, what I do in the downstream projects looks like this:
find_package(rms_utils)
# ...
target_link_libraries(${PROJECT_NAME} PUBLIC rms_utils)
As stated above, after making this change, the downstream projects aren't finding includes or linking as appropriate. What do I need to change to resolve this.
An example error, per request in comments:
/opt/rms/src/rms/core/src/genericsweep.cpp:12:10: fatal error: 'rms/plugin.hpp' file not found
full text of CMakeLists.txt
###########################################################
###########################################################
##### 1. Required CMake Version #####
###########################################################
###########################################################
cmake_minimum_required(VERSION 3.16.0)
###########################################################
###########################################################
##### 2. Package Name and Version #####
###########################################################
###########################################################
set(VERBOSE 1)
add_link_options("LINKER:-v")
file(READ "VERSION" ver_raw_in)
string(REGEX MATCH " _version=([0-9\.]+).*" _ ${ver_raw_in})
set(PROJ_VERSION "${CMAKE_MATCH_1}")
string(REGEX MATCH ".*_soversion=([0-9\.]+).*" _ ${ver_raw_in})
set(PROJ_SOVERSION "${CMAKE_MATCH_1}")
string(REGEX MATCH ".*_rms_interface_sdr_version=([0-9\.]+).*" _ ${ver_raw_in})
set(SDRIFACE_VERSION "${CMAKE_MATCH_1}")
string(REGEX MATCH ".*_rms_interface_portswitcher_version=([0-9\.]+).*" _ ${ver_raw_in})
set(PSIFACE_VERSION "${CMAKE_MATCH_1}")
string(REGEX MATCH ".*_rms_interface_powermeter_version=([0-9\.]+).*" _ ${ver_raw_in})
set(PMIFACE_VERSION "${CMAKE_MATCH_1}")
string(REGEX MATCH ".*_rms_interface_transmitter_version=([0-9\.]+).*" _ ${ver_raw_in})
set(TXIFACE_VERSION "${CMAKE_MATCH_1}")
string(REGEX MATCH ".*_rms_interface_receiver_version=([0-9\.]+).*" _ ${ver_raw_in})
set(RXIFACE_VERSION "${CMAKE_MATCH_1}")
string(REGEX MATCH ".*_rms_interface_spectrumanalyzer_version=([0-9\.]+).*" _ ${ver_raw_in})
set(SPECANIFACE_VERSION "${CMAKE_MATCH_1}")
string(REGEX MATCH ".*_rms_interface_powermeter_version=([0-9\.]+).*" _ ${ver_raw_in})
set(SPECANIFACE_VERSION "${CMAKE_MATCH_1}")
project(rms_utils
LANGUAGES CXX
VERSION ${PROJ_VERSION}
DESCRIPTION "library supporting core RMS functionality")
###########################################################
###########################################################
##### 3. required build definitions and options #####
###########################################################
###########################################################
include(GNUInstallDirs)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_definitions(-DQT_NO_KEYWORDS)
IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
SET(CMAKE_INSTALL_PREFIX /opt/rms CACHE PATH "comment" FORCE)
ENDIF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
option (FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." TRUE)
if (${FORCE_COLORED_OUTPUT})
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options (-fdiagnostics-color=always)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options (-fcolor-diagnostics)
endif ()
endif ()
###########################################################
###########################################################
##### 4. find all depdendency packages #####
###########################################################
###########################################################
list(APPEND CMAKE_PREFIX_PATH "/opt/qt-rms/")
find_package(Qt6 6.2 COMPONENTS Core Sql REQUIRED)
###########################################################
###########################################################
##### 5. set up build targets #####
###########################################################
###########################################################
set(
PROJ_SOURCES
src/baseworker.cpp
src/complex.cpp
src/iqbuffer.cpp
src/logging_core.cpp
src/plugin.cpp
src/stopwatch.cpp
src/utilities.cpp
)
set(
PROJ_INCLUDES
include/consoletext.hpp
include/complex.hpp
include/iqbuffer.hpp
include/constants.hpp
include/logging_core.hpp
include/plugin.hpp
include/rmsutils_global.hpp
include/stopwatch.hpp
include/utilities.hpp
include/baseworker.hpp
include/singleshotworker.hpp
include/continuousworker.hpp
)
set(
INTERFACES
rms_interface_sdr
rms_interface_portswitcher
rms_interface_transmitter
rms_interface_receiver
rms_interface_spectrumanalyzer
rms_interface_powermeter
)
set(SDR_INCLUDES include/sdrinterface.hpp)
set(PORTSWITCHER_INCLUDES include/portswitcherinterface.hpp)
set(TRANSMITTER_INCLUDES include/transmitterinterface.hpp)
set(RECEIVER_INCLUDES include/receiverinterface.hpp include/collectiqtask.hpp)
set(POWERMETER_INCLUDES include/powermeterinterface.hpp)
set(SPECTRUMANALYZER_INCLUDES include/spectrumanalyzerinterface.hpp)
add_library(${PROJECT_NAME}
SHARED
${PROJ_SOURCES}
${PROJ_INCLUDES}
)
add_library(rms_interface_sdr SHARED
${SDR_INCLUDES}
src/sdrinterface.cpp)
add_library(rms_interface_portswitcher SHARED
${PORTSWITCHER_INCLUDES}
src/portswitcherinterface.cpp)
add_library(rms_interface_transmitter SHARED
${TRANSMITTER_INCLUDES}
src/transmitterinterface.cpp)
add_library(rms_interface_receiver SHARED
${RECEIVER_INCLUDES}
include/collectiqtask.hpp)
add_library(rms_interface_spectrumanalyzer SHARED
${SPECTRUMANALYZER_INCLUDES}
src/spectrumanalyzerinterface.cpp)
add_library(rms_interface_powermeter SHARED
${POWERMETER_INCLUDES}
src/powermeterinterface.cpp)
string(TOUPPER ${PROJECT_NAME}_LIBRARY UPPERNAME)
target_compile_definitions(${PROJECT_NAME} PRIVATE ${UPPERNAME})
target_compile_definitions(rms_interface_sdr PRIVATE ${UPPERNAME})
target_compile_definitions(rms_interface_portswitcher PRIVATE ${UPPERNAME})
target_compile_definitions(rms_interface_transmitter PRIVATE ${UPPERNAME})
target_compile_definitions(rms_interface_receiver PRIVATE ${UPPERNAME})
target_compile_definitions(rms_interface_spectrumanalyzer PRIVATE ${UPPERNAME})
target_compile_definitions(rms_interface_powermeter PRIVATE ${UPPERNAME})
set_target_properties(${PROJECT_NAME}
PROPERTIES
VERSION ${PROJ_VERSION}
SOVERSION ${PROJ_SOVERSION}
MAP_IMPORTED_CONFIG_COVERAGE "DEBUG"
PUBLIC_HEADER "${PROJ_INCLUDES}"
)
set_target_properties(rms_interface_sdr
PROPERTIES
VERSION ${SDRIFACE_VERSION}
SOVERSION ${SDRIFACE_VERSION}
MAP_IMPORTED_CONFIG_COVERAGE "DEBUG"
PUBLIC_HEADER "${SDR_INCLUDES}"
)
set_target_properties(rms_interface_portswitcher
PROPERTIES
VERSION ${PSIFACE_VERSION}
SOVERSION ${PSIFACE_VERSION}
MAP_IMPORTED_CONFIG_COVERAGE "DEBUG"
PUBLIC_HEADER "${PORTSWITCHER_INCLUDES}"
)
set_target_properties(rms_interface_transmitter
PROPERTIES
VERSION ${TXIFACE_VERSION}
SOVERSION ${TXIFACE_VERSION}
MAP_IMPORTED_CONFIG_COVERAGE "DEBUG"
PUBLIC_HEADER "${TRANSMITTER_INCLUDES}"
)
set_target_properties(rms_interface_receiver
PROPERTIES
VERSION ${RXIFACE_VERSION}
SOVERSION ${RXIFACE_VERSION}
MAP_IMPORTED_CONFIG_COVERAGE "DEBUG"
PUBLIC_HEADER "${RECEIVER_INCLUDES}"
)
set_target_properties(rms_interface_spectrumanalyzer
PROPERTIES
VERSION ${SPECANIFACE_VERSION}
SOVERSION ${SPECANIFACE_VERSION}
MAP_IMPORTED_CONFIG_COVERAGE "DEBUG"
PUBLIC_HEADER "${SPECTRUMANALYZER_INCLUDES}"
)
set_target_properties(rms_interface_powermeter
PROPERTIES
VERSION ${PMIFACE_VERSION}
SOVERSION ${PMIFACE_VERSION}
MAP_IMPORTED_CONFIG_COVERAGE "DEBUG"
PUBLIC_HEADER "${POWERMETER_INCLUDES}"
)
target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)
target_include_directories(
rms_interface_sdr
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src)
target_include_directories(
rms_interface_portswitcher
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src)
target_include_directories(
rms_interface_transmitter
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src)
target_include_directories(
rms_interface_receiver
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src)
target_include_directories(
rms_interface_spectrumanalyzer
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src)
target_include_directories(
rms_interface_powermeter
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src)
###########################################################
###########################################################
##### 6. Link against external libraries #####
###########################################################
###########################################################
target_link_libraries(${PROJECT_NAME} Qt::Core Qt::Sql fftw3)
target_link_libraries(rms_interface_sdr Qt::Core Qt::Sql rms_utils rms_interface_transmitter rms_interface_receiver)
target_link_libraries(rms_interface_portswitcher Qt::Core Qt::Sql rms_utils)
target_link_libraries(rms_interface_transmitter Qt::Core Qt::Sql rms_utils)
target_link_libraries(rms_interface_receiver Qt::Core Qt::Sql rms_utils)
target_link_libraries(rms_interface_spectrumanalyzer Qt::Core Qt::Sql rms_utils)
target_link_libraries(rms_interface_powermeter Qt::Core Qt::Sql rms_utils)
###########################################################
###########################################################
##### 7. Install #####
###########################################################
###########################################################
##### all changes that I made when following the guide mentioned in the post happened below this line ######
# this is what I had previously
#install(
# TARGETS ${PROJECT_NAME} ${INTERFACES}
# EXPORT ${PROJECT_NAME}Targets
# LIBRARY
# DESTINATION ${CMAKE_INSTALL_LIBDIR}
# ARCHIVE
# DESTINATION ${CMAKE_INSTALL_LIBDIR}
# RUNTIME
# DESTINATION ${CMAKE_INSTALL_BINDIR}
# PUBLIC_HEADER
# DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rms
# INCLUDES
# DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
# )
#export(
# TARGETS ${PROJECT_NAME} ${INTERFACES}
# FILE ${PROJECT_NAME}Config.cmake
# NAMESPACE ${PROJECT_NAME}::
# FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake")
#install(
# EXPORT ${PROJECT_NAME}Config
# DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")
# and this is what I have now
install(
TARGETS ${PROJECT_NAME} ${INTERFACES}
EXPORT ${PROJECT_NAME}Targets
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rms
INCLUDES
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
EXPORT ${PROJECT_NAME}Targets
FILE "${PROJECT_NAME}Targets.cmake"
DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake"
NAMESPACE ${PROJECT_NAME}::
)
include(CMakePackageConfigHelpers)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake"
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION "${PROJ_VERSION}"
COMPATIBILITY AnyNewerVersion
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake"
)
### for cmake debugging purposes
get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
Linking would also fail (building without cleaning won't need to find headers, but will still fail on trying to link)
--- edits 2022/03/26
added an example error message, fixed an error in what I typed here for the target_link_libraries line that a downstream project might use, added full text of the CMakeLists.txt

multiple definions of functions gcc/g++ __multi3 __negti2 etc

hi I have a sgx project that compile and run with a makefile. The trsted part is compiled with c++ 11 while the untrusted part is compiled with c++ 17.
I am trying now to compile with cmake. I put all the flags I used in the Makefile.. (of course something is not right). It compile fine, but return a lot of linking errors:
[ 64%] Linking CXX executable cscore
/usr/local/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a(_muldi3.o): in function `__multi3':
(.text+0x0): multiple definition of `__multi3'; /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a(_muldi3.o):(.text+0x0): first defined here
/usr/local/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a(_negdi2.o): in function `__negti2':
(.text+0x0): multiple definition of `__negti2'; /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a(_negdi2.o):(.text+0x0): first defined here
/usr/local/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a(_lshrdi3.o): in function `__lshrti3':
(.text+0x0): multiple definition of `__lshrti3'; /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a(_lshrdi3.o):(.text+0x0): first defined here
/usr/local/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a(_ashldi3.o): in function `__ashlti3':
(.text+0x0): multiple definition of `__ashlti3'; /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a(_ashldi3.o):(.text+0x0): first defined here
/usr/local/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a(_ashrdi3.o): in function `__ashrti3':
(.text+0x0): multiple definition of `__ashrti3'; /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a(_ashrdi3.o):(.text+0x0): first defined here
here is the cmake code
# FindPackage cmake file for Intel SGX SDK
cmake_minimum_required(VERSION 2.8.11) # target_include_directories
include(CMakeParseArguments)
set(SGX_FOUND "NO")
if(EXISTS SGX_DIR)
set(SGX_PATH ${SGX_DIR})
elseif(EXISTS SGX_ROOT)
set(SGX_PATH ${SGX_ROOT})
elseif(EXISTS $ENV{SGX_SDK})
set(SGX_PATH $ENV{SGX_SDK})
elseif(EXISTS $ENV{SGX_DIR})
set(SGX_PATH $ENV{SGX_DIR})
elseif(EXISTS $ENV{SGX_ROOT})
set(SGX_PATH $ENV{SGX_ROOT})
else()
set(SGX_PATH "/opt/intel/sgxsdk")
endif()
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(SGX_COMMON_CFLAGS -m32)
set(SGX_LIBRARY_PATH ${SGX_PATH}/lib32)
set(SGX_ENCLAVE_SIGNER ${SGX_PATH}/bin/x86/sgx_sign)
set(SGX_EDGER8R ${SGX_PATH}/bin/x86/sgx_edger8r)
else()
set(SGX_COMMON_CFLAGS -m64)
set(SGX_LIBRARY_PATH ${SGX_PATH}/lib64)
set(SGX_ENCLAVE_SIGNER ${SGX_PATH}/bin/x64/sgx_sign)
set(SGX_EDGER8R ${SGX_PATH}/bin/x64/sgx_edger8r)
endif()
find_path(SGX_INCLUDE_DIR sgx.h "${SGX_PATH}/include" NO_DEFAULT_PATH)
find_path(SGX_LIBRARY_DIR libsgx_urts.so "${SGX_LIBRARY_PATH}" NO_DEFAULT_PATH)
if(SGX_INCLUDE_DIR AND SGX_LIBRARY_DIR)
set(SGX_FOUND "YES")
set(SGX_INCLUDE_DIR "${SGX_PATH}/include" CACHE PATH "Intel SGX include directory" FORCE)
set(SGX_TLIBC_INCLUDE_DIR "${SGX_INCLUDE_DIR}/tlibc" CACHE PATH "Intel SGX tlibc include directory" FORCE)
set(SGX_LIBCXX_INCLUDE_DIR "${SGX_INCLUDE_DIR}/libcxx" CACHE PATH "Intel SGX libcxx include directory" FORCE)
set(SGX_INCLUDE_DIRS ${SGX_INCLUDE_DIR} ${SGX_TLIBC_INCLUDE_DIR} ${SGX_LIBCXX_INCLUDE_DIR})
mark_as_advanced(SGX_INCLUDE_DIR SGX_TLIBC_INCLUDE_DIR SGX_LIBCXX_INCLUDE_DIR SGX_LIBRARY_DIR)
message(STATUS "Found Intel SGX SDK.")
endif()
if(SGX_FOUND)
set(SGX_HW OFF CACHE BOOL "Run SGX on hardware, OFF for simulation.")
set(SGX_MODE Debug CACHE STRING "SGX build mode: Debug; PreRelease; Release.")
if(SGX_HW)
set(SGX_URTS_LIB sgx_urts)
set(SGX_USVC_LIB sgx_uae_service)
set(SGX_TRTS_LIB sgx_trts)
set(SGX_TSVC_LIB sgx_tservice)
else()
set(SGX_URTS_LIB sgx_urts_sim)
set(SGX_USVC_LIB sgx_uae_service_sim)
set(SGX_TRTS_LIB sgx_trts_sim)
set(SGX_TSVC_LIB sgx_tservice_sim)
endif()
if(SGX_MODE STREQUAL "Debug")
set(SGX_COMMON_CFLAGS "${SGX_COMMON_CFLAGS} -O0 -g -DSGX_DEBUG -DDEBUG -UNDEBUG -UEDEBUG")
elseif(SGX_MODE STREQUAL "PreRelease")
set(SGX_COMMON_CFLAGS "${SGX_COMMON_CFLAGS} -O2 -UDEBUG -DNDEBUG -DEDEBUG")
elseif(SGX_MODE STREQUAL "Release")
set(SGX_COMMON_CFLAGS "${SGX_COMMON_CFLAGS} -O2 -UDEBUG -DNDEBUG -UEDEBUG")
else()
message(FATAL_ERROR "SGX_MODE ${SGX_MODE} is not Debug, PreRelease or Release.")
endif()
set(ENCLAVE_INC_DIRS "${SGX_INCLUDE_DIR}" "${SGX_TLIBC_INCLUDE_DIR}" "${SGX_LIBCXX_INCLUDE_DIR}")
set(ENCLAVE_C_FLAGS "${SGX_COMMON_CFLAGS} -nostdinc -fvisibility=hidden -fpie -fstack-protector-strong")
set(ENCLAVE_CXX_FLAGS "${ENCLAVE_C_FLAGS} -nostdinc++")
set(APP_INC_DIRS "${SGX_PATH}/include")
set(APP_C_FLAGS "${SGX_COMMON_CFLAGS} -fPIC -Wno-attributes ")
set(APP_CXX_FLAGS "${APP_C_FLAGS}")
function(_build_edl_obj edl edl_search_paths use_prefix)
set(oneValueArgs EXTRA_FLAGS)
set(multiValueArgs EXTRA_INCLUDE_DIRS)
cmake_parse_arguments(OBJ "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
get_filename_component(EDL_NAME ${edl} NAME_WE)
get_filename_component(EDL_ABSPATH ${edl} ABSOLUTE)
set(EDL_T_C "${CMAKE_CURRENT_BINARY_DIR}/${EDL_NAME}_t.c")
set(SEARCH_PATHS "")
foreach(path ${edl_search_paths})
get_filename_component(ABSPATH ${path} ABSOLUTE)
list(APPEND SEARCH_PATHS "${ABSPATH}")
endforeach()
list(APPEND SEARCH_PATHS "${SGX_PATH}/include")
string(REPLACE ";" ":" SEARCH_PATHS "${SEARCH_PATHS}")
if(${use_prefix})
set(USE_PREFIX "--use-prefix")
endif()
if(NOT "${OBJ_EXTRA_INCLUDE_DIRS}" STREQUAL "")
# message("OBJ_EXTRA_INCLUDE_DIRS: ${OBJ_EXTRA_INCLUDE_DIRS}")
endif()
add_custom_command(OUTPUT ${EDL_T_C}
COMMAND ${SGX_EDGER8R} ${USE_PREFIX} --trusted ${EDL_ABSPATH} --search-path ${SEARCH_PATHS}
MAIN_DEPENDENCY ${EDL_ABSPATH}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set( LIB_ENCLAVE_C_FLAGS "-std=c11 ${ENCLAVE_C_FLAGS} ${OBJ_EXTRA_FLAGS}")
add_library(${target}-edlobj OBJECT ${EDL_T_C})
set_target_properties(${target}-edlobj PROPERTIES COMPILE_FLAGS ${LIB_ENCLAVE_C_FLAGS})
target_include_directories(${target}-edlobj PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${ENCLAVE_INC_DIRS} ${OBJ_EXTRA_INCLUDE_DIRS})
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/${EDL_NAME}_t.h")
endfunction()
# build enclave shared library
function(add_enclave_library target)
set(optionArgs USE_PREFIX)
set(oneValueArgs EDL LDSCRIPT OPENSSL_LIBRARY_PATH WOLFSSL_LIBRARY_PATH)
set(multiValueArgs SRCS TRUSTED_LIBS EDL_SEARCH_PATHS EXTRA_INCLUDE_DIRS EXTRA_OPTIONS_FLAGS)
cmake_parse_arguments("SGX" "${optionArgs}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if("${SGX_EDL}" STREQUAL "")
message(FATAL_ERROR "${target}: SGX enclave edl file is not provided!")
endif()
if(NOT "${SGX_EXTRA_INCLUDE_DIRS}" STREQUAL "")
# message("SGX_EXTRA_INCLUDE_DIRS: ${SGX_EXTRA_INCLUDE_DIRS}")
endif()
if(NOT "${SGX_EXTRA_OPTIONS_FLAGS}" STREQUAL "")
# message("SGX_EXTRA_OPTIONS_FLAGS: ${SGX_EXTRA_OPTIONS_FLAGS}")
endif()
if("${SGX_EDL_SEARCH_PATHS}" STREQUAL "")
message("${target}: SGX enclave edl file search paths are not provided!")
endif()
if(NOT "${SGX_LDSCRIPT}" STREQUAL "")
# message("SGX_LDSCRIPT provided ${SGX_LDSCRIPT}")
get_filename_component(LDS_ABSPATH ${SGX_LDSCRIPT} ABSOLUTE)
set(LDSCRIPT_FLAG "-Wl,--version-script=${LDS_ABSPATH}")
endif()
if(NOT "${SGX_OPENSSL_LIBRARY_PATH}" STREQUAL "")
# message("SGX_OPENSSL_LIBRARY_PATH provided ${SGX_OPENSSL_LIBRARY_PATH}")
if(SGX_MODE STREQUAL "Debug")
set(OPENSSL_SGX_SSL_LIBRARY_NAME "sgx_tsgxssld")
set(OPENSSL_SGX_CRYPTO_LIBRARY_NAME "sgx_tsgxssl_cryptod")
else()
set(OPENSSL_SGX_SSL_LIBRARY_NAME "sgx_tsgxssl")
set(OPENSSL_SGX_CRYPTO_LIBRARY_NAME "sgx_tsgxssl_crypto")
endif()
set(OPENSSL_FLAGS "-L${SGX_OPENSSL_LIBRARY_PATH} -Wl,--whole-archive -l${OPENSSL_SGX_SSL_LIBRARY_NAME} -Wl,--no-whole-archive -l${OPENSSL_SGX_CRYPTO_LIBRARY_NAME}")
endif()
if(NOT "${SGX_WOLFSSL_LIBRARY_PATH}" STREQUAL "")
# message("SGX_WOLFSSL_LIBRARY_PATH provided ${SGX_WOLFSSL_LIBRARY_PATH}")
set(WOLFSSL_SGX_LIBRARY_NAME "wolfssl.sgx.static.lib")
set(WOLFSSL_FLAGS "-L${SGX_WOLFSSL_LIBRARY_PATH} -l${WOLFSSL_SGX_LIBRARY_NAME}")
# message("WOLFSSL_FLAGS provided ${WOLFSSL_FLAGS}")
endif()
_build_edl_obj(${SGX_EDL} "${SGX_EDL_SEARCH_PATHS}" ${SGX_USE_PREFIX} EXTRA_INCLUDE_DIRS ${SGX_EXTRA_INCLUDE_DIRS} EXTRA_FLAGS ${SGX_EXTRA_OPTIONS_FLAGS})
set( LIB_ENCLAVE_CPP_FLAGS "-std=c++11 ${ENCLAVE_CXX_FLAGS} ${SGX_EXTRA_OPTIONS_FLAGS}")
add_library(${target} SHARED ${SGX_SRCS} $<TARGET_OBJECTS:${target}-edlobj>)
set_target_properties(${target} PROPERTIES COMPILE_FLAGS ${LIB_ENCLAVE_CPP_FLAGS})
target_include_directories(${target} PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${ENCLAVE_INC_DIRS} ${SGX_EXTRA_INCLUDE_DIRS})
set(TLIB_LIST "")
foreach(TLIB ${SGX_TRUSTED_LIBS})
string(APPEND TLIB_LIST "$<TARGET_FILE:${TLIB}> ")
add_dependencies(${target} ${TLIB})
endforeach()
set(SGX_COMPILER_OPTIONS "${SGX_COMMON_CFLAGS} -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles \
${OPENSSL_FLAGS} ${WOLFSSL_FLAGS} \
-L${SGX_LIBRARY_PATH} -Wl,--whole-archive -l${SGX_TRTS_LIB} -Wl,--no-whole-archive \
-Wl,--start-group ${TLIB_LIST} -lsgx_tstdc -lsgx_tcxx -lsgx_pthread -lsgx_tkey_exchange -lsgx_tcrypto -l${SGX_TSVC_LIB} -Wl,--end-group \
-Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \
-Wl,-pie,-eenclave_entry -Wl,--export-dynamic \
${LDSCRIPT_FLAG} -Wl,--defsym,__ImageBase=0")
# message("add_enclave_library SGX_COMPILER_OPTIONS: ${SGX_COMPILER_OPTIONS}")
target_link_libraries(${target} ${SGX_COMPILER_OPTIONS})
endfunction()
# sign the enclave, according to configurations one-step or two-step signing will be performed.
# default one-step signing output enclave name is target.signed.so, change it with OUTPUT option.
function(enclave_sign target)
set(optionArgs IGNORE_INIT IGNORE_REL)
set(oneValueArgs KEY CONFIG OUTPUT)
cmake_parse_arguments("SGX" "${optionArgs}" "${oneValueArgs}" "" ${ARGN})
if("${SGX_CONFIG}" STREQUAL "")
message("${target}: SGX enclave config is not provided!")
else()
get_filename_component(CONFIG_ABSPATH ${SGX_CONFIG} ABSOLUTE)
endif()
if("${SGX_KEY}" STREQUAL "")
if (NOT SGX_HW OR NOT SGX_MODE STREQUAL "Release")
message(FATAL_ERROR "${target}: Private key used to sign enclave is not provided!")
endif()
else()
get_filename_component(KEY_ABSPATH ${SGX_KEY} ABSOLUTE)
endif()
if("${SGX_OUTPUT}" STREQUAL "")
set(OUTPUT_NAME "${target}.signed.so")
else()
set(OUTPUT_NAME ${SGX_OUTPUT})
endif()
if(${SGX_IGNORE_INIT})
set(IGN_INIT "-ignore-init-sec-error")
endif()
if(${SGX_IGNORE_REL})
set(IGN_REL "-ignore-rel-error")
endif()
if(SGX_HW AND SGX_MODE STREQUAL "Release")
add_custom_target(${target}-sign ALL
COMMAND ${SGX_ENCLAVE_SIGNER} gendata
$<$<NOT:$<STREQUAL:${SGX_CONFIG},>>:-config> $<$<NOT:$<STREQUAL:${SGX_CONFIG},>>:${CONFIG_ABSPATH}>
-enclave $<TARGET_FILE:${target}> -out $<TARGET_FILE_DIR:${target}>/${target}_hash.hex ${IGN_INIT} ${IGN_REL}
COMMAND ${CMAKE_COMMAND} -E cmake_echo_color
--cyan "SGX production enclave first step signing finished, \
use ${CMAKE_CURRENT_BINARY_DIR}/${target}_hash.hex for second step"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
else()
add_custom_target(${target}-sign ALL ${SGX_ENCLAVE_SIGNER} sign -key ${KEY_ABSPATH}
$<$<NOT:$<STREQUAL:${SGX_CONFIG},>>:-config> $<$<NOT:$<STREQUAL:${SGX_CONFIG},>>:${CONFIG_ABSPATH}>
-enclave $<TARGET_FILE:${target}>
-out $<TARGET_FILE_DIR:${target}>/${OUTPUT_NAME}
${IGN_INIT} ${IGN_REL}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endif()
set(CLEAN_FILES "$<TARGET_FILE_DIR:${target}>/${OUTPUT_NAME};$<TARGET_FILE_DIR:${target}>/${target}_hash.hex")
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${CLEAN_FILES}")
endfunction()
function(add_untrusted_executable target)
set(optionArgs USE_PREFIX)
set(oneValueArgs OPENSSL_LIBRARY_PATH)
set(multiValueArgs SRCS EDL EDL_SEARCH_PATHS EXTRA_BUILD_OBJECTS EXTRA_INCLUDE_DIRS EXTRA_OPTIONS_FLAGS)
cmake_parse_arguments("SGX" "${optionArgs}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if("${SGX_EDL}" STREQUAL "")
message(FATAL_ERROR "${target}: SGX enclave edl file is not provided!")
endif()
if("${SGX_EDL_SEARCH_PATHS}" STREQUAL "")
message("${target}: SGX enclave edl file search paths are not provided!")
endif()
if(NOT "${SGX_OPENSSL_LIBRARY_PATH}" STREQUAL "")
message("SGX_OPENSSL_LIBRARY_PATH provided ${SGX_OPENSSL_LIBRARY_PATH}")
if(SGX_MODE STREQUAL "Debug")
set(OPENSSL_SGX_SSL_LIBRARY_NAME "sgx_usgxssld")
else()
set(OPENSSL_SGX_SSL_LIBRARY_NAME "sgx_usgxssl")
endif()
set(OPENSSL_FLAGS "-L${SGX_OPENSSL_LIBRARY_PATH} -Wl,--whole-archive -l${OPENSSL_SGX_SSL_LIBRARY_NAME} ")
message("OPENSSL_FLAGS provided ${OPENSSL_FLAGS}")
endif()
if(NOT "${SGX_EXTRA_INCLUDE_DIRS}" STREQUAL "")
message("SGX_EXTRA_INCLUDE_DIRS: ${SGX_EXTRA_INCLUDE_DIRS}")
endif()
if(NOT "${SGX_EXTRA_OPTIONS_FLAGS}" STREQUAL "")
message("SGX_EXTRA_OPTIONS_FLAGS: ${SGX_EXTRA_OPTIONS_FLAGS}")
endif()
set(EDL_U_SRCS "")
foreach(EDL ${SGX_EDL})
get_filename_component(EDL_NAME ${EDL} NAME_WE)
get_filename_component(EDL_ABSPATH ${EDL} ABSOLUTE)
set(EDL_U_C "${CMAKE_CURRENT_BINARY_DIR}/${EDL_NAME}_u.c")
set(EDL_U_H "${CMAKE_CURRENT_BINARY_DIR}/${EDL_NAME}_u.h")
set(SEARCH_PATHS "")
foreach(path ${SGX_EDL_SEARCH_PATHS})
get_filename_component(ABSPATH ${path} ABSOLUTE)
list(APPEND SEARCH_PATHS "${ABSPATH}")
endforeach()
list(APPEND SEARCH_PATHS "${SGX_PATH}/include")
string(REPLACE ";" ":" SEARCH_PATHS "${SEARCH_PATHS}")
if(${SGX_USE_PREFIX})
set(USE_PREFIX "--use-prefix")
endif()
add_custom_command(OUTPUT ${EDL_U_C}
COMMAND ${SGX_EDGER8R} ${USE_PREFIX} --untrusted ${EDL_ABSPATH} --search-path ${SEARCH_PATHS}
MAIN_DEPENDENCY ${EDL_ABSPATH}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
list(APPEND EDL_U_SRCS ${EDL_U_C})
list(APPEND EDL_U_HDRS ${EDL_U_H})
endforeach()
set(EXTRA_BUILD_OBJECTS "")
foreach(EBOBJ ${SGX_EXTRA_BUILD_OBJECTS})
get_filename_component(EBOBJ_NAME ${EBOBJ} NAME_WE)
get_filename_component(EBOBJ_ABSPATH ${EBOBJ} ABSOLUTE)
set(EBOBJ_NAME "${EBOBJ_NAME}-ext-obj")
add_library(${EBOBJ_NAME} OBJECT IMPORTED GLOBAL)
set_target_properties(${EBOBJ_NAME} PROPERTIES IMPORTED_OBJECTS ${EBOBJ_ABSPATH})
list(APPEND EXTRA_BUILD_OBJECTS ${EBOBJ_NAME})
endforeach()
message("EXTRA_BUILD_OBJECTS ====== ${EXTRA_BUILD_OBJECTS}")
add_executable(${target} ${SGX_SRCS} ${EDL_U_SRCS} $<TARGET_OBJECTS:${EXTRA_BUILD_OBJECTS}>)
set( U_EXEC_CPP_FLAGS "-std=c++17 ${APP_CXX_FLAGS} ${SGX_EXTRA_OPTIONS_FLAGS} ")
message("U_EXEC_CPP_FLAGS : ${U_EXEC_CPP_FLAGS}")
set_target_properties(${target} PROPERTIES COMPILE_FLAGS ${U_EXEC_CPP_FLAGS})
target_include_directories(${target} PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${SGX_EXTRA_INCLUDE_DIRS} ${APP_INC_DIRS})
target_link_libraries(${target} "${SGX_COMMON_CFLAGS} \
${OPENSSL_FLAGS} \
-L${SGX_LIBRARY_PATH} \
-l${SGX_URTS_LIB} \
-l${SGX_USVC_LIB} \
-lcrypto -lwolfssl -lpthread")
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${EDL_U_HDRS})
endfunction()
else(SGX_FOUND)
message(WARNING "Intel SGX SDK not found!")
if(SGX_FIND_REQUIRED)
message(FATAL_ERROR "Could NOT find Intel SGX SDK!")
endif()
endif(SGX_FOUND)
that was called as
add_enclave_library(Enclave
SRCS ${T_SRCS} ${T_SRCS_Crypto} ${T_SRCS_HTTPS_Handlers} ${T_SRCS_DataUtils} ${T_SRCS_Agg}
EDL Enclave/Enclave.edl
EDL_SEARCH_PATHS ${EDL_SEARCH_PATHS}
USE_PREFIX
LDSCRIPT ${LDS}
OPENSSL_LIBRARY_PATH ${SGX_OPENSSL_LIB_DIR}
WOLFSSL_LIBRARY_PATH ${SGX_WOLFSSL_LIB_DIR}
EXTRA_INCLUDE_DIRS ${T_INCLUDE_DIRS}
EXTRA_OPTIONS_FLAGS ${WOLFSSL_ENCLAVE_EXTRA_FLAGS})
enclave_sign(Enclave KEY Enclave/Enclave_private.pem CONFIG Enclave/Enclave.config.xml)
set(WOLFSSL_APP_EXTRA_FLAGS "${WOLFSSL_C_EXTRA_FLAGS} -DWOLFSSL_SHA512 -DOPENSSL_EXTRA -DOPENSSL_ALL -DLWS_HAVE_SSL_CTX_load_verify_file \
-DLWS_WITH_SOCKS5 -DLWS_WITH_DETAILED_LATENCY -DLWS_WITH_SPAWN -DLWS_WITH_RANGES -DLWS_WITH_ACCESS_LOG -DCPPHTTPLIB_OPENSSL_SUPPORT -DHAVE_SUPPORTED_CURVES")
add_untrusted_executable(cscore SRCS ${U_SRCS} ${U_SRCS_Exchanges}
EDL Enclave/Enclave.edl
EDL_SEARCH_PATHS ${EDL_SEARCH_PATHS}
OPENSSL_LIBRARY_PATH ${SGX_OPENSSL_LIB_DIR}
EXTRA_INCLUDE_DIRS ${U_INCLUDE_DIRS}
EXTRA_OPTIONS_FLAGS ${WOLFSSL_APP_EXTRA_FLAGS}
EXTRA_BUILD_OBJECTS App/kdb/c.o
)
add_dependencies(cscore Enclave-sign)
Any help is appreciated.

cmake_configuration_types and 3rd party libraries

I am trying to create a custom cmake_configuration_type using the method as described here
The issue I am facing is the correct linking of 3rd party libraries. E.g., when I create a custom configuration the executable is not linking correctly to third party libraries for the Final configuration. Some libraries linked to are in release mode and others in debug. Would anybody point me to whether CMake gives a way to resolve this issue ?
Here is the code as requested :
CMakeLists.txt :
cmake_minimum_required(VERSION 3.5)
project(DisplayImage)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake)
# Add configurations
include(SetupConfiguration)
# if (WIN32)
# # Restrict the generated configuration to be what we configured above.
# # No point creating project files for build types that will not compile.
# # Note: it's set to FORCE so that both CMAKE_BUILD_TYPE and CMAKE_CONFIGURATION_TYPES match up.
# set(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE} CACHE STRING "Build configurations to generate." FORCE)
# mark_as_advanced(CMAKE_CONFIGURATION_TYPES)
# endif()
message("Generated with config types: ${CMAKE_CONFIGURATION_TYPES}")
######################################################################
# Choose C++ standard. Currently 11, as we try to support VS2013.
######################################################################
set(mp_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS 0)
set(CMAKE_CXX_STANDARD ${mp_CXX_STANDARD})
set(CMAKE_CXX_STANDARD_REQUIRED ON)
######################################################################
# Add Optional Requirements
######################################################################
if(WIN32)
set(_library_sub_dir "bin")
else()
set(_library_sub_dir "lib")
endif()
find_package( OpenCV REQUIRED )
add_executable(DisplayImage main.cpp)
target_link_libraries(DisplayImage ${OpenCV_LIBS})
if (CMAKE_CONFIGURATION_TYPES MATCHES Release)
set_property(TARGET DisplayImage PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Release>:Release>")
set_target_properties(DisplayImage PROPERTIES RELEASE_POSTFIX "R")
elseif(CMAKE_CONFIGURATION_TYPES MATCHES Final)
set_property(TARGET DisplayImage PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Release>:Release>")
set_target_properties(DisplayImage PROPERTIES RELEASE_POSTFIX "F")
target_compile_definitions(DisplayImage PUBLIC -DFINAL)
elseif(CMAKE_CONFIGURATION_TYPES MATCHES Debug)
set_property(TARGET DisplayImage PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug")
set_target_properties(DisplayImage PROPERTIES DEBUG_POSTFIX "D")
endif()
The main.cpp
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv )
{
if ( argc != 2 )
{
printf("usage: DisplayImage.out <Image_Path>\n");
return -1;
}
Mat image;
image = imread( argv[1], 1 );
if ( !image.data )
{
printf("No image data \n");
return -1;
}
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", image);
waitKey(0);
return 0;
}
In the CMake folder in the project the following two files mpSetupMSVCRuntime.cmake
if(MSVC)
set(variables
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELEASE
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
)
add_definitions(/bigobj)
add_definitions(/MP)
endif()
and SetupConfiguration.cmake
if(NOT SET_UP_CONFIGURATIONS_DONE)
set(SET_UP_CONFIGURATIONS_DONE TRUE)
get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(isMultiConfig)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release;Final" CACHE STRING "" FORCE)
else()
if(NOT CMAKE_BUILD_TYPE)
message("Defaulting to release build.")
set(CMAKE_BUILD_TYPE Release CACHE STRING "" FORCE)
endif()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY HELPTSTRING "Choose the type of build")
#set the valid options for cmake-gui drop-down list
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug;Release;Final")
endif()
# now set up the Final configuration
set(CMAKE_C_FLAGS_FINAL "${CMAKE_C_FLAGS_RELEASE}" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_FINAL "${CMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_FINAL "${CMAKE_EXE_LINKER_FLAGS_RELEASE}" CACHE STRING "" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_FINAL "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}" CACHE STRING "" FORCE)
set(CMAKE_MODULE_LINKER_FLAGS_FINAL "${CMAKE_MODULE_LINKER_FLAGS_RELEASE}" CACHE STRING "" FORCE)
endif()
Thanks for your help
So finally I was able to solve this with some changes to the CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(DisplayImage)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake)
# Add configurations
include(SetupConfiguration)
# if (WIN32)
# # Restrict the generated configuration to be what we configured above.
# # No point creating project files for build types that will not compile.
# # Note: it's set to FORCE so that both CMAKE_BUILD_TYPE and CMAKE_CONFIGURATION_TYPES match up.
# set(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE} CACHE STRING "Build configurations to generate." FORCE)
# mark_as_advanced(CMAKE_CONFIGURATION_TYPES)
# endif()
message("Generated with config types: ${CMAKE_CONFIGURATION_TYPES}")
######################################################################
# Choose C++ standard. Currently 11, as we try to support VS2013.
######################################################################
set(mp_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS 0)
set(CMAKE_CXX_STANDARD ${mp_CXX_STANDARD})
set(CMAKE_CXX_STANDARD_REQUIRED ON)
######################################################################
# Add Optional Requirements
######################################################################
if(WIN32)
set(_library_sub_dir "bin")
else()
set(_library_sub_dir "lib")
endif()
find_package( OpenCV REQUIRED )
foreach(_cvlib ${OpenCV_LIBS})
set_target_properties(${_cvlib} PROPERTIES MAP_IMPORTED_CONFIG_FINAL "RELEASE")
endforeach()
add_executable(DisplayImage main.cpp)
if (CMAKE_CONFIGURATION_TYPES MATCHES Release)
target_link_libraries(DisplayImage ${OpenCV_LIBS})
set_property(TARGET DisplayImage PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Release>:Release>")
set_target_properties(DisplayImage PROPERTIES RELEASE_POSTFIX "R")
elseif(CMAKE_CONFIGURATION_TYPES MATCHES Final)
target_link_libraries(DisplayImage ${OpenCV_LIBS})
set_property(TARGET DisplayImage PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Final>:Final>")
set_target_properties(DisplayImage PROPERTIES RELEASE_POSTFIX "F")
add_definitions(-DFINAL)
elseif(CMAKE_CONFIGURATION_TYPES MATCHES Debug)
target_link_libraries(DisplayImage ${OpenCV_LIBS})
set_property(TARGET DisplayImage PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug")
set_target_properties(DisplayImage PROPERTIES DEBUG_POSTFIX "D")
endif()
The key was to use the MAP_IMPORTED_CONFIG_<CONFIG> feature of CMake.

Why No ops registered when I try to load frozen model in Android NDK?

I want to use c++ tensorflow API through ndk and cmake, I can create the library but when I load a frozen model a lot of errors like this when I try to load graph:
E/native: op_kernel.cc:1148 OpKernel ('op: "PopulationCount"
device_type: "CPU" constraint { name: "T" allowed_values { list {
type: DT_INT32 } } }') for unknown op: PopulationCount
So I understand that my library does not support the operations.
Do I need to add another library to support these operations?
I based my Cmake script on this Cmakelist and
I used the build_android_all.sh script to build the dependencies for armeabi-v7a.
This is how my cmake script looks like:
cmake_minimum_required(VERSION 3.4.1)
include(ExternalProject)
SET(PROJECT_NAME tf_native_lib)
SET(OpenCV_FOUND true )
SET(PREBUILT_DIR ${TENSORFLOW_ROOT_DIR}/tensorflow/contrib/makefile/gen)
SET(TARGET_NSYNC_LIB ${TENSORFLOW_ROOT_DIR}/tensorflow/contrib/makefile /downloads/nsync/builds/${ANDROID_ABI}.android.c++11)
FIND_PACKAGE(OpenCV REQUIRED)
add_library( # Sets the name of the library.
${PROJECT_NAME}
SHARED
src/main/cpp/native-lib.h
src/main/cpp/native-lib.cpp
src/main/cpp/TensorflowInferenceHandler.h
src/main/cpp/TensorflowInferenceHandler.cpp
)
add_library(lib_proto STATIC IMPORTED )
set_target_properties(lib_proto PROPERTIES IMPORTED_LOCATION
${PREBUILT_DIR}/protobuf_android/${ANDROID_ABI}/lib/libprotobuf.a)
add_library(lib_nsync STATIC IMPORTED )
set_target_properties(lib_nsync PROPERTIES IMPORTED_LOCATION
${TARGET_NSYNC_LIB}/libnsync.a)
add_library(lib_tf STATIC IMPORTED )
set_target_properties(lib_tf PROPERTIES IMPORTED_LOCATION
${PREBUILT_DIR}/lib/android_${ANDROID_ABI}/libtensorflow-core.a)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DIS_SLIM_BUILD \
-std=c++11 -fno-rtti -fno-exceptions \
-O2 -Wno-narrowing -fomit-frame-pointer \
-mfpu=neon -mfloat-abi=softfp -fPIE -fPIC \
-ftemplate-depth=900 \
-DGOOGLE_PROTOBUF_NO_RTTI \
-DGOOGLE_PROTOBUF_NO_STATIC_INITIALIZER")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} \
-Wl,--allow-multiple-definition \
-Wl,--whole-archive \
-fPIE -pie -v")
# MESSAGE("tensorflow lib dir ${TENSORFLOW_LIB_DIR}")
target_link_libraries( # Specifies the target library.
${PROJECT_NAME}
${OpenCV_LIBS}
android
dl
log
m
z
jnigraphics
lib_tf
lib_proto
lib_nsync)
include_directories(
${OPENCV_INCLUDE_DIRS}
${PREBUILT_DIR}/proto
${PREBUILT_DIR}/protobuf_android/${ANDROID_ABI}/include
${PREBUILT_DIR}/nsync/public
${TENSORFLOW_ROOT_DIR}/tensorflow/contrib/makefile/downloads/eigen
${TENSORFLOW_ROOT_DIR}/bazel-tensorflow/external/nsync/public
${TENSORFLOW_ROOT_DIR}/bazel-genfiles
${TENSORFLOW_ROOT_DIR}
../../../cpp_utils)
If this is not possible, where are the sources to link the tensorflow_inference.so with my Jni Sources?
Thanks in advance.
Unai.
The PopulationCount and few other Ops are declared in tensorflow/core/ops/bitwise_ops.cc. Add that file to the end of /tensorflow/contrib/makefile/tf_op_files.txt. Then recompile the Tensorflow. That is what worked for me.

How to build a "file copy" RPM using cmake?

I want to build a demo rpm package which copies one file to the target system and executes some pre and post script.
I managed to create a package. When I run the package on the target system I got the e warning "warning: package xxx intend for yyy plattform". But no file was copied.
Any ideas?
After goes my code/project:
Project tree:
myRpm/CMakeLists.txt
myRpm/install.txt
myRpm/post.py
myRpm/post.sh
myRpm/pre.py
myRpm/pre.sh
CMakeLists:
cmake_minimum_required (VERSION 2.8)
if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
INCLUDE(InstallRequiredSystemLibraries)
set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1)
set(CPACK_PACKAGE_NAME "my test")
set(CPACK_PACKAGE_VENDOR "tets")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "fake rpm")
set(CPACK_PACKAGE_VERSION "6.6.6")
set(CPACK_PACKAGE_VERSION_MAJOR "6")
set(CPACK_PACKAGE_VERSION_MINOR "6")
set(CPACK_PACKAGE_VERSION_PATCH "6")
set(targetDestDir "myDir")
set(CPACK_GENERATOR "RPM")
install(
FILES "${CMAKE_CURRENT_SOURCE_DIR}/install.txt" "${CMAKE_CURRENT_SOURCE_DIR}/pre.py" "${CMAKE_CURRENT_SOURCE_DIR}/post.py"
DESTINATION "${targetDestDir}"
)
set(CPACK_RPM_PRE_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/pre.sh")
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/post.sh")
include(CPack)
endif()
The value of CPACK_RPM_PACKAGE_ARCHITECTURE is important when building RPMs for other systems/distros.
The following code should work:
cmake_minimum_required (VERSION 2.8)
if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
INCLUDE(InstallRequiredSystemLibraries)
set(CMAKE_INSTALL_TMPDIR /tmp CACHE PATH "Output dir for tmp")
set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1)
set(CPACK_PACKAGE_NAME "mytest")
set(CPACK_PACKAGE_VENDOR "tets")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "fake rpm")
set(CPACK_PACKAGE_VERSION "6.6.6")
set(CPACK_PACKAGE_VERSION_MAJOR "6")
set(CPACK_PACKAGE_VERSION_MINOR "6")
set(CPACK_PACKAGE_VERSION_PATCH "6")
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_PACKAGE_ARCHITECTURE "noarch")
set(targetDestDir ${CMAKE_INSTALL_TMPDIR})
install(
FILES "${CMAKE_CURRENT_SOURCE_DIR}/install.txt" "${CMAKE_CURRENT_SOURCE_DIR}/post.py"
DESTINATION "${targetDestDir}"
)
set(CPACK_RPM_PRE_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/pre.sh")
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/post.sh")
include(CPack)
endif()
Note:
the pre.sh and post.sh are in the root dir of the sources. In the post.sh the post.py is called.