Thread: Compilation fails everytime while using SQLAllocHandle

  1. #1
    Registered User
    Join Date
    Jan 2015
    Posts
    9

    Compilation fails everytime while using SQLAllocHandle

    Hi All,

    Im stuck with this error for a week and I cant move on... Please help me out... I have been trying to compile this simple C program on my AIX machine but getting the below error.

    Code:
    #include <stdio.h>
    #include "sql.h"
    #include "sqlext.h"
    main() {
    SQLHENV env;
    char dsn[256];
    char desc[256];
    SQLSMALLINT dsn_ret;
    SQLSMALLINT desc_ret;
    SQLUSMALLINT direction;
    SQLRETURN ret;
    SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
    }
    I used below compilation and got the error :

    Code:
    /apps//scripts$gcc data.c -o data
    ld: 0711-317 ERROR: Undefined symbol: .SQLAllocHandle
    ld: 0711-317 ERROR: Undefined symbol: .SQLExecDirect
    ld: 0711-317 ERROR: Undefined symbol: .SQLFreeHandle
    ld: 0711-317 ERROR: Undefined symbol: .SQLBindCol
    ld: 0711-317 ERROR: Undefined symbol: .SQLFetch
    ld: 0711-317 ERROR: Undefined symbol: .SQLDisconnect
    ld: 0711-317 ERROR: Undefined symbol: .SQLSetEnvAttr
    ld: 0711-317 ERROR: Undefined symbol: .SQLDriverConnect
    ld: 0711-317 ERROR: Undefined symbol: .SQLGetDiagRec
    ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
    collect2: ld returned 8 exit status

    UNIX odbc is installed in

    Code:
    /usr/local/easysoft/unixODBC
    The header files are located in

    Code:
    /usr/local/easysoft/unixODBC/include

    I copy pasted the header files from here to my current directory and compiled my program.

    Don't know what is missing ...

    Please throw some light .......

  2. #2
    Registered User
    Join Date
    Mar 2012
    Location
    the c - side
    Posts
    373
    Have you tried googling on "Undefined symbol: .SQLAllocHandle" etc?

  3. #3
    Registered User
    Join Date
    Jan 2015
    Posts
    9
    Quote Originally Posted by gemera View Post
    Have you tried googling on "Undefined symbol: .SQLAllocHandle" etc?
    Yes, I have tried various solutions provided in different sides, but could not solve it.

    One of the solution was to include the lib file "libodbc.a".

    It was not present inside /usr/lib but inside /usr/local/easysoft/unixODBC/lib.

    I copy paseted that lib file to my current directory which is /apps/scripts.

    And I ran the below command

    Code:
     /apps/rmb/scripts$gcc database.c -L/apps/rmb/scripts -lodbc -o database
    ld: 0711-317 ERROR: Undefined symbol: .SQLAllocHandle
    ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
    collect2: ld returned 8 exit status
    /apps/rmb/scripts$

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > I copy pasted the header files from here to my current directory and compiled my program.
    Don't do this.

    Your gcc command line should look something like this
    Code:
    gcc -I/usr/local/easysoft/unixODBC/include -L/usr/local/easysoft/unixODBC/lib data.c -o data -lodbc
    minus-capital-I tells the compiler where to find header files.

    minus-capital-L tells the linker where to find additional libraries. You need to find where the .a / .so files are stored underneath /usr/local/easysoft/unixODBC. I guessed lib, but they might be somewhere else.

    minus-lowercase-l specifies the name of a library that the linker (that's the ld program in the error messages) should use - ideally one containing the symbols which are currently unresolved. If you say -lfoo, the real filename is called libfoo.a, so bear this in mind when specifying -l parameters.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Jan 2015
    Posts
    9
    Quote Originally Posted by Salem View Post
    > I copy pasted the header files from here to my current directory and compiled my program.

    Your gcc command line should look something like this
    Code:
    gcc -I/usr/local/easysoft/unixODBC/include -L/usr/local/easysoft/unixODBC/lib data.c -o data -lodbc
    .
    Hi Salem ,

    Thanks for the advise... I tried your command, it still throws the same error... please advise

    Code:
     /apps/rmb/scripts$gcc -I/usr/local/easysoft/unixODBC/include -L/usr/local/easysoft/unixODBC/lib data.c -o data -lodbc
    ld: 0711-317 ERROR: Undefined symbol: .SQLAllocHandle
    ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
    collect2: ld returned 8 exit status
    Please advise

  6. #6
    Lurker
    Join Date
    Dec 2004
    Posts
    296
    Quote Originally Posted by lawliet View Post
    Hi Salem ,

    Thanks for the advise... I tried your command, it still throws the same error... please advise

    Code:
     /apps/rmb/scripts$gcc -I/usr/local/easysoft/unixODBC/include -L/usr/local/easysoft/unixODBC/lib data.c -o data -lodbc
    ld: 0711-317 ERROR: Undefined symbol: .SQLAllocHandle
    ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
    collect2: ld returned 8 exit status
    Please advise
    Did you do as Salem said and checked where your header files and library files actually are, or did you just copy and paste what he wrote as an example?
    "A Professor of Computer Science gave a paper on how he uses Linux to teach his undergraduates about operating systems. Someone in the audience asked why use Linux rather than Plan 9?' and the professor answered:Plan 9 looks like it was written by experts; Linux looks like something my students could aspire to write'."

  7. #7
    Registered User
    Join Date
    Jan 2015
    Posts
    9
    Quote Originally Posted by Jimmy View Post
    Did you do as Salem said and checked where your header files and library files actually are, or did you just copy and paste what he wrote as an example?
    Hi Jimmy,

    I already provided the installation path in the first post itself, based on that only salem provided the example... It is the same path.... Still its not working...
    Don't know how to solve it

  8. #8
    Lurker
    Join Date
    Dec 2004
    Posts
    296
    Quote Originally Posted by lawliet View Post
    Hi Jimmy,

    I already provided the installation path in the first post itself, based on that only salem provided the example... It is the same path.... Still its not working...
    Don't know how to solve it
    You specified where the includes could be found. Have you actually verified where the library files are?

    Salem gave you a example where the library files probably where installed and told you to verify that it was the correct path before you used his example. So, again, did you verify where the library files are installed?
    Last edited by Jimmy; 02-15-2015 at 01:43 PM. Reason: Toned it down a notch.
    "A Professor of Computer Science gave a paper on how he uses Linux to teach his undergraduates about operating systems. Someone in the audience asked why use Linux rather than Plan 9?' and the professor answered:Plan 9 looks like it was written by experts; Linux looks like something my students could aspire to write'."

  9. #9
    Registered User
    Join Date
    Jan 2015
    Posts
    9
    Hi,

    Sorry for the late reply,

    Please find all the details below. Library path is correct. Still it wont compile.

    Code:
    /usr/local/easysoft/unixODBC/lib$ls
    libodbc.a         libodbc.so.1      libodbccr.a.1     libodbcinst.a     libodbcinst.so.1
    libodbc.a.1       libodbccr.a       libodbccr.so.1    libodbcinst.a.1
    
    
    
    
    /usr/local/easysoft/unixODBC/include$ls
    odbcinst.h       odbcinstext.h    sql.h            sqlext.h         sqltypes.h       sqlucode.h       unixodbc_conf.h
    
    
    /apps/rmb/scripts$gcc -I/usr/local/easysoft/unixODBC/include -L/usr/local/easysoft/unixODBC/lib database.c -o data -lodbc
    ld: 0711-317 ERROR: Undefined symbol: .SQLAllocHandle
    ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
    collect2: ld returned 8 exit status
    /apps/rmb/scripts$

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well there's more than one library file there, perhaps you need to add another one.

    Here's how to see what you might need. Run this command line in your lib directory.
    Code:
    for i in *.a ; do echo "Searching library $i" ; nm $i | egrep "T .*SQLAllocHandle" ; done
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #11
    Registered User
    Join Date
    Jan 2015
    Posts
    9
    Hi Salem,

    Finally it worked.. I tried the below command

    gcc -maix64 -I/usr/local/easysoft/unixODBC/include -I. -L/usr/local/easysoft/unixODBC/lib -lodbc -o data database.c

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to generate random numbers the same everytime
    By lehe in forum C++ Programming
    Replies: 11
    Last Post: 04-09-2009, 06:00 PM
  2. Random # everytime (my code)
    By Paz_Rax in forum C++ Programming
    Replies: 2
    Last Post: 01-22-2004, 05:34 AM
  3. open file for different name everytime it runs
    By Jasonymk in forum C++ Programming
    Replies: 9
    Last Post: 03-04-2003, 11:32 PM
  4. 98DDK compilation fails
    By marsface in forum Windows Programming
    Replies: 0
    Last Post: 12-03-2002, 05:00 AM
  5. I get a parse error everytime I use asm
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 11-09-2001, 01:17 AM