cmake多重定义问题

时间:2018-03-31 02:29:49

标签: c++ opencv cmake

我只是使用cmake来编译cbb,openCv的c ++代码,并且我在运行make命令后出错了

  /home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(pngerror.c.o): In function `png_warning':
pngerror.c:(.text.png_warning+0x0): multiple definition of `png_warning'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-pngerror.o):(.text+0x2f0): first defined here
/home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(pngerror.c.o): In function `png_chunk_warning':
pngerror.c:(.text.png_chunk_warning+0x0): multiple definition of `png_chunk_warning'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-pngerror.o):(.text+0x4b0): first defined here
/home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(pngerror.c.o): In function `png_error':
pngerror.c:(.text.png_error+0x0): multiple definition of `png_error'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-pngerror.o):(.text+0xf0): first defined here
/home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(pngerror.c.o): In function `png_chunk_error':
pngerror.c:(.text.png_chunk_error+0x0): multiple definition of `png_chunk_error'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-pngerror.o):(.text+0x470): first defined here
/home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(pngerror.c.o): In function `png_set_error_fn':
pngerror.c:(.text.png_set_error_fn+0x0): multiple definition of `png_set_error_fn'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-pngerror.o):(.text+0x510): first defined here
/home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(pngerror.c.o): In function `png_get_error_ptr':
pngerror.c:(.text.png_get_error_ptr+0x0): multiple definition of `png_get_error_ptr'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-pngerror.o):(.text+0x530): first defined here
/home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(png.c.o): In function `png_zalloc':
png.c:(.text.png_zalloc+0x0): multiple definition of `png_zalloc'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-png.o):(.text+0x110): first defined here
/home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(png.c.o): In function `png_zfree':
png.c:(.text.png_zfree+0x0): multiple definition of `png_zfree'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-png.o):(.text+0x190): first defined here
/home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(png.c.o): In function `png_set_sig_bytes':
png.c:(.text.png_set_sig_bytes+0x0): multiple definition of `png_set_sig_bytes'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-png.o):(.text+0x0): first defined here
/home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(png.c.o): In function `png_sig_cmp':
png.c:(.text.png_sig_cmp+0x0): multiple definition of `png_sig_cmp'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-png.o):(.text+0x40): first defined here
/home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(png.c.o): In function `png_reset_crc':
png.c:(.text.png_reset_crc+0x0): multiple definition of `png_reset_crc'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-png.o):(.text+0x1a0): first defined here
/home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(png.c.o): In function `png_calculate_crc':
png.c:(.text.png_calculate_crc+0x0): multiple definition of `png_calculate_crc'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-png.o):(.text+0x1c0): first defined here
/home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(png.c.o): In function `png_create_info_struct':
png.c:(.text.png_create_info_struct+0x0): multiple definition of `png_create_info_struct'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-png.o):(.text+0x270): first defined here
/home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(png.c.o): In function `png_destroy_info_struct':
png.c:(.text.png_destroy_info_struct+0x0): multiple definition of `png_destroy_info_struct'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-png.o):(.text+0x920): first defined here
/home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(png.c.o): In function `png_info_init_3':
png.c:(.text.png_info_init_3+0x0): multiple definition of `png_info_init_3'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-png.o):(.text+0x210): first defined here
/home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(png.c.o): In function `png_data_freer':
png.c:(.text.png_data_freer+0x0): multiple definition of `png_data_freer'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-png.o):(.text+0x310): first defined here
/home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(png.c.o): In function `png_free_data':
png.c:(.text.png_free_data+0x0): multiple definition of `png_free_data'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng.a(libpng12_la-png.o):(.text+0x350): first defined here
/home/medo/opencv/share/OpenCV/3rdparty/lib/liblibpng.a(png.c.o): In function `png_get_io_ptr':

从错误中看起来另一个共享库已被链接并产生了这些问题,但我想使用opencv库所有库静态,这是我尝试做的事情

现在我的cmake

cmake_minimum_required (VERSION 2.8)
project (wordxx)


set(TBB_BUILD_STATIC ON CACHE BOOL " " FORCE)
set(TBB_BUILD_SHARED OFF CACHE BOOL " " FORCE)
set(TBB_BUILD_TBBMALLOC OFF CACHE BOOL " " FORCE)
set(TBB_BUILD_TBBMALLOC_PROXY OFF CACHE BOOL " " FORCE)
set(TBB_BUILD_TESTS OFF CACHE BOOL " " FORCE)






set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
set(CMAKE_CONFIG_DIR /home/medo/xx/wordxx)
set(CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_CONFIG_DIR}")




add_definitions(-DCONFIG_DIR="${CONFIG_DIR}")

find_package( OpenCV REQUIRED )




MESSAGE("  OpenCV information:") 
MESSAGE("  OpenCV_INCLUDE_DIRS: ${OpenCV_INCLUDE_DIRS}") 
MESSAGE("  OpenCV_LIBRARIES: ${OpenCV_LIBRARIES}") 
MESSAGE("  OpenCV_LIBRARY_DIRS: ${OpenCV_LIBRARY_DIRS}") 
include_directories( ${OpenCV_INCLUDE_DIRS} )


add_definitions( -DBOOST_ALL_NO_LIB )
set(Boost_USE_STATIC_LIBS ON)
unset(Boost_INCLUDE_DIR CACHE)
unset(Boost_LIBRARY_DIRS CACHE)
set(Boost_INCLUDE_DIR /home/medo/build/boost)
set(Boost_LIBRARY_DIRS /home/medo/build/boost/stage/lib)
set(BOOST_ROOT /home/medo/build/boost)




find_package( Boost 1.5.9 REQUIRED COMPONENTS  filesystem system)  
MESSAGE("Boost information:") 
MESSAGE("  Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}") 
MESSAGE("  Boost_LIBRARIES: ${Boost_LIBRARIES}") 
MESSAGE("  Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}") 




if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
    #execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
    if (GCC_VERSION VERSION_LESS 4.7)
        #set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -msse -msse2 -msse3")
    else ()
        #set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -msse -msse2 -msse3")
    endif ()
else ()
    #set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -msse -msse2 -msse3")
endif ()

# Boost
if(WIN32)
    include_directories(lib/boost)
    include_directories(lib/boost/boost)
    link_directories( ${PROJECT_SOURCE_DIR}/lib/boost/lib )
else()
     INCLUDE_DIRECTORIES(${BOOST_INCLUDE_DIR})

endif()


set(CMAKE_EXE_LINKER_FLAGS "-lboost_thread -lpthread ")


#Set Linker flags
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")



set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -msse -msse2 -msse3")


include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})





add_subdirectory(lib/tbb)
set_property(TARGET tbb_static tbb_def_files PROPERTY FOLDER "dependencies")
include_directories(tbb_static PUBLIC lib/tbb/include)



# dlib
include_directories(lib/dlib/include)




# dlib library
add_subdirectory(lib/dlib)

ADD_EXECUTABLE(wordxx Source.cpp) 




target_link_libraries(wordxx dlib   ${OpenCV_LIBS} ${Boost_LIBRARIES} )
TARGET_LINK_LIBRARIES (wordxx ${tbb_static_LIBS})  
target_link_libraries(wordxx PUBLIC tbb_static)

现在当我删除

  

设置(CMAKE_EXE_LINKER_FLAGS" -static-libgcc -static-libstdc ++ -static")

它的工作但是一些openCv库没有链接静态像我在运行我的程序后得到的这个错误./wordxx

  

wordxx:加载共享库时出错:libjpeg.so.8:无法打开共享对象文件:没有这样的文件或目录

opencv中的这个库我必须使用

  

设置(CMAKE_EXE_LINKER_FLAGS" -static-libgcc -static-libstdc ++ -static")

要避免此问题,但这会使multiple definition发出任何想法

0 个答案:

没有答案