NO

Author Topic: Linking the static library (.lib) into another project  (Read 5846 times)

tpekar

  • Guest
Linking the static library (.lib) into another project
« on: July 05, 2011, 08:03:33 PM »
I created a project to create a static library.  I have another project that has the main C program that needs to link the static library in.  How do I do that in the IDE (or the command line POLINK, either one)?

CommonTater

  • Guest
Re: Linking the static library (.lib) into another project
« Reply #1 on: July 05, 2011, 08:48:28 PM »
In the IDE you would add the library's name and path to the project settings on the linker tab and under folders.

Or you can use
Code: [Select]
#pragma lib "library.lib"
or
#pragma comment(lib,"library.lib")
in your code and add the library's path to your project options folders...

One note about libraries in Pelles C... 'cause I'm betting this would be your next question...  If you put all your library functions into a single source file, the linker will link all of them into every program even if they are not used.  The clever way is to put each function in it's own .c file and use a .h file to amalgamate the library.  This way the linker includes only the needed functions reducing the size of your program (significantly for big libraries).

tpekar

  • Guest
Re: Linking the static library (.lib) into another project
« Reply #2 on: July 06, 2011, 04:15:28 PM »
Actually what I am trying to do is incorporate Mix Software's C/Database Toolchest into my code.  They suggested recompiling their source (since their .lib is 16-bit and will not run on Windows 7 64-bit), which I did and it compiled fine (a few warnings).  But when I try to link it in, I get the following polink errors:

Building C:\Users\pekar\Documents\Pelles C Projects\crtdb\crtdb.exe.
POLINK: error: Unresolved external symbol '_stricmp'.
POLINK: error: Unresolved external symbol '__imp__timeGetTime@0'.
POLINK: error: Unresolved external symbol '_memicmp@12'.
POLINK: error: Unresolved external symbol '_WinMain@16'.
POLINK: fatal error: 4 unresolved external(s).
*** Error code: 1 ***
Done.

I have asked Mix technical support, but they say they are not familiar with the Pelles C compiler.  Suggestions anyone?

Thanks in advance.

CommonTater

  • Guest
Re: Linking the static library (.lib) into another project
« Reply #3 on: July 06, 2011, 04:52:45 PM »
A library should not have WinMain in it...  That's a windows entry point and should exist only in your main program.

You may also have to make some source level adjustments in function calls... for example stricmp() is a non-standard (for C-99) function and is thus prefixed by an underscore in Pelles C...  memicmp() is the same.

If the source isn't too big, can you attach the unedited version?  It might help to see what we're up against...
 



Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Linking the static library (.lib) into another project
« Reply #4 on: July 06, 2011, 05:20:53 PM »
This may help:
use -Go option  (Define compatibility names) oldnames.lib for _stricmp and _memicmp
include lib winmm.lib for timeGetTime
May the source be with you

tpekar

  • Guest
Re: Linking the static library (.lib) into another project
« Reply #5 on: July 06, 2011, 10:35:56 PM »
It exceeds the 256K limit.  However, memicmp and stricmp are defined in it.  Here is the source of my main program:

#include "isam.h"
#include "isamerr.h"
int i;
char source[129]="";
Db_Obj *db;
main(int argc, char *argv[]) {
for (i=0;i<argc;i++) {
  strcat(source,argv);
  strcat(source," ");
}
/*
if (argc<3) abortx(source,"\nMust be at least 2 parameters to create database");
*/
argv[argc]==NULL;
db=icreate_db(argv[1], 0, &argv[2]);
/*
if (db==NULL) abortx(source,"\ncould not create database");
 else joblog(source,"\ndatabase created successfully");
 */
 }

CommonTater

  • Guest
Re: Linking the static library (.lib) into another project
« Reply #6 on: July 07, 2011, 01:05:41 AM »
In C-99, thus Pelles C... the minimum program skeleton is one of these...
Code: [Select]
int main (void)
  {
     // your code here

   return 0; }
Code: [Select]
int main (int argc, char* argv[])
  {
     // your code here

    return 0; }

which explains your "missing return value" error...

Have you tried making a project for the library, importing it's source and recompiling it as a stand alone .lib?