Author Topic: Include External Object File in to Project  (Read 8909 times)

ThomasG

  • Guest
Include External Object File in to Project
« on: August 15, 2005, 05:34:33 pm »
Hi,

I just made the transition to Code::Blocks. I think is a very good program. But now I run into an issue. I imported a Visual C++ Solution in to Code::Blocks. When I try to compile it, then I get the following:

Code
Release/dongle.o:dongle.c:(.text+0x62): undefined reference to `KFUNC'
collect2: ld returned 1 exit status
make.exe: *** [Release/IMS7_DLL.dll] Error 1

That function is declared in a header file as

Code
// KEYBD and KFUNC are resolved by linking with KL2.OBJ
extern unsigned  KEYBD(unsigned);
extern unsigned int __cdecl far GETLASTKEYERROR(void);
extern unsigned long KFUNC(unsigned, unsigned, unsigned, unsigned);

What do I have to do, to include the KL2.obj file in the project?

It must be possible to get the project running with the GCC Compiler, since I had it once running with Dev-C++, but I don't have the sources anymore.

Thanks for any help in advance.

Regards,
Thomas

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Include External Object File in to Project
« Reply #1 on: August 15, 2005, 05:49:39 pm »
Normally you'd have to include KL2.c (the sourcefile) in your project and let codeblocks handle the dependency stuff.

But right now, you don't have the source code, so the only solution is to make a library out of KL2 (call it KL2.LIB). And include KL2.LIB in your project's linker libraries. (See why it's better to keep the sources? ;-) )

Oh, now that I remember, I recall there's a C decompiler out there in the web. You'd get a nasty, ugly C file, but hey, at least you could recompile it! ;-)

ThomasG

  • Guest
Re: Include External Object File in to Project
« Reply #2 on: August 15, 2005, 06:58:56 pm »
I would like to have the C code, but it's a library we bought, and they will not give that source code out for several reasons. Since it is working with the Visual C++ 2003 and it was working with Dev-C++, there must be a way to get it working in Code::Blocks too. I guess, I'm missing just a setting somewhere.

Thomas

Offline Urxae

  • Regular
  • ***
  • Posts: 376
Re: Include External Object File in to Project
« Reply #3 on: August 15, 2005, 07:25:03 pm »
Well, if it worked with Dev-C++, it can probably be done by going to Build options -> <your target or project> -> Linker -> Other linker options, and add whatever Dev-C++ adds to the command line in that text box.

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Include External Object File in to Project
« Reply #4 on: August 15, 2005, 07:26:40 pm »
You did know libraries are composed out of .obj files, didn't you? I don't remember the name of the microsoft tool, but you CAN convert .obj's into .lib's.

So it's just matter of converting your .obj into .lib, and adding it to the project link libraries. object files are meant to be temporary objects (either to create libs, or exes), not to be used as libraries themselves.

grv575

  • Guest
Re: Include External Object File in to Project
« Reply #5 on: August 15, 2005, 10:05:19 pm »
Wouldn't you need to use ar.exe and ranlib.exe (gcc).

 You could just try passing the name of the.o file to the linker other options as was mentioned, but be careful  - not sure if a rebuildwill delete all .o files

ThomasG

  • Guest
Re: Include External Object File in to Project
« Reply #6 on: August 16, 2005, 02:19:05 am »
Hi,

I figured out what to do. I found my old Dev-C++ project where the stuff was working. I imported it and looked at the Linker settings. Thanks Urxae for the hint, it helped. I attached a screen shot of my settings that made it working.



Thanks for your help guys,
Thomas