I tried to setup a three layer convolution generator pipeline. Build is failing at linking step.
Example followed in apps/wavelet
running make
in build directory results in the following error:
[ 87%] Linking CXX executable conv-3
CMakeFiles/conv-3.dir/main.cpp.o: In function `Halide::Internal::check_introspection(void const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)':
main.cpp:(.text+0xa6): undefined reference to `Halide::Internal::Introspection::get_source_location[abi:cxx11]()'
main.cpp:(.text+0xc3): undefined reference to `Halide::Internal::Introspection::get_variable_name(void const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
CMakeFiles/conv-3.dir/main.cpp.o: In function `HalideIntrospectionCanary::(anonymous namespace)::TestCompilationUnit::TestCompilationUnit()':
main.cpp:(.text+0xa6a): undefined reference to `Halide::Internal::Introspection::test_compilation_unit(bool (*)(bool (*)(void const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)), bool (*)(void
const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&), void (*)())'
./genfiles/halide_rt_host/halide_rt_host.a(halide_rt_host.a.o): In function `halide_spawn_thread':
posix_allocator.cpp:(.text.halide_spawn_thread+0x3d): undefined reference to `pthread_create'
./genfiles/halide_rt_host/halide_rt_host.a(halide_rt_host.a.o): In function `halide_join_thread':
posix_allocator.cpp:(.text.halide_join_thread+0x1a): undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
CMakeFiles/conv-3.dir/build.make:96: recipe for target 'conv-3' failed
make[2]: *** [conv-3] Error 1
CMakeFiles/Makefile2:230: recipe for target 'CMakeFiles/conv-3.dir/all' failed
make[1]: *** [CMakeFiles/conv-3.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
CMakeLists.txt
project(three_layer_conv)
cmake_minimum_required(VERSION 3.1.3)
set(HALIDE_DISTRIB_DIR "/home/user/workspace/Halide/distrib")
include(/home/user/workspace/Halide/distrib/halide.cmake)
# Define the wavelet app
add_executable(conv-3 "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp")
set_target_properties(conv-3 PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO)
target_include_directories(conv-3 PRIVATE "${HALIDE_INCLUDE_DIR}" "${HALIDE_TOOLS_DIR}")
# Define a halide_library() for each generator we have, and link each one into wavelet
#halide_library("conv_3" SRCS "conv_3_generator.cpp")
#file(GLOB GENS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/*_generator.cpp")
#foreach(GEN_SRC ${GENS})
# string(REPLACE "_generator.cpp" "" GEN_NAME "${GEN_SRC}")
# halide_library("${GEN_NAME}" SRCS ${GEN_SRC})
# target_link_libraries(conv-3 "${GEN_NAME}" )
#endforeach()
#target_link_libraries(conv-3 PUBLIC "conv_3" pthread)
halide_generator(conv_3.generator SRCS conv_3_generator.cpp)
set(LIB conv_3)
halide_library_from_generator(${LIB} GENERATOR conv_3.generator)
target_link_libraries(conv-3 PRIVATE ${LIB} pthread)
make VERBOSE=1
results in
/usr/bin/c++ -rdynamic CMakeFiles/conv-3.dir/main.cpp.o -o conv-3 ./genfiles/conv_3/conv_3.a -lpthread ./genfiles/halide_rt_host/halide_rt_host.a -ldl
PS: Manually adding -lpthread
to the end of the command results in resolution of the pthread linking error.
Do I need to change my CMake file?
Edit : Halide.cmake
file can be found here
halide_library, halide_library_from_generator, halide_generator
functions are defined in Halide.cmake
Edit 2
OS : Ubuntu 18.04.3 LTS
compiler : cc/c++ (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
linker : GNU ld (GNU Binutils for Ubuntu) 2.30
LLVM : LLVM version 8.0.0 Optimized build
LLVM options : none
Build target : binary
There were two ways in which this problem was solved:
-lpthread -lHalide
to /usr/bin/c++ -rdynamic CMakeFiles/conv-3.dir/main.cpp.o -o conv-3 ./genfiles/conv_3/conv_3.a -lpthread ./genfiles/halide_rt_host/halide_rt_host.a -ldl
This solved the linking problem