Author Topic: Building an application which uses dll's  (Read 7908 times)

Offline OldSeaWolf

  • Single posting newcomer
  • *
  • Posts: 7
Building an application which uses dll's
« on: September 01, 2010, 08:35:22 pm »
Dear members of the forum.
I have met a problem while I decided create a program that uses dynamically linked libraries.
I had created and compiled two test projects of my dlls without any problems and errors. In the process of compilation and linking 3 files were created for each project in the directory bin\debug:
<name>.dll, lib<name>.dll.a, lib<name>.dll.def .
Then I have created a project with a program that must use these dlls (future exe-module), copied lib<name>.dll.a file to the project directory and pointed it in the linker options of the project. I have added these files to the project tree as well. However after I started building (Ctrl-F9), some strange errors of the linker appeared.
Here is a quote:
mingw32-g++.exe: obj\Debug\libinout.dll.o: No such file or directory
mingw32-g++.exe: obj\Debug\libarithm.dll.o: No such file or directory

When I delete these files from the project tree leaving them in linker options another error springs out:
ld.exe:          cannot find -larithm.dll


Please explain me what causes these mistakes and what  I'm doing wrong. I tried to find this information in the users manual, however I didn't find any (perhaps I was not careful enough in my search). Could you give me a step by step instruction of creating such a project? I have made such projects based on the same source text in Visual Studio and dev-cpp (which contains an older version of MinGW) successfully, but I can't resolve the same problem in this IDE. Could you help me?


Offline stahta01

  • Lives here!
  • ****
  • Posts: 7699
    • My Best Post
Re: Building an application which uses dll's
« Reply #1 on: September 01, 2010, 08:39:50 pm »
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 OldSeaWolf

  • Single posting newcomer
  • *
  • Posts: 7
Re: Building an application which uses dll's
« Reply #2 on: September 01, 2010, 09:10:21 pm »
Tim, here is the full log after Ctrl-F11. If it is necessary, I can send you all the project, it is a simple console application.


-------------- Clean: Debug in main ---------------

Cleaned "main - Debug"

-------------- Build: Debug in main ---------------

mingw32-g++.exe -Wall -fexceptions  -g     -c "C:\samp\gcd_lcm(2)\dynamic_link (CodeBlocks)\main\main.cpp" -o obj\Debug\main.o
mingw32-g++.exe  -o bin\Debug\main.exe obj\Debug\libinout.dll.o obj\Debug\main.o obj\Debug\libarithm.dll.o    -larithm.dll -linout.dll
mingw32-g++.exe: obj\Debug\libinout.dll.o: No such file or directory
mingw32-g++.exe: obj\Debug\libarithm.dll.o: No such file or directory
Process terminated with status 1 (0 minutes, 3 seconds)
0 errors, 0 warnings
 

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7699
    • My Best Post
Re: Building an application which uses dll's
« Reply #3 on: September 01, 2010, 09:14:23 pm »
Something is not right; but, I am not sure what is the cause.

What did you type into the Linker Library search path?
What did you type into the extra/other linker options?
What is the files in the project?

Quote
I have added these files to the project tree as well.
Try removing the DLLs from project tree.

Tim S.
« Last Edit: September 01, 2010, 09:16:30 pm 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 OldSeaWolf

  • Single posting newcomer
  • *
  • Posts: 7
Re: Building an application which uses dll's
« Reply #4 on: September 01, 2010, 09:28:29 pm »
I didn't point any paths to the IDE. I have copied the dll<...>.dll.a files to the main directory of the project (where I put all my sources). And I included these *.a files into the project.
First I added them to the project file-tree, then I pointed them in the linker options:
Project -> Build Options -> Linker Settings -> Link Libraries (Add Button).

Files in the project

Sources:
main.cpp

Headers:
arithm.h
inout.h

Others
libarithm.dll.a
libinout.dll.a


Offline stahta01

  • Lives here!
  • ****
  • Posts: 7699
    • My Best Post
Re: Building an application which uses dll's
« Reply #5 on: September 01, 2010, 09:31:03 pm »


Others
libarithm.dll.a
libinout.dll.a



Please remove the others files.

Tim S.
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 OldSeaWolf

  • Single posting newcomer
  • *
  • Posts: 7
Re: Building an application which uses dll's
« Reply #6 on: September 01, 2010, 09:34:04 pm »
I removed these two files from Others and here is the log after rebuilding:



-------------- Clean: Debug in main ---------------

Cleaned "main - Debug"

-------------- Build: Debug in main ---------------

mingw32-g++.exe -Wall -fexceptions  -g     -c "C:\samp\gcd_lcm(2)\dynamic_link (CodeBlocks)\main\main.cpp" -o obj\Debug\main.o
mingw32-g++.exe  -o bin\Debug\main.exe obj\Debug\main.o    -larithm.dll -linout.dll
c:/program files/codeblocks/mingw/bin/../lib/gcc/mingw32/4.4.1/../../../../mingw32/bin/ld.exe: cannot find -larithm.dll
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 4 seconds)
1 errors, 0 warnings
 

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7699
    • My Best Post
Re: Building an application which uses dll's
« Reply #7 on: September 01, 2010, 09:35:26 pm »
Add the path to the Linker Search folder to find the library/DLL.

Project Build Options
Tab "search directory"
Sub-Tab "Linker"

Tim S.
« Last Edit: September 01, 2010, 09:37:52 pm 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 OldSeaWolf

  • Single posting newcomer
  • *
  • Posts: 7
Re: Building an application which uses dll's
« Reply #8 on: September 01, 2010, 09:43:28 pm »
1. What path have I to add: path that contains *.a files (lib<...>.dll.a) or path with real dlls (<...>.dll)?
2. How should I add these paths (I have two dlls)?
Project -> Build Options... -> Search Directories -> Linker -> Add Button ?
Or perhaps I must do this in some other way?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7699
    • My Best Post
Re: Building an application which uses dll's
« Reply #9 on: September 01, 2010, 09:57:26 pm »
Project -> Build Options... -> Search Directories -> Linker -> Add Button ?

Correct, add the path to the library/dll file used in the link list.

Tim S.
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 OldSeaWolf

  • Single posting newcomer
  • *
  • Posts: 7
Re: Building an application which uses dll's
« Reply #10 on: September 01, 2010, 10:16:54 pm »
I have added the paths to both dll files which were created in the process of compilation of these dll projects and the chief project was built successfully.

In fact I had three independent projects: main, arithm, inout, each of them was situated in its own folder with the same name. To make the project "main" to be compiled I had to add to its linker settings the following directories: arithm\bin\Debug, inout\bin\Debug . Both directories contained the compiled dll files: arithm.dll and inout.dll.

Is this correct and is this the thing you actually meant? Or not?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7699
    • My Best Post
Re: Building an application which uses dll's
« Reply #11 on: September 01, 2010, 10:22:08 pm »
I think it is correct.

The main thing is the items added to the linker library list should have their path added search dir linker area if they can not be found.

Tim S.
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 OldSeaWolf

  • Single posting newcomer
  • *
  • Posts: 7
Re: Building an application which uses dll's
« Reply #12 on: September 01, 2010, 10:33:41 pm »
Thank you very much, Tim.