Linking error (cygwin, make, windows, sql)

Discussion in 'C++' started by PG, Mar 8, 2008.

  1. PG

    PG Guest

    I am trying to compile a simple ODBC and C example on Windows XP SP2.
    I have Cygwin_NT 5.1.

    This is the code (obtained from
    http://www.easysoft.com/developer/languages/c/odbc_tutorial.html#dm_f...)
    i am attempting to compile.

    ODBCTest.c

    #include <stdio.h>
    #include <windows.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);
    SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);

    direction = SQL_FETCH_FIRST;
    while(SQL_SUCCEEDED(ret = SQLDataSources(env, direction,
    dsn, sizeof(dsn), &dsn_ret,
    desc, sizeof(desc),
    &desc_ret))) {
    direction = SQL_FETCH_NEXT;
    printf("%s - %s\n", dsn, desc);
    if (ret == SQL_SUCCESS_WITH_INFO) printf("\tdata truncation\n");
    }

    }

    Makefile

    CC=gcc
    INCPATH=-I/usr/include -Iinclude
    LIBS=-L. -lodbc32
    LD=ld
    all: clean ODBCTest.exe

    ODBCTest.o : ODBCTest.c
    $(CC) $(INCPATH) $(CFLAGS) -o ODBCTest.o -c ODBCTest.c
    ODBCTest.exe : ODBCTest.o
    $(CC) $(LIBS) $(CFLAGS) -o ODBCTest.exe ODBCTest.o
    clean:
    -rm *.o
    -rm *.exe


    Make output and Errors:

    $ make
    rm *.o
    rm *.exe
    rm: cannot remove `*.exe': No such file or directory
    make: [clean] Error 1 (ignored)
    gcc -I/usr/include -Iinclude -o ODBCTest.o -c ODBCTest.c
    gcc -L. -lodbc32 -o ODBCTest.exe ODBCTest.o
    ODBCTest.o:ODBCTest.c:(.text+0x4a): undefined reference to
    `_SQLAllocHandle@12'
    ODBCTest.o:ODBCTest.c:(.text+0x70): undefined reference to
    `_SQLSetEnvAttr@16'
    ODBCTest.o:ODBCTest.c:(.text+0xca): undefined reference to
    `_SQLDataSources@32'
    collect2: ld returned 1 exit status
    make: *** [ODBCTest.exe] Error 1


    Things i have checked:
    libodbc32.a exists in c:\cygwin\lib\w32api.
    If i remove the above lib, i get a "lib not found" kind of error when
    i run make, meaning this is the lib make is using and there is no path
    issue.
    if i edit libodbc32.a in a binary editor, i can see the all the three
    functions mentioned in the error (_SQLAllocHandle@12,
    _SQLSetEnvAttr@16 and _SQLDataSources@32) exist.

    How can i fix these linking errors?

    Thanks

    PG
    --
    comp.lang.c.moderated - moderation address: -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.
     
    PG, Mar 8, 2008
    #1
    1. Advertising

  2. PG

    Ian Collins Guest

    PG wrote:
    > I am trying to compile a simple ODBC and C example on Windows XP SP2.
    > I have Cygwin_NT 5.1.
    >

    Why cross-post this to three groups where it is off topic? Try one of
    the many windows programming groups.

    --
    Ian Collins.
    --
    comp.lang.c.moderated - moderation address: -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.
     
    Ian Collins, Mar 17, 2008
    #2
    1. Advertising

  3. PG

    Flash Gordon Guest

    PG wrote, On 08/03/08 18:21:
    > I am trying to compile a simple ODBC and C example on Windows XP SP2.
    > I have Cygwin_NT 5.1.


    Since you are not using C why cross-post to a C++ group?

    > This is the code (obtained from
    > http://www.easysoft.com/developer/languages/c/odbc_tutorial.html#dm_f...)
    > i am attempting to compile.


    ODBC is not topical here since it is not standard C. There are, however,
    mailing lists for unixODBC, see the unixODBC web site for details. For
    the MS implementation there are plenty of Microsoft groups.

    <snip>

    > How can i fix these linking errors?


    How to drive your tools to link to non-standard libraries is also not
    topical here. However, there are Cygwin mailing lists. However I suggest
    you try specifying the libraries you need after the object files that
    reference them.
    --
    Flash Gordon
    --
    comp.lang.c.moderated - moderation address: -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.
     
    Flash Gordon, Mar 17, 2008
    #3
  4. On Sat, 8 Mar 2008 12:21:40 -0600 (CST), PG <> wrote:

    >I am trying to compile a simple ODBC and C example on Windows XP SP2.
    >I have Cygwin_NT 5.1.
    >
    >This is the code (obtained from
    >http://www.easysoft.com/developer/languages/c/odbc_tutorial.html#dm_f...)


    You will probably have beeter asking on the site you got the code from
    or a newsgroup where ODBC and/or Windows is topical.


    Remove del for email
    --
    comp.lang.c.moderated - moderation address: -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.
     
    Barry Schwarz, Mar 17, 2008
    #4
  5. PG

    John Bode Guest

    On Mar 8, 1:21 pm, PG <> wrote:
    > I am trying to compile a simple ODBC and C example on Windows XP SP2.
    > I have Cygwin_NT 5.1.
    >


    Note that questions about ODBC, cygwin, XP, etc. really aren't topical
    here (your question isn't about the C language as such, which is what
    this group focuses on). In the future, you should direct such
    questions to newsgroups devoted to embedded SQL or ODBC programming.
    However, I think I know the answer to your problem.

    [snip]

    > Makefile
    >
    > CC=gcc
    > INCPATH=-I/usr/include -Iinclude
    > LIBS=-L. -lodbc32


    I suspect you need to add the path to the libodbc32.a library to your
    LIBS variable, like so:

    -L/cygdrive/c/lib/w32api

    Give that a shot, let me know if it works.
    --
    comp.lang.c.moderated - moderation address: -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.
     
    John Bode, Mar 20, 2008
    #5
  6. PG

    John Bode Guest

    On Mar 8, 1:21 pm, PG <> wrote:
    > I am trying to compile a simple ODBC and C example on Windows XP SP2.
    > I have Cygwin_NT 5.1.
    >


    Note that questions about ODBC on Windows using Cygwin are not topical
    for this newsgroup; our focus is on the C language itself, not
    applications using C. However, I think I know what your problem is:


    [snip]

    >
    > Makefile
    >
    > CC=gcc
    > INCPATH=-I/usr/include -Iinclude
    > LIBS=-L. -lodbc32


    You need to specify the path to the libodbc32.a library, otherwise it
    will only look in the standard library path. Add the following to
    your LIBS variable:

    -L/cygdrive/c/cygwin/lib/w32api

    I think that's the right path, anyway.
    --
    comp.lang.c.moderated - moderation address: -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.
     
    John Bode, Mar 20, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    455
  2. Replies:
    0
    Views:
    434
  3. WELCOME to

    , Sep 3, 2003, in forum: Python
    Replies:
    1
    Views:
    514
    Robin Becker
    Sep 5, 2003
  4. capes
    Replies:
    0
    Views:
    342
    capes
    Oct 4, 2006
  5. PG
    Replies:
    5
    Views:
    478
    John Bode
    Mar 20, 2008
Loading...

Share This Page