October 29, 2025, 10:39:25 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Unresolved external error

Started by LarryMc, April 18, 2009, 12:36:56 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LarryMc

Got a Unresolved external error problem that I just can't see the cause of.

I use Fletchie's ctl.inc in almost every program I write.

I created a static library which has the following in it:$include "windows.inc"
$use "msimg32.lib"
$include "ctl.inc"

It compiles fine.
I put it in the ebdev\libs dir  cblm2.lib is the lib name

I have a CBLM2.inc file that contains:$use "CBLM2.lib"
This is to be put in any application that uses the lib.

I have an application that has the include file in it:$include "CBLM2.inc"

When I compile my application I get the Unresolved external error for the SplitTwo function in Fletchie's library.
The application doesn't use anything from Fletchie's lib.
Only the static lib CBLM2.lib uses that function.

If I add $include "ctl.inc" to the application, which doesn't use it, then the unresolved goes away.

Any ideas.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

Larry,
First..static libraries don't $USE anything, so the statement will do nothing.

Remember how compiling works.

Source->Assember->Object

At this point the object file has unresolved references that must be taken care of by the linker.  When you make a static library what you have is a collection of objects waiting to be linked.

Source1->Asm1->Object1
Source2->Asm2->Object2
Source3->Asm3->Object3
Static Library = Object1+Object2+Object3 (call it myllib.lib)

Think of the static library as just a .zip file containing those three separate object files, because in essence that is what it really is, the AR archiver makes an archive of the objects and gives it a header, which is just a directory of the objects contained in the static library.

Then when you $use a static library in your program, and you are building an executable the linker is invoked:

Mysource.eba->Mysource.asm->Mysource.o(bject)
Link: Mysource.o + mylib.lib + (any $USE libraries) + (All standard libraries) = Mysource.exe

Now onto your problem.....  The first line of ctl.inc is:

$use "ctl.lib"

Which will be ignored when you are making a static library, since the linker is not involved. So the reference to SplitTwo will remain unresolved until the linker is invoked, which only happens when you make an executable or DLL.

So how do you get around this?

#1.  You have to $use "ctl.lib" in your program, (or just $include "ctl.inc" as you did)
#2.  You could add ctl.lib to your static library project, but that may cause issues if the person using your static library also uses ctl.
#3.  You could use the source for SplitTwo in your static library directly so there is no reference to be resolved.

Paul.


Ionic Wind Support Team

LarryMc

thanks for the excellent explanation

BTW
QuoteYou could use the source for SplitTwo in your static library directly so there is no reference to be resolved.

I don't have the source(that I know of)

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

Larry, I have the sources on another HDD, but am unable to connect it now.
Try this if you want to include the splittwo in your library:

1. Open the command prompt and navigate to directory with ctl.lib.
2. Update D:\EBDev\bin to you path in this script, and type all this into the command interpreter:
set path=D:\EBDev\bin
ar -x ctl.lib SplitTwo.o

ar -x will extract the object file with SplitTwo function.
3. Copy SplitTwo.o to directory with your project, then add the copied file into the project. Compile.
Now your static library includes the SplitTwo function.

LarryMc

I had just sent you an email about that.

It appears your bag of tricks is bottomless.

Thanks

Larry

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library