NO

Author Topic: Problem with external library  (Read 4688 times)

CBSD

  • Guest
Problem with external library
« on: June 13, 2008, 02:23:24 PM »
Hello everybody!

Probably this problem because of me, but...

I tried to link self made (with Pelles C) external library to another Pellec C Windows console project but had no success.  :'( I'd read all recommendations about it on this respectable forum. I'd added my lib to 'Library and object files:'. String looks like this:

kernel32.lib advapi32.lib delayimp.lib dima.lib

Lib dima.lib is mine

I also added my folder to the 'Folders' - Library tab. It looks like this:

I:\Program Files\PellesC\Lib\Win
I:\Program Files\PellesC\Lib
N:\C_work\dima

But it did not help. I got

Building testexe.exe.
POLINK: error: Unresolved external symbol '_dima_fun'.
POLINK: fatal error: 1 unresolved external(s).
*** Error code: 1 ***
Done.

again and again. dima_fun is the function that I want to call. This function really is in the dima.lib

Help me please!!!!

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Problem with external library
« Reply #1 on: June 13, 2008, 03:02:20 PM »
Perhaps adding a function prototype with right calling convention may help.

like int _cdecl dima_fun(void); etc. depending how you compiled it.
May the source be with you

CBSD

  • Guest
Re: Problem with external library
« Reply #2 on: June 13, 2008, 05:50:36 PM »
Timovjl your are a man of genius! It works!  ;D But for God's sake, why it dose not work without _cdecl?!  ???

Many thanks!
« Last Edit: June 14, 2008, 06:27:04 AM by CBSD »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Problem with external library
« Reply #3 on: June 13, 2008, 08:47:15 PM »
Quote
But for God's sake, why it dose not work without _cdecl?!
PellesC support all Windows calling conventions. look at help file.
It works if project and library use same calling convention.
See example project.

PS.
The real genius Pelle explained that to me some time ago.
« Last Edit: June 13, 2008, 09:01:30 PM by timovjl »
May the source be with you

CBSD

  • Guest
Re: Problem with external library
« Reply #4 on: June 14, 2008, 06:24:39 AM »
Thanks again Timovjl!

I see that default calling conv. of EXE project is _cdecl while the LIB project has _stdcall. All we need to do synchronize the calling conventions in LIB and EXE project. For me, it would be more logically to set up the same calling conventions as a default in all types of projects. Though, may be I am wrong.

If this is not very long story, I want to know the purpose of present PellesC logic.

Forward thanks!

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Problem with external library
« Reply #5 on: June 14, 2008, 08:46:47 AM »
PellesC default calling convention is __cdecl for console and __stdcall for GUI program.
May the source be with you

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: Problem with external library
« Reply #6 on: June 14, 2008, 05:24:12 PM »
Console mode projects are intended for standard C and free of 'Windows clutter', so they default the C calling convention (cdecl). GUI mode project are by definition for Windows where the default calling convention is stdcall. Different project types will have different conventions, but there really isn't a good *common* convention...

( Generally speaking I personally think it's safer to include the calling convention in any form of 'interface' prototypes, maybe 'hidden' in a macro, rather than remember to use the same convention for all the projects. Just one thing less that *may* cause problems a year from now... )
/Pelle

CBSD

  • Guest
Re: Problem with external library
« Reply #7 on: June 15, 2008, 04:53:06 PM »
Thanks for information Pelle and Timovjl!

Now I formulated the logic for myself!  :)

1) Console projects are mostly for learning purposes and have cdecl calling convention. Being a *pure* (and newbie) C programmer, I can use functions with variable number of parameters for example!

2) *Real tough* GUI projects have stdcall convention because of Windows clutter. This tool used by experienced programmers.

3) Library is a tool for experienced developers not for beginners!  ;D Hence it has *experienced* stdcall convention by default.

Now my restless mind has a rest.  ;D