Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: gtafan on November 27, 2018, 03:55:12 pm

Title: Include dll into C++ project
Post by: gtafan on November 27, 2018, 03:55:12 pm
How can I include a dll into my C++ prject in Code::Blocks? I have the .h, .dll and the other file, but what i have to do in
Code::Blocks, so can use al the stuff from the .h file?
Title: Re: Include dll into C++ project
Post by: stahta01 on November 28, 2018, 08:08:34 am
Do you know what a compiler is?

If yes, lookup the directions for your compiler.

You can sometimes link to an DLL; but, the rules very by compiler and DLL.

Tim S.
Title: Re: Include dll into C++ project
Post by: gtafan on November 28, 2018, 03:54:09 pm
Do you know what a compiler is?

If yes, lookup the directions for your compiler.

You can sometimes link to an DLL; but, the rules very by compiler and DLL.

Tim S.
Not shure about your first question, what you exactly mean, but compiler is the thing turning my sorce code into executable machine code, how exactly it´s done I don´t care. I am really not going to do that stuf manualy. The reason I am using an IDE like Code::Blocks is because I don´t want to do the most programming related stuff manually.
Posibly I just misunderstood your question and you wanted to know if the dll was compiled with the same compiler, as the one I use. If this was your question, I have no idea which compiler was used for that dll.
Title: Re: Include dll into C++ project
Post by: oBFusCATed on November 28, 2018, 04:30:49 pm
His remark is related to the fact that some compilers (linkers to be exact) aren't able to link when a dll is given on the command line. They need special import libraries.
So his suggestion is useful, because if you have no idea about the capabilities of your compiler you're going to suffer a lot and you'll have to always ask for help at random forums and possibly be ignored.

If you're using a mingw based compiler and the dll is compatible with your compiler, just add the dll to the list of linked libraries, adjust the search paths and you should be able to link it.
If it doesn't work. Post full rebuild log, but first read compiler/linkers manual how it is supposed to work in your case.

Probably reading this first might help: http://wiki.codeblocks.org/index.php/FAQ-Compiling_(errors)#Q:_What_do_I_need_to_know_when_using_3rd_party_libs.3F

Also keep in mind that IDEs save time if you know what you're doing. If you expect to click buttons at random and get the result you're after - you'll be disappointed and you'll suffer a lot.
Title: Re: Include dll into C++ project
Post by: BlueHazzard on November 28, 2018, 11:11:43 pm
Additionally keep in mind if you use a c++ dynamic library you will have a bad time if you do not use the same compiler as the dll (compiler vendor and compiler version (or to be more speciffic the ABI has to be the same)). With c dll you will have more luck.
MSVC compiled dlls are not compatible with mingw gcc without some conversation. You find the instruction in google.
If you use a gcc compiled dll you probably will have a .lib file or a .a file and you simply add them to the Project->Build options->Select the project on the left->Linker->libraries...

Title: Re: Include dll into C++ project
Post by: gtafan on November 29, 2018, 03:16:42 pm
His remark is related to the fact that some compilers (linkers to be exact) aren't able to link when a dll is given on the command line. They need special import libraries.
So his suggestion is useful, because if you have no idea about the capabilities of your compiler you're going to suffer a lot and you'll have to always ask for help at random forums and possibly be ignored.

If you're using a mingw based compiler and the dll is compatible with your compiler, just add the dll to the list of linked libraries, adjust the search paths and you should be able to link it.
If it doesn't work. Post full rebuild log, but first read compiler/linkers manual how it is supposed to work in your case.

Probably reading this first might help: http://wiki.codeblocks.org/index.php/FAQ-Compiling_(errors)#Q:_What_do_I_need_to_know_when_using_3rd_party_libs.3F

Also keep in mind that IDEs save time if you know what you're doing. If you expect to click buttons at random and get the result you're after - you'll be disappointed and you'll suffer a lot.
I have that default gcc compiler avaible with the last version of Code::Blocks, not shure about its exact name. As far I know it´s C dll I need to use.
So my question was more about exact steps I have to do in Code::Blocks, like select menu item x then a window apear, then select something there and so on.
Title: Re: Include dll into C++ project
Post by: oBFusCATed on November 29, 2018, 06:09:20 pm
Have you read the FAQ item? Have you find the needed information there?
Title: Re: Include dll into C++ project
Post by: gtafan on November 30, 2018, 11:31:35 am
Have you read the FAQ item? Have you find the needed information there?
I have read the FAQ, but the information I need was not there.
Title: Re: Include dll into C++ project
Post by: oBFusCATed on November 30, 2018, 11:53:49 am
Are you sure?

What about these two:
Quote
* In the linker settings (Project->Build Options->Search directories->Linker), point to the folder where you have your compiled library. A library usually ends with *.a or *.lib. Note that there are generally two types of libs: Static libs (after linking you are done) and Dynamic libs (where you link against an import lib but require another dynamic lib at runtime).
* In the linker settings (Project->Build Options->Linker settings) add the library/libraries you need to link against in the right order to the list of libs to link against. Order matters - again, dependencies must be taken into account. Inspect the developers guide of the component to know the dependencies. On Windows, this may include the MSDN, too which tells you what libraries you need to link against for certain symbols you or the library may make use of.
Title: Re: Include dll into C++ project
Post by: gtafan on November 30, 2018, 01:33:56 pm
Are you sure?

What about these two:
Quote
* In the linker settings (Project->Build Options->Search directories->Linker), point to the folder where you have your compiled library. A library usually ends with *.a or *.lib. Note that there are generally two types of libs: Static libs (after linking you are done) and Dynamic libs (where you link against an import lib but require another dynamic lib at runtime).
* In the linker settings (Project->Build Options->Linker settings) add the library/libraries you need to link against in the right order to the list of libs to link against. Order matters - again, dependencies must be taken into account. Inspect the developers guide of the component to know the dependencies. On Windows, this may include the MSDN, too which tells you what libraries you need to link against for certain symbols you or the library may make use of.
Looks like I am blind, sorry my fault and thanks.
But 1 question I still have, didn´t I need to select where the .h file of the lib is?
Title: Re: Include dll into C++ project
Post by: oBFusCATed on November 30, 2018, 01:58:05 pm
Same link, few lines above the lines I've pasted explains this, too.
Title: Re: Include dll into C++ project
Post by: gtafan on November 30, 2018, 02:32:51 pm
Same link, few lines above the lines I've pasted explains this, too.
You mean include files, right?
OK, looks like it worcks.