Help configuring linker

Started by david_finlayson, July 28, 2010, 01:49:36 AM

Previous topic - Next topic

david_finlayson

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?

TimoVJL

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

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.

TimoVJL

#3
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.

May the source be with you

david_finlayson

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?

AlexN

Quote from: david_finlayson on July 28, 2010, 09:50:52 PM
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 ;)