Author Topic: Include dll into C++ project  (Read 448 times)

Offline gtafan

  • Multiple posting newcomer
  • *
  • Posts: 92
Include dll into C++ project
« 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?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6368
    • My Best Post
Re: Include dll into C++ project
« Reply #1 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.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline gtafan

  • Multiple posting newcomer
  • *
  • Posts: 92
Re: Include dll into C++ project
« Reply #2 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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11279
    • Travis build status
Re: Include dll into C++ project
« Reply #3 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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2105
Re: Include dll into C++ project
« Reply #4 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...


Offline gtafan

  • Multiple posting newcomer
  • *
  • Posts: 92
Re: Include dll into C++ project
« Reply #5 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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11279
    • Travis build status
Re: Include dll into C++ project
« Reply #6 on: November 29, 2018, 06:09:20 pm »
Have you read the FAQ item? Have you find the needed information there?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline gtafan

  • Multiple posting newcomer
  • *
  • Posts: 92
Re: Include dll into C++ project
« Reply #7 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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11279
    • Travis build status
Re: Include dll into C++ project
« Reply #8 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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline gtafan

  • Multiple posting newcomer
  • *
  • Posts: 92
Re: Include dll into C++ project
« Reply #9 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?
« Last Edit: November 30, 2018, 01:48:41 pm by gtafan »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11279
    • Travis build status
Re: Include dll into C++ project
« Reply #10 on: November 30, 2018, 01:58:05 pm »
Same link, few lines above the lines I've pasted explains this, too.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline gtafan

  • Multiple posting newcomer
  • *
  • Posts: 92
Re: Include dll into C++ project
« Reply #11 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.
« Last Edit: November 30, 2018, 03:23:10 pm by gtafan »