Linking .lib into IDE

Started by tpekar, August 17, 2012, 11:34:31 PM

Previous topic - Next topic

tpekar

I have 2 .lib that I have linked into my program using the PellesC command line.  However, I can't figure out how to do it in the IDE.  I have included them in the linker options under Project Options.  They are in my working project directory.  And I added my current working project directory to the list of library directories.  What am I doing wrong?

Any help would be greatly appreciated! :)

CLR

Hi tpekar.

What you've done is correct and it should work. Please make sure your libraries and program are both win32 or both win64. You can't use an win32 library in a win64 program. Also check the calling conventions of your functions in your library and in your program (Project -> Options -> Compiler -> Calling conv.) They should match.

CommonTater

Quote from: tpekar on August 17, 2012, 11:34:31 PM
I have 2 .lib that I have linked into my program using the PellesC command line.  However, I can't figure out how to do it in the IDE.  I have included them in the linker options under Project Options.  They are in my working project directory.  And I added my current working project directory to the list of library directories.  What am I doing wrong?

Any help would be greatly appreciated! :)

What error messages are you getting?  We're not mind readers...

If you've included the libs on the linker's settings... have you included their headers into your source files?


tpekar

I changed my calling convention to stdcall and am still getting errors (different from when I had cdecl).  Sorry, here they are:

Building addndx.exe.
POLINK: error: Symbol '_cb_prints@4' is multiply defined: 'C:\Users\pekar\Documents\Pelles C Projects\addndx\output\ADDNDX.obj' and 'cbt.lib(w32io.obj)'.
POLINK: error: Unresolved external symbol '_stricmp'.
POLINK: error: Unresolved external symbol '__imp__timeGetTime@0'.
POLINK: fatal error: 2 unresolved external(s).
*** Error code: 1 ***
Done.

My source code for addndx (included here) does not have a 'cb_prints'.

CommonTater

#4
Quote from: tpekar on August 20, 2012, 09:00:45 PM
I changed my calling convention to stdcall and am still getting errors (different from when I had cdecl).  Sorry, here they are:

Building addndx.exe.
POLINK: error: Symbol '_cb_prints@4' is multiply defined: 'C:\Users\pekar\Documents\Pelles C Projects\addndx\output\ADDNDX.obj' and 'cbt.lib(w32io.obj)'.
POLINK: error: Unresolved external symbol '_stricmp'.
POLINK: error: Unresolved external symbol '__imp__timeGetTime@0'.
POLINK: fatal error: 2 unresolved external(s).
*** Error code: 1 ***
Done.

My source code for addndx (included here) does not have a 'cb_prints'.


Ok... looking at your source there are a number of problems...

First, the setup of it is terrible... don't just jam everything up together... set it up in a clear and easly readable manner... like this...

#include "isam.h"
#pragma lib "isam.lib"
#pragma lib "cbt.lib"

int i;
char source[129]= "";
char message[129];

#include "tools.c"   
                             
main(int argc, char *argv[])
  {
    Db_Obj *db;

    if (argc < 4)
     {
        printf("\nMust have at least 3 parameters to create index");
        exit(-3);
     }

    for (i = 0; i < argc; i++)
      {
         strcat(source,argv[i]);
         strcat(source," ");
      }

    argv[argc]=NULL;

    db=iopen_db(argv[2]);

    if (db == NULL)
      {
        printf("\ndatabase %s not found, cannot create index", argv[2]);
        exit(-1);
       //  abortx(message);
      }

    if (imkindex(db, argv[1], &argv[3]) == I_ERROR)
      {
         iprterr();
         printf("\nindex %s could not be created", argv[1]);
        exit(-2);
      // abortx(message);
      }
    else printf("index created successfully");
  }


For the code itself...

It's int main (int argc, char* argv[])  and it returns a value to the operating system at the end usually return 0; ... and yes it matters... that's how the OS knows if your program succeeded or had errors.

Do not #include .c files ... make a header (.h file) with the functions you want to import.

You are using several functions without the correct headers... strcat() for one... #include <string.h> ... this probably explains most of the unresolved externals.

You are including cbt.lib with no header to import functions.  The linker will not find references to it's functions in your code and will not include it.

For the duplicated identifier I'm betting it's either in that tools.c file you're including directly into your source or it's referenced by it.  (This by the way is why we make header files!)

TimoVJL

QuotePOLINK: error: Unresolved external symbol '_stricmp'.
use compiler option -Go (Define compability names)
QuotePOLINK: error: Unresolved external symbol '__imp__timeGetTime@0'.
insert #pragma lib "winmm.lib"
May the source be with you