- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How do I force CMAKE to use dpcpp to link and not C++ ? I am trying to use the OpenCV .so libs. How do I force -shared-libgcc? Do I even need -shared-libgcc?
I've ported over a small cuda program with a kernel.cu from a windows VS project to Linux Ubuntu 20.04 using DPCT (all on my local machine). The dpct translator had a few minor glitch that I was able to fix by hand. I am having difficulty coercing MAKE to use DPC++ to link with the OpenCV .so. In build/CMakeFiles/My_Image.dir/link.txt I see the failing link call generated by CMAKE (Note "C++" and the lack of "-shared-libgcc"
/usr/bin/c++ CMakeFiles/My_Image.dir/dpct_output/ImageProcessing.cpp.o
CMakeFiles/My_Image.dir/dpct_output/kernel.dp.cpp.o
-o ../dpct_output/My_Image
-L/usr/local/lib
-Wl,-rpath,/usr/local/lib
-lopencv_core -lopencv_imgcodecs
If I open a terminal and use the following command by hand to build the bin, I am able to successfully link and build the program:
# dpcpp CMakeFiles/My_Image.dir/dpct_output/ImageProcessing.cpp.o
CMakeFiles/My_Image.dir/dpct_output/kernel.dp.cpp.o
-o ../dpct_output/My_Image
-L/usr/local/lib
-Wl,-rpath,/usr/local/lib
-shared-libgcc /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_imgcodecs.so
My CMakeList.txt file is:
cmake_minimum_required(VERSION 3.16)
include(FindPkgConfig)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_CXX_COMPILER "dpcpp") #dpcpp/sycl
set(CMAKE_LINKER "dpcpp")
set(CMAKE_CXX_C )
set(CMAKE_LINKER_FLAGS -shared-libgcc)
set(CMAKE_CXX_STANDARD 17)
set(MY_SHARED_LIBS /usr/local/lib)
add_compile_options("-shared-libgcc")
add_link_options("-shared-libgcc")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lopencv_core -lopencv_imgcodecs")
# this will hand link the project (when called from Foo/build):
#
# dpcpp CMakeFiles/My_Image.dir/dpct_output/ImageProcessing.cpp.o CMakeFiles/My_Image.dir/dpct_output/kernel.dp.cpp.o
# -o ../dpct_output/My_Image
# -L/usr/local/lib
# -Wl,
# -rpath,/usr/local/lib
# -shared-libgcc /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_imgcodecs.so
project(My_Image)
set(DPCT_OUT "dpct_output") #working dir, todo: move code to amindir, change path to main dir
set(SYCL "/opt/intel/oneapi/compiler/2021.3.0/linux") # will need to be set locally for now, @todo
include_directories("${SYCL}/include/sycl")
link_directories("${SYCL}/lib")
link_directories(/usr/local/lib)
add_executable(My_Image ${DPCT_OUT}/ImageProcessing.cpp "${DPCT_OUT}/kernel.dp.cpp")
set_target_properties(My_Image PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/${DPCT_OUT}")
find_package(OpenCV REQUIRED )
if(OpenCV_FOUND)
message(STATUS "OpenCV library status:")
message(STATUS " config: ${OpenCV_DIR}")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libs: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
add_library(OpenCV SHARED IMPORTED)
set_target_properties(OpenCV PROPERTIES IMPORTED_LOCATION ${MY_SHARED_LIBS})
set_target_properties(OpenCV PROPERTIES INTERFACE_LINK_LIBRARIES libopencv_imgcodecs.so) #PROPERTIES IMPORTED_LOCATION /usr/local/lib/libopencv_core.so)
set_target_properties(OpenCV PROPERTIES INTERFACE_LINK_LIBRARIES libopencv_core.so )
target_link_libraries(My_Image SHARED IMPORTED libopencv_core.so) LINK_INTERFACE_LIBRARIES
target_link_libraries(My_Image SHARED IMPORTED libopencv_imgcodecs.so)
message(STATUS "set_target_properties(OpenCV = " get_target_properties(OpenCV) )
include_directories(${OpenCV_INCLUDE_DIRS})
else()
message(STATUS "OpenCV_DIR Not Set")
endif()
#debug
message(STATUS "Final values:")
message(STATUS "CMAKE_CURRENT_LIST_DIR=${CMAKE_CURRENT_LIST_DIR}")
message(STATUS "MY_SHARED_LIBS = ${MY_SHARED_LIBS}")
message(STATUS "CMAKE_CXX_FLAGS= ${CMAKE_CXX_FLAGS}")
add_custom_target( dpct
COMMAND dpct --in-root=${CMAKE_CURRENT_LIST_DIR}
--out-root=${CMAKE_CURRENT_LIST_DIR}/${DPCT_OUT}/
--extra-arg="-I${SYCL}"
--extra-arg="-I${OpenCV_INCLUDE_DIRS}"
--extra-arg="-std=c++17"
--enable-ctad
${CMAKE_CURRENT_LIST_DIR}/kernel.cu
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/kernel.cu
)
$ make
-- OpenCV library status:
-- config: /usr/local/lib/cmake/opencv4
-- version: 4.5.3
-- libs: opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_gapi;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_stitching;opencv_video;opencv_videoio
-- include path: /usr/local/include/opencv4
-- set_target_properties(OpenCV = get_target_properties(OpenCV)
-- Final values:
-- CMAKE_CURRENT_LIST_DIR=/home/Foo/wip/Bar
-- MY_SHARED_LIBS = /usr/local/lib
-- CMAKE_CXX_FLAGS= -std=c++11 -lopencv_core -lopencv_imgcodecs
-- Configuring done
-- Generating done
-- Build files have been written to: /home/Foo/wip/Bar/build
Scanning dependencies of target My_Image
CMake Error: Directory Information file not found
[ 33%] Linking CXX executable ../dpct_output/My_Image
/usr/bin/ld: CMakeFiles/My_Image.dir/dpct_output/ImageProcessing.cpp.o: in function `dpct::{lambda(cl::sycl::exception_list)#1}::operator()(cl::sycl::exception_list) const':
ImageProcessing.cpp:(.text+0xc2): undefined reference to `cl::sycl::exception_list::begin() const'
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thanks for reaching out to us.
>> cmake_minimum_required(VERSION 3.16)
Could you please try with CMake 3.20.0 version as it is the Cmake supported version for oneAPI compilers and may be this is the reason why it is getting linked successfully by giving the command manually in terminal.
Please refer the following link for more details
>> How do I force CMAKE to use dpcpp to link
The below link gives more details regarding the usage of CMake with dpcpp compiler on linux.
If the issue still persists, please provide us a small reproducer (steps to reproduce it if any) so that we can work on it from our end.
Regards,
Vidya.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Reminder:
Is your issue resolved ? If not please provide us the above mentioned details.
Regards,
Vidya.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
We assume that your issue is resolved.
If you need any additional information, please submit a new question as this thread will no longer be monitored.
Have a good day!
Regards,
Vidya.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page