Author Topic: How to include an external lib and dll ???  (Read 12128 times)

Offline kerstin

  • Single posting newcomer
  • *
  • Posts: 5
How to include an external lib and dll ???
« on: September 08, 2008, 08:15:59 am »
Hello,

I'm trying to compile a program which was written with Visual Studio 2005 with C:B and MinGW.
The program needs an external lib -> I set under project -> Build Option -> linker settings -> name of lib without .lib and under search directory I set the path to the project.
I tried also to include it under settings-> compiler&debugger-> linker settings (here I added both dll. and lib) and also I set the path under search directory.

Still I'm getting this error:
07App.o obj\Debug\TarifeMenu.o  obj\Debug\skript.res   -lgdi32 -luser32 -lkernel32 -lIEICAN02 bin\IEICAN02.lib ..\IEICAN02.dll C:\Kerstin\Code_Block\ta_project_test\IEICAN02.dll C:\Kerstin\Code_Block\ta_project_test\IEICAN02.lib
mingw32-g++.exe: ..\IEICAN02.dll: No such file or directory

Has anyone an idea???

THANKS!!!

Kerstin

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9657
Re: How to include an external lib and dll ???
« Reply #1 on: September 08, 2008, 09:06:47 am »
-lIEICAN02 bin\IEICAN02.lib ..\IEICAN02.dll C:\Kerstin\Code_Block\ta_project_test\IEICAN02.dll C:\Kerstin\Code_Block\ta_project_test\IEICAN02.lib
Did you notice that all the "libs" starting with ..\IEICAN02.dll ae missing the linker flag -l?
It seems you don't provider them through the library (project/target) options.
Either you really fill them under the project's "build options" -> tab "Linker settings" -> listbox "link libraries" line by line or (if you like) under "other linker options" but then it's best top put each library in an own line and (most important" don't forget to add the "-l" flag in front of each library.
As you see: The first solution is the best. ;-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline kerstin

  • Single posting newcomer
  • *
  • Posts: 5
Re: How to include an external lib and dll ???
« Reply #2 on: September 08, 2008, 09:20:25 am »
hi

Sorry but what do you mean with
Quote
"-l" flag in front of each library
?
Did you mean something like this?

Other linker option:
-l IEICAN02.lib

or

link libraries:
bin\IEICAN02.lib
..\IEICAN02.dll

Edit. Removed MS word content.
« Last Edit: September 08, 2008, 09:32:23 am by MortenMacFly »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9657
Re: How to include an external lib and dll ???
« Reply #3 on: September 08, 2008, 09:31:54 am »
-l IEICAN02.lib

bin\IEICAN02.lib
..\IEICAN02.dll
According to your image (Please: Never-ever use MS Word format again but true images such as JPG or PNG) you did several things wrong:

1.) Your library has an import library (if I got that picture right). So it makes no sense to link against both, the library and the DLL. Choose the library only and put the DLL to the application at runtime. I believe that's what you want to achieve.

2.) The linker option for GCC is: -l[library name]. That's a lower-case "L" WITHOUT space between the linker option and the library. Otherwise the linker takes this as two options: "-l" without am library -> so it get ignored and IEICAN02.lib as an object (not library!) file to link into the application. This won't work.

3.) You tell the linker to "somehow" include 3 files all of (more ort less) the same type. Decide for one way to go.

I strongly suggest you first read yourself into the command line version of the compiler / linker of your choice.

I'll give you a final hint:
1.) add *only* the import library under "link libraries" -> without path, without extension, without prefix.
2.) add the path to the import library under "search directories" -> linker
3.) put the DLL into your application directory.

BTW: This has been told a lot on this forum although it's not really related to C::B. I can only suggest to everybody:  Learn how a compiler / linker works before you start using (any) IDE. Use the command line to get the basic skills, then use the IDE to automise the boring stuff. Otherwise you will sooner or later be lost again.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline kerstin

  • Single posting newcomer
  • *
  • Posts: 5
Re: How to include an external lib and dll ???
« Reply #4 on: September 08, 2008, 09:46:17 am »
Thanks a lot , I think he found the dll now!
this is what I get now, just in case I'm wrong:

obj\Debug\skript.res   -lgdi32 -luser32 -lkernel32 -lIEICAN02 C:\Kerstin\Code_Block\ta_project_test\IEICAN02.dll C:\Kerstin\Code_Block\ta_project_test\IEICAN02.lib

But can I ask you one more thing?

I get now this error:
 obj\Debug\CAN.o: In function `ZN4CCAN16MyCAN_CountCardsEv':
C:/Kerstin/Code_Block/ta_project_test/CAN.CPP:20: undefined reference to `_imp___Z14CAN_CountCardsv@0'

