NO

Author Topic: Linking with static lib  (Read 2900 times)

Ze

  • Guest
Linking with static lib
« 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?
« Last Edit: May 01, 2013, 05:39:35 PM by Ze »

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Linking with static lib
« Reply #1 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)
« Last Edit: May 02, 2013, 10:18:42 PM by frankie »
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Ze

  • Guest
Re: Linking with static lib
« Reply #2 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.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Linking with static lib
« Reply #3 on: May 14, 2013, 02:19:19 PM »
Actaully there is no way to do that.  :(
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide