NO

Author Topic: Help configuring linker  (Read 3193 times)

david_finlayson

  • Guest
Help configuring linker
« on: July 28, 2010, 01:49:36 AM »
I've set up a workspace with 3 projects, 1 exe and 2 libs. The exe depends on the libs.

The libs apparently build properly into their respective project folders but the exe project fails link against them.

I've added the lib project directories to the Project Options > Folders > Libraries list (on the exe project properties)
I've also added the names of the LIB files on the Linker tab (also on the exe project properties)
I've added the two library projects to Project > Workspace > Project Dependencies

When I build the exe project I see it building the libs. And I can see the libs in their folders, but the linker fails while linking the exe:

POLINK: error: Unresolved external symbol '_open_bin_input'.
... and so on for each function defined in the lib...

What am I missing?

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Help configuring linker
« Reply #1 on: July 28, 2010, 08:13:31 AM »
Do you use header files for them ?
Have you defined calling conventions in function prototypes ?
Are those calling conventions same (__cdecl or __stdcall) or defined in function prototypes.
May the source be with you

david_finlayson

  • Guest
Re: Help configuring linker
« Reply #2 on: July 28, 2010, 09:06:35 AM »
Headers: yes. I wrote them myself and saved them in the lib project directory along with the .c file. Also, I've added them to the exe project's folder list under headers.

Calling conventions? I don't know what you are talking about. They are whatever Pelles C uses as a default (since I didn't knowingly change them).

The libraries are simple 1 .c file and 1 .h file. Each defines a dozen or so functions I like to re-use in other projects.

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Help configuring linker
« Reply #3 on: July 28, 2010, 10:31:48 AM »
Here is a test project.
TestMain.exe
TestMainCon.exe can't link becauce calling convention differs in Foo1().
TestMainCon is compiled with __cdecl and library foo1.lib with __stdcall.

« Last Edit: July 28, 2010, 10:47:05 AM by timovjl »
May the source be with you

david_finlayson

  • Guest
Re: Help configuring linker
« Reply #4 on: July 28, 2010, 09:50:52 PM »
Thank you for sharing the test project. The problem seems to be that I did not use the #pragma lib <library.lib> at the top of my executable file. I restructured my project to look like yours (all files in the same folder) and then added the pragmas for each library. Now it all compiles and links.

My past C experience is on Linux where all the code is built with gcc, hence no convention issues. I never needed a pragma to load a static library before either, that was a compiler flag. All things to learn. Would I need a similar pragma to load a dynamic library?

Online AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Help configuring linker
« Reply #5 on: July 29, 2010, 08:24:30 AM »
My past C experience is on Linux where all the code is built with gcc, hence no convention issues. I never needed a pragma to load a static library before either, that was a compiler flag. All things to learn. Would I need a similar pragma to load a dynamic library?

You do not need the pragma, but it is the easy way at Pelles C.

At the project options you can also add your libraries at the list of "library and object files".
best regards
 Alex ;)