|
| help building, using static library |
 |
29 Jan 2007 11:21:54 -0800 |
I am trying to gain some understanding in builing and using
libraries. I have the following files.
// ----- hello.h -----
#ifndef HELLO_H
#define HELLO_H
void SayHello();
#endif
// ----- hello.cpp -----
#include "hello.h"
#include <iostream>
void SayHello()
{ std::cout << "Hello there!" << std::endl; }
// ----- main.cpp -----
#include <iostream>
#include "hello.h"
int main()
{
std::cout << "Begin program..." << std::endl;
SayHello();
std::cout << "End program..." << std::endl;
return 0;
}
What I am trying to do as a learning exercise is build a static
library containing SayHello() and then create a console app which uses
that library. To keep the size of the console application down, I'm
interested in targeting the cc3250.dll. Here are the commands I ran
and their output:
C:\MyCode\libtest>bcc32 -c hello.cpp
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
hello.cpp:
C:\MyCode\libtest>tlib /C Hello.lib -+hello.obj
TLIB 4.5 Copyright (c) 1987, 1999 Inprise Corporation
Warning: 'hello' not found in library
C:\MyCode\libtest>bcc32 -c -WCR main.cpp
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
main.cpp:
C:\MyCode\libtest>ilink32 /Tpe/ap/Gn/x/c c0x32 main.obj, myprog.exe, ,
Hello.lib import32.lib cw32i.lib
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
As you can see, no errors are reported (the warning reported by tlib
is apparently normal), but when I try to run myprog.exe, "Begin
program..." is output to my screen, but then an error window pops up,
saying "myprog.exe has encountered a problem and needs to close."
Clearly, I'm doing something wrong. Given when the run-time error
occurs, I believe my problem has to do with the fact that my library
invokes std::cout from the standard libary and that I've somehow
failed to link to it properly. That's just a guess -- I'm a complete
novice when it comes to static and dynamic libraries. So is the
general premise of my goal -- building a static library and using it
within an application that targets the cc3250.dll -- flawed? If not,
do I have to link something else into my library to have cout
available within it? Any help would be appreciated. Thanks.
|
| Post Reply
|
| Re: help building, using static library |
 |
