Pelles C forum

C language => Beginner questions => Topic started by: Ze on May 01, 2013, 04:31:00 PM

Title: Linking with static lib
Post by: Ze on May 01, 2013, 04:31:00 PM
Hi all. I'm beginner in C. I have a win32 project and a static lib, linked with it.
Up to a point it worked. Then I removed the check "Enable Microsoft extensions" and rebuild the project. I received a notices "POLINK: error: Unresolved external symbol '...'" with my lib functions names. I returned the check back, but still get this messages.
I tried to rebuild the application and the library, set different values ​​of runtime library, but nothing works, the library functions are not visible to linker.
Please help me to understand the problem.

P.S.
Sorry for my English.

----------------
I'm sorry, found one more detail. The problem occurs when I connecting two libraries to the application. If I leave one library, the functions are linking correctly. If two simultaneously - functions of one of these are not available. Can be a problem is that both of them include stdlib.h?
Title: Re: Linking with static lib
Post by: frankie on May 02, 2013, 10:14:36 PM
Check that you used the correct calling convention for library and program (compiler options->calling conv.)
Rebuild libraries first than the program then link together.
Remember that a GUI program defaults to __stdcall, while a consolle application uses __cdecl. This is not mandatory, but if you don't make aware both, program and library, of what type they are the names in library are different (__cdecl simply prepend an underscore to the function name i.e _myfunc, __stdcall append a decoration indicating how many stack bytes are required for parameters i.e. _myfunc@12)
Title: Re: Linking with static lib
Post by: Ze on May 14, 2013, 01:04:26 PM
Thank you for the answer. Calling convention in both projects is __cdecl.
Problem resolved itself. I did not even know how. After some builds error is gone.
And another question:
Can I change the project type in IDE after creation? I could not find any instruments for this.
Thank you.
Title: Re: Linking with static lib
Post by: frankie on May 14, 2013, 02:19:19 PM
Actaully there is no way to do that.  :(