Changing .lib file in application dynamically

Hello Everybody,

I have this application in which I use a .lib file which is added to the application in Project Editor menu before compilation.

My problem that I am using different versions of that .lib file depending on a choice in the application.
Now I am creating various copies of the application depending on the .lib I need, another workaround is having a copy of each version and rename before running the application.

I hope there is a way or code to change the targeted .lib at runtime.

I am using Clarion 6.3

Thank you

You could use COMPILE(), based on the switch of your choice, using different pragma statements in code.

     PRAGMA ('link (version1.lib)')

Thank you for your reply.

Can you elaborate more about how I can implement this to work after application execution to choose the required .lib file.

Thank you again.


The only way I know of to achieve something like that at run-time is to use LoadLibrary() on DLLs.

If your .lib files are actually pointing to different DLLs, then you could do this.

I will check that.

Best Regards

In Clarion, as in many other programming languages, .lib files are static libraries that are linked to your application at compile time. This integration means that once your application is compiled with a specific .lib file, that version becomes a fixed part of your executable and cannot be changed during runtime. Consequently, the idea of switching between different versions of a .lib file based on user choices within the application isn’t feasible. You would need to compile a separate version of your application for each .lib file version you wish to use.

However, for dynamic behavior, as Jeff mentioned, you might need to consider using dynamic libraries (DLLs), particularly leveraging the Windows API function LoadLibrary. This function allows your application to load a DLL at runtime, enabling you to programmatically choose which DLL to load and even switch between different DLLs while the application is running.

Transitioning from static libraries to DLLs will necessitate some modifications in your application(s). This subject might require a deeper understanding and possibly several forum posts here if it’s not something you’re already familiar with. It’s a significant change but can provide the flexibility you need for dynamic functionality.

1 Like

Thank for the detailed information.

Best regards

If you look in Clarion\libsrc\win\ClaRunExt.clw, there is an example of LoadLibrary in use, along with calls to GetProcAddress().

I will check that too.

Best Regards