29 Jan 2007 14:10:56 -0800 |
On Jan 29, 3:32 pm, Alan Bellingham <a...@episys.com> wrote:
> What does -WCR do (this machine doesn't currently have bcc installed)?
> Are you sure you can link code with and without it defined?
>
> (It appears to make the app use the DLL runtime. If part of your code
> uses the DLL runtime, and part the static runtime, you'll have
> interesting punchups.)
This is precisely what I'm trying to grasp. I'm wondering if it's
possible to create a static library that uses functionality from the
standard library, but in such a that my library does not itself
contain the standard library. Or in other words, if my intent when
building my final executable is to target the cc3250.dll (which as I
understand it contains what's needed at runtime for cout, cin, etc.),
then how can I compile and link a static library that relies on that
functionality being available via cc3250.dll? Or does the use of
standard-library functions and objects in my library then force me to
make my library a DLL?
As I mentioned, I'm a beginner when it comes to creating and using
libraries, so perhaps my understanding is flawed. I'm trying to
really understand libraries, which is why I'm attempting to explicitly
invoke the compiler and the linker as shown in my original post. I
want to see and understand the "ugly details", if you will, rather
than have those details hidden away from me by implicit calling of the
linker.
Thanks.
|
| Post Reply
|
| Re: help building, using static library |
 |
29 Jan 2007 15:01:20 -0800 |
On Jan 29, 5:12 pm, "Ed Mulroy" <dont_email...@bitbuc.ket>
wrote:
> You forgot the -WCR on the line where you compiled hello.cpp
> C:\MyCode\libtest>bcc32 -c -WCR hello.cpp
> instead of
> C:\MyCode\libtest>bcc32 -c hello.cpp
Thanks, Ed. You kindly suggest I forgot the -WCR option, however I'll
fully admit that my error was one born more of ignorance than
forgetfulness. In any case, I rebuilt everything, this time including
the -WCR option where you specified, and everything of course works
like a charm. Thanks for all your help to the community in the way of
your frequent contributions to this group and your helpful website.
|
| Post Reply
|
| Re: help building, using static library |
 |
Mon, 29 Jan 2007 17:00:50 -050 |
FYI:
> ...What does -WCR do ...
-WCR is equivalent to saying -WR -WC, dynamic linked, console mode.
> ...If part of your code uses the DLL runtime, and part the
> static runtime...
He used cw32i.lib, the dynamic version of the runtime library.
. Ed
> Alan Bellingham wrote in message
> news:j2msr2554ht7t17274qm4o1ibe8lk9natc@4ax.com...
>
> This could be down to something as basic as not using exactly the same
> compilation options on the application and the library. For instance,
> different packing options might do nasty things.
>
> What does -WCR do (this machine doesn't currently have bcc installed)?
> Are you sure you can link code with and without it defined?
>
> (It appears to make the app use the DLL runtime. If part of your code
> uses the DLL runtime, and part the static runtime, you'll have
> interesting punchups.)
|
| Post Reply
|
| Re: help building, using static library |
 |
Mon, 29 Jan 2007 17:12:35 -050 |
You forgot the -WCR on the line where you compiled hello.cpp
C:\MyCode\libtest>bcc32 -c -WCR hello.cpp
instead of
C:\MyCode\libtest>bcc32 -c hello.cpp
Here is a screen capture:
-----------------------------------------------------------------------------
C:\Documents and Settings\Edward\My Documents\lookat\q203
>build
C:\Documents and Settings\Edward\My Documents\lookat\q203
>bcc32 -v -c -WCR hello.cpp
Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland
hello.cpp:
C:\Documents and Settings\Edward\My Documents\lookat\q203
>tlib /C Hello.lib -+hello.obj
TLIB 4.5 Copyright (c) 1987, 1999 Inprise Corporation
C:\Documents and Settings\Edward\My Documents\lookat\q203
>bcc32 -v -c -WCR main.cpp
Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland
main.cpp:
C:\Documents and Settings\Edward\My Documents\lookat\q203
>ilink32 /Tpe/ap/Gn/x/c/v c0x32 main.obj, myprog.exe, ,Hello.lib
import32.lib cw32i.lib
Turbo Incremental Link 5.66 Copyright (c) 1997-2002 Borland
C:\Documents and Settings\Edward\My Documents\lookat\q203
>myprog
Begin program...
Hello there!
End program...
C:\Documents and Settings\Edward\My Documents\lookat\q203
>
-----------------------------------------------------------------------------
. Ed
> mark_ngp wrote in message
> news:1170098514.405938.288330@v45g2000cwv.googlegroups.com...
>
>I am trying to gain some understanding in builing and using
> libraries. I have the following files.
>
> // ----- hello.h -----
> #ifndef HELLO_H
> #define HELLO_H
>
> void SayHello();
>
> #endif
>
> // ----- hello.cpp -----
> #include "hello.h"
> #include <iostream>
>
> void SayHello()
> { std::cout << "Hello there!" << std::endl; }
>
> // ----- main.cpp -----
> #include <iostream>
> #include "hello.h"
>
> int main()
> {
> std::cout << "Begin program..." << std::endl;
> SayHello();
> std::cout << "End program..." << std::endl;
> return 0;
> }
>
>
> What I am trying to do as a learning exercise is build a static
> library containing SayHello() and then create a console app which uses
> that library. To keep the size of the console application down, I'm
> interested in targeting the cc3250.dll. Here are the commands I ran
> and their output:
>
> C:\MyCode\libtest>bcc32 -c hello.cpp
> Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
> hello.cpp:
>
> C:\MyCode\libtest>tlib /C Hello.lib -+hello.obj
> TLIB 4.5 Copyright (c) 1987, 1999 Inprise Corporation
> Warning: 'hello' not found in library
>
> C:\MyCode\libtest>bcc32 -c -WCR main.cpp
> Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
> main.cpp:
>
> C:\MyCode\libtest>ilink32 /Tpe/ap/Gn/x/c c0x32 main.obj, myprog.exe, ,
> Hello.lib import32.lib cw32i.lib
> Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
>
> As you can see, no errors are reported (the warning reported by tlib
> is apparently normal), but when I try to run myprog.exe, "Begin
> program..." is output to my screen, but then an error window pops up,
> saying "myprog.exe has encountered a problem and needs to
close."
>
> Clearly, I'm doing something wrong. Given when the run-time error
> occurs, I believe my problem has to do with the fact that my library
> invokes std::cout from the standard libary and that I've somehow
> failed to link to it properly. That's just a guess -- I'm a complete
> novice when it comes to static and dynamic libraries. So is the
> general premise of my goal -- building a static library and using it
> within an application that targets the cc3250.dll -- flawed? If not,
> do I have to link something else into my library to have cout
> available within it? Any help would be appreciated. Thanks.
>
|
| Post Reply
|
|
|