Problems compiling simple UDF (plusudf).

Connectivity

Problems compiling simple UDF (plusudf).

I am a new user trying to load a simple UDF into the database but getting some errors. I am on Windows XP using VS2005. Your help is appreciated.

Here are the steps:

C code:
void plusudf(int *a, int *b, int *result)
{ *result = *a + *b;}

CREATE FUNCTION plusudf(
a INTEGER,
b INTEGER
)RETURNS INTEGER
LANGUAGE C
NO SQL
EXTERNAL NAME 'SS!plusudf!c:\mysrc\plusudf.c'

Note - I have tried SL!libcmt! but it did not help.

Errors/Warnings reported during compilation
---------------------------------------------------------------------------
Microsoft (R) Program Maintenance Utility Version 8.00.50727.762
Copyright (C) Microsoft Corporation. All rights reserved.

cl /D_CRT_SECURE_NO_DEPRECATE /DWIN32 /GS- -D_USE_32BIT_TIME_T /c /Fosam
e.obj same.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for
80x86
Copyright (C) Microsoft Corporation. All rights reserved.

same.c
cl /D_CRT_SECURE_NO_DEPRECATE /DWIN32 /GS- -D_USE_32BIT_TIME_T /c /FoNCR
_new_delete.obj NCR_new_delete.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for
80x86
Copyright (C) Microsoft Corporation. All rights reserved.

NCR_new_delete.cpp
cl /D_CRT_SECURE_NO_DEPRECATE /DWIN32 /GS- -D_USE_32BIT_TIME_T /c /Fopre
_plusudf.obj pre_plusudf.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for
80x86
Copyright (C) Microsoft Corporation. All rights reserved.

pre_plusudf.c
cl /D_CRT_SECURE_NO_DEPRECATE /DWIN32 /GS- -D_USE_32BIT_TIME_T /Felibudf
_0402_0.dll /LD same.obj NCR_new_delete.obj pre_plusudf.obj @FileList udf.
lib msvcrt.lib "msvcrt".lib "libcmt".lib
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for
80x86
Copyright (C) Microsoft Corporation. All rights reserved.

cl /link /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib

NMAKE : fatal error U1077: '"c:\Program Files\Microsoft Visual Studio 8\VC\
bin\cl.EXE"' : return code '0x2'
Stop.

cufconfig -o :
SourceDirectoryPath: C:\Program Files\Teradata\Tdat\tdconfig\Teradata\tdbs_udf\u
sr\
CompilerTempDirectory: C:\Program Files\Teradata\Tdat\tdconfig\UDFTemp\
UDFLibraryPath: C:\Program Files\Teradata\Tdat\tdconfig\udflib\
CompilerPath: c:\Program Files\Microsoft Visual Studio 8\VC\bin\CL.EXE
LinkerPath: c:\Program Files\Microsoft Visual Studio 8\VC\bin\LINK.EXE
UDFServerMemPath: C:\Program Files\Teradata\Tdat\tdconfig\udfsrv\
MaximumCompilations: 10
UDFServerTasks: 2
SecureServerAMPs: 20
ParallelUserServerAMPs: 2
SecureServerPEs: 20
ParallelUserServerPEs: 2
TDSPLibBase: C:\Program Files\Teradata\Tdat\tdconfig\tdsplib\
SecureGroupMembership: tdatudf
UDFLibPath:
UDFIncPath:
UDFEnvFile:
CLILibPath: c:\Program Files\NCR\Teradata Client\cliv2\lib
CLIIncPath: c:\Program Files\NCR\Teradata Client\cliv2\inc
CLIEnvFile:
JavaLibraryPath: C:\Program Files\Teradata\Tdat\tdconfig\jarlib\
JREPath: C:\Program Files\Java\jre1.6.0_07\
JavaLogPath: c:\Temp\
JavaEnvFile:
JavaServerTasks: 20
JavaVersion: 0x10004
JavaBaseDebugPort: 0

5 REPLIES
Teradata Employee

Re: Problems compiling simple UDF (plusudf).

Hello,

Can you please provide the whole C code?

Regards,

Adeel

Re: Problems compiling simple UDF (plusudf).

The following is the C code I am using for the UDF.

void plusudf(int *a, int *b, int *result)
{ *result = *a + *b;}

Thanks
Teradata Employee

Re: Problems compiling simple UDF (plusudf).

May not solve your problem, but that's not a valid prototype for a Teradata UDF.
Needs to be something like this (for scalar function with default parameter style TD_GENERAL):

#define SQL_TEXT Latin_Text
#include

void plusudf(INTEGER *a, INTEGER *b, INTEGER *result, char sqlstate[6])
{ *result = *a + *b;}
Teradata Employee

Re: Problems compiling simple UDF (plusudf).

Try the following C-code:

#define SQL_TEXT Latin_Text
#include

void plusudf (int *a, int *b, int *result)
{
*result = *a + *b;
}

And the following BTEQ script to compile:

.LOGON ;

CREATE FUNCTION plusudf(
a INTEGER,
b INTEGER
)RETURNS INTEGER
LANGUAGE C
NO SQL
EXTERNAL NAME 'CS!plusudf!c:\mysrc\plusudf.c';

.LOGOFF;

Running the BTEQ script (bteq ) should compile the UDF.

Regards,

Adeel
Teradata Employee

Re: Problems compiling simple UDF (plusudf).

I see this forum is stripping the header filename in "angle brackets" from the required #include directive. Depending on the path, you may be able to use double quotes. At least this way it should display and show what was meant; you can adjust if needed:
#include "sqltypes_td.h"