this function (countCards) are defined in the lib I just included, (he finds the .h file). so why is it still an undefined reference?


Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9657
Re: How to include an external lib and dll ???
« Reply #5 on: September 08, 2008, 10:02:09 am »
-lIEICAN02 C:\Kerstin\Code_Block\ta_project_test\IEICAN02.dll C:\Kerstin\Code_Block\ta_project_test\IEICAN02.lib
You seem not to understand what I was trying to tell you, so I "translate" what you tell the linker with this command line:

1.) link against the import library IEICAN02(.lib) (correct)
2.) link against the object file IEICAN02.dll --> wrong in two ways: a) this is not an object file b) you don't need to link against this DLL at all as you have an import library.
3.) link against the object file IEICAN02.lib --> wrong in two ways: a) this is not an object file b) you don't need to link against this library again. You did this already with 1.)

Honestly: Do what I told you, read the compiler's manual. You will get stuck over and over again. I am telling you! I was right in the last post -> you got stuck again because you did not listen to me. I won't tell again.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline kerstin

  • Single posting newcomer
  • *
  • Posts: 5
Re: How to include an external lib and dll ???
« Reply #6 on: September 08, 2008, 01:05:28 pm »
Sorry but I have to annoy you again. I tried to read some stuff up know, but it didn't really help.

I followed your steps again, and hopefully I have know what you suggested, but I still get the same error:

mingw32-g++.exe  -o bin\Debug\ta_project_test.exe obj\Debug\AbrechnungStatMenu.o obj\Debug\AdminMenu.o obj\Debug\BMP.o obj\Debug\BasisDialog.o obj\Debug\CAN.o obj\Debug\CCANDaten.o obj\Debug\CDaten.o obj\Debug\CDebug.o obj\Debug\CSVDatei.o obj\Debug\CTADaten.o obj\Debug\CThread.o obj\Debug\CZustand.o obj\Debug\CZustandBMWApp.o obj\Debug\CZustandInit.o obj\Debug\CZustandTAApp.o obj\Debug\DrawTool.o obj\Debug\EinstellungenMenu.o obj\Debug\Fahrt.o obj\Debug\FahrtenlisteMenu.o obj\Debug\Filter.o obj\Debug\INIDatei.o obj\Debug\LogikThread.o obj\Debug\MathTool.o obj\Debug\Ringpuffer.o obj\Debug\Schrift.o obj\Debug\TA_VorVersion_07App.o obj\Debug\TarifeMenu.o  obj\Debug\skript.res   -lgdi32 -luser32 -lkernel32 -lIEICAN02
obj\Debug\CAN.o: In function `ZN4CCAN16MyCAN_CountCardsEv':
C:/Kerstin/Code_Block/ta_project_test/CAN.CPP:20: undefined reference to `_imp___Z14CAN_CountCardsv@0'
obj\Debug\CAN.o: In function `ZN4CCAN19MyCAN_ReadBoardInfoEtP14CAN_BOARD_INFO':

I tried the console already last week, but I'm not really good at. So please have you another idea for me, beside using the console?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9657
Re: How to include an external lib and dll ???
« Reply #7 on: September 08, 2008, 02:45:21 pm »
C:/Kerstin/Code_Block/ta_project_test/CAN.CPP:20: undefined reference to `_imp___Z14CAN_CountCardsv@0'
obj\Debug\CAN.o: In function `ZN4CCAN19MyCAN_ReadBoardInfoEtP14CAN_BOARD_INFO':
It's hard to tell as I don't know your CAN SDK. Is the *.lib file *really* the import library for the DLL? Is that really all you need? (Is there a bas library you need to add, too)? Do you mix compilers (e.g. using MinGW/GCC for the application build but the rest was build with another compiler)?

There are too much "unknows" to me so I am not in a position to help you. You should ask the developer of the "IEICAN02" library (SDK?!) for help, not me.

If you are an "expert" you could also try to use the symbol table plugin of C::B to analyse which symbols are actually being exported in the library (and probably the DLL). You could also try to link *only* against the DLL (it sounds strange, but MinGW/GCC can do that!) if it's a compiler mismatch error. MinGW/GCC can handle VC libraries just fine usually but I simply don't know sure how the lib/DLL was built.

Sorry, but I can't help more. It's like asking for the content of a blackbox I don't know. Even worse: It's actually *not* a C::B issue so we are violating our forum rules in addition.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline kerstin

  • Single posting newcomer
  • *
  • Posts: 5
Re: How to include an external lib and dll ???
« Reply #8 on: September 08, 2008, 02:56:37 pm »
Thanks for your help, anyway!!!
At least I know now, that the lib and dll is correct included. Thats something too  :lol:
Kerstin

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9657
Re: How to include an external lib and dll ???
« Reply #9 on: September 08, 2008, 04:04:56 pm »
At least I know now, that the lib and dll is correct included. Thats something too  :lol:
A quick google search revealed this:
http://icp-nmr.com/iei/download/manual/expansion/M_ICAN-02_ENG.pdf
If we are talking about this one and you are in a critical development environment you should really use the MS compiler suite. The library is designed for MS compiler. You can still use C::B (if you like). ;-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