Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

std Linking error UDF Impala

Highlighted

std Linking error UDF Impala

Explorer

Hi

I have a problem with I try execute UDF in Impala declaring a std static variable. For example:

 

#include <string>
#include <stdlib.h>

static std::string rowRes = "Test";

IntVal TestUDF(FunctionContext* context)
{
return IntVal(rowRes.len);
}

No problem if I compile with g++ (shared libray) but if I compile it with clang, impala returns this error (select TestUDF();):

 

ERROR: Problem linking /var/lib/impala/udfs/TestUDFs.ll to main module: Appending variables with different element types!

 

This is my CMakeLists.txt:

 

cmake_minimum_required(VERSION 2.6)

# where to put generated libraries
set(LIBRARY_OUTPUT_PATH "build")
# where to put generated binaries
set(EXECUTABLE_OUTPUT_PATH "build")

find_program(CLANG_EXECUTABLE clang++)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -ggdb ")

# Function to generate rule to cross compile a source file to an IR module.
# This should be called with the .cc src file and it will generate a
# src-file-ir target that can be built.
# e.g. COMPILE_TO_IR(test.cc) generates the "test-ir" make target.
set(IR_COMPILE_FLAGS "-emit-llvm" "-O3" "-c" "--std=c++11" "-stdlib=libstdc++")
function(COMPILE_TO_IR SRC_FILE)
  get_filename_component(BASE_NAME ${SRC_FILE} NAME_WE)
  set(OUTPUT_FILE "build/${BASE_NAME}.ll")
  add_custom_command(
    OUTPUT ${OUTPUT_FILE}
    COMMAND ${CLANG_EXECUTABLE} ${IR_COMPILE_FLAGS} ${SRC_FILE} -o ${OUTPUT_FILE}
    DEPENDS ${SRC_FILE})
  add_custom_target(${BASE_NAME}-ir ALL DEPENDS ${OUTPUT_FILE})
endfunction(COMPILE_TO_IR)


# Build the UDA/UDFs into a shared library.
# add_library(TestUDFs SHARED TestUDFs.cc)

# Custom targest to cross compile UDA/UDF to ir
if (CLANG_EXECUTABLE)
  COMPILE_TO_IR(TestUDFs.cc )
endif(CLANG_EXECUTABLE)

 

Thanks!!!

Regards