NO

Author Topic: Linking .lib into IDE  (Read 5795 times)

tpekar

  • Guest
Linking .lib into IDE
« 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! :)

CLR

  • Guest
Re: Linking .lib into IDE
« Reply #1 on: August 19, 2012, 03:30:25 AM »
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

  • Guest
Re: Linking .lib into IDE
« Reply #2 on: August 19, 2012, 05:43:00 AM »
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

  • Guest
Re: Linking .lib into IDE
« Reply #3 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'.

CommonTater

  • Guest
Re: Linking .lib into IDE
« Reply #4 on: August 20, 2012, 09:39:07 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...
Code: [Select]
#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!)
 
« Last Edit: August 20, 2012, 09:41:28 PM by CommonTater »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Linking .lib into IDE
« Reply #5 on: August 21, 2012, 12:54:42 PM »
Quote
POLINK: error: Unresolved external symbol '_stricmp'.
use compiler option -Go (Define compability names)
Quote
POLINK: error: Unresolved external symbol '__imp__timeGetTime@0'.
insert #pragma lib "winmm.lib"
May the source be with you