Author Topic: Using DLLs with CodeBlocks  (Read 6022 times)

Offline AndrewCot

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 678
Re: Using DLLs with CodeBlocks
« Reply #15 on: April 13, 2022, 11:46:48 pm »
Guys, see Miguels's post #1 above as he explained what was needed to link a DLL and you guys are going in circles as you need to link to a .a file and if you do not have a .a file for the DLL then you need to get one!!!

Offline rascalito

  • Single posting newcomer
  • *
  • Posts: 8
Re: Using DLLs with CodeBlocks
« Reply #16 on: April 15, 2022, 03:26:41 am »
Hello!

Thanks for your reply!

I tried without the dll extension, it doesn't change.
I tried also many combinations, local path, absolute path, etc, since there are a few parameters that can have an influence
(and made a spreadsheet to be sure not to forget one combination).

Quote
If that does not work as well I would try to get a small sample from the web were you create a DLL yourself and run a test program.

That's probably what I will end doing. I'm surprised that such a simple task is so complicated with CodeBlocks. I'm working mostly
with embedded systems, (Texas instruments and more recently STM32) and when you need at lib, you just add it to the source tree
by browsing to its location, and you include the .h file in the code.
It was pretty much the same 25 years ago as a BeOS programmer. You add the dll (which was called "shared object", .so), you include
the h file and period! That's it.

Quote
Guys, see Miguels's post #1 above as he explained what was needed to link a DLL and you guys are going in circles as you need to link to
a .a file and if you do not have a .a file for the DLL then you need to get one!!!

So do you mean that CodeBlocks does not allow the use of DLLs?

R
« Last Edit: April 15, 2022, 03:28:37 am by rascalito »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: Using DLLs with CodeBlocks
« Reply #17 on: April 15, 2022, 04:58:42 am »
It means that Code::Blocks is not a magic wand!

If your compiler can not link to an DLL; using Code::Blocks will not make it work!

Can you answer the simple question was the DLL an C++ DLL or an C DLL?

If C++ DLL you must use an compatible C++ compiler to build and link the code.

If you post a full build log; when you try linking to the full path of the DLL I might be able to help you.

You likely have not tried linking to the DLL full path; but, since you have issues cutting and pasting the full log that is a guess on my part.

Edit: If you linked to the DLL using a full path I would expect to see something like the below in the log.
Code
-lC:\Users\Rascalito\Develop\CodeBlocks\Kalman\kalman_lib.dll

Edit2: Notice the "-l" in front of the DLL path.

Tim S.
« Last Edit: April 15, 2022, 07:09:02 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Using DLLs with CodeBlocks
« Reply #18 on: April 15, 2022, 10:38:44 am »
Well, the easiest way is always to have the SDK for the (Kalman) lib that consists of both: The lib to links against and the runtime. DLL's are not guaranteed to be linkable. You can try but you may fail. It depends on the linker, not C::B. Also, in case of a DLL it could be way more issues, like wrong compiler flavour/architecture, wrong bit (32 vs. 64).

What you are trying to do can have many errors. So once again:
- Grab either the SDK and use the proper import lib
- Grab the source code of the Kalman.dll and compile it with the same compiler and create an import lib yourself.

But that is beyond the scope of this forum which is about C::B and not how to compile libs.

So please, keep this forum clean, remain in the scope of C::B related questions, otherwise this topic might get locked.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline tigerbeard

  • Almost regular
  • **
  • Posts: 190
Re: Using DLLs with CodeBlocks
« Reply #19 on: April 15, 2022, 12:54:48 pm »
I'm surprised that such a simple task is so complicated with CodeBlocks.
Once you solved your riddle, you will find that CB is very easy to use with DLLs/SOs. I am using SO's all the time and its just adding a path and a single name in CB,
As I did a few year ago, you might be surprised about the technical details of DLLs/SO's. Although DLLs and SOs are basically the same they follow different rules in Windows and Linux. They must to handle multiple versions on the same lib on system level, there are major differences between DLLs in C and C++ (keyword name mangling) and the fact that C++ DLLs only work if they were done with the same compiler as stahta01 wrote and more. Each OS creates a set of rules you must obey. On a microcontroller much of that is not an issue, making things a lot easier.
When I started with Visual Studio I was totally ignorant of all of this. I could copy & paste DLL code but I was a script kiddie rather than a programmer beacause I did not really understand what I was doing. From your posts I would guess you are not aware of any of those complexities as well. I am not implying you are not a good programmer (as I was), but you might have some things to catch up on DLLs.


So do you mean that CodeBlocks does not allow the use of DLLs?
Of course not, why should it? The use of DLLs in computer programming is so extraordinary rare that over 20 years of CB development you are the first user ever even mentioning that. Maybe you should consider filing a feature request for it. (irony off)
There was a Mercedes Benz S-Class driver asking after a test drive why the vehicle of the current Rallye motorsport world champion was so badly designed that you could not do a controlled turn with it? I wonder does  this question tell more about the vehicle or about the questioner?

Seriously, I can see you are frustrated.
Please allow me to point out a key item about CB: Its an open system. It allows you to use any compiler on any of the major OS including Arm compiler and MS visual studio's compiler. However, this flexibility and openess comes with a price: I does not shield you from technical complexiities as other IDEs do. There is a chance that if you do not understand what you are doing, you will fail. Embedded dev environments, VisualStudio and probable also Apple dev environments are tight and closed. They can be, because there is only only one way of doing things and the tools know all the fixed parameters and can do things for you.
It possible to extend CB to do the same, e.g. a DLL creation wizard for Windows, but you would need one for each combination of compiler and OS. Yet nobody thought such a thing was worthwhile, because knowing the basics and using the CB core facilities is the better option in the long run.
What CB is lacking though and what would help people in your situation is easyly accessible documentation like an help with How-Tos and examples or tutorials. But I am sure also in your case once you solved the issue like all people before you you will not gather enough motivation to sit down and write up a documentation like that. And once you have mastered the skills to use CB as a efficient tool you will lack the motiviation for it. Welcome to the viscious circle of open source.  :)


That's probably what I will end doing.
I am sorry I can not help you further on windows. Sitting in front of your terminal with the lib, the full log output and dev tools I m sure its easy to solve. However, I am sure what you say is the best way forward.

To get a feel for what is behind DLLs I can recommend David A. Wheelers paper "Program Library HOWTO" from May 15, 2010. I am sure google will find it. Although its Linux also Win users cross reading the 25 pgs should get a good feel why DLLs are more than they seem on the first glance. Win has the same issues, just different solutions. After reading you might see why here we fail to give you just the right cue.