BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

help building, using static library

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Command Line Tools)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Tue Jan 30, 2007 1:21 am    Post subject: help building, using static library Reply with quote



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.
Back to top
Alan Bellingham
Guest





PostPosted: Tue Jan 30, 2007 2:32 am    Post subject: Re: help building, using static library Reply with quote



mark_ngp (AT) yahoo (DOT) com wrote:

Quote:
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."

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.)

Alan Bellingham
--
Team Thai Kingdom
<url:http://www.borland.com/newsgroups/> Borland newsgroup descriptions
<url:http://www.borland.com/newsgroups/netiquette.html> netiquette
Back to top
Ed Mulroy
Guest





PostPosted: Tue Jan 30, 2007 4:00 am    Post subject: Re: help building, using static library Reply with quote



FYI:

Quote:
...What does -WCR do ...
-WCR is equivalent to saying -WR -WC, dynamic linked, console mode.


Quote:
...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

Quote:
Alan Bellingham wrote in message
news:j2msr2554ht7t17274qm4o1ibe8lk9natc (AT) 4ax (DOT) 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.)
Back to top
Guest






PostPosted: Tue Jan 30, 2007 4:10 am    Post subject: Re: help building, using static library Reply with quote

On Jan 29, 3:32 pm, Alan Bellingham <a...@episys.com> wrote:

Quote:
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.
Back to top
Ed Mulroy
Guest





PostPosted: Tue Jan 30, 2007 4:12 am    Post subject: Re: help building, using static library Reply with quote

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
Quote:
build

C:\Documents and Settings\Edward\My Documents\lookat\q203
Quote:
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
Quote:
tlib /C Hello.lib -+hello.obj
TLIB 4.5 Copyright (c) 1987, 1999 Inprise Corporation


C:\Documents and Settings\Edward\My Documents\lookat\q203
Quote:
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
Quote:
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
Quote:
myprog
Begin program...

Hello there!
End program...

C:\Documents and Settings\Edward\My Documents\lookat\q203
Quote:


-----------------------------------------------------------------------------

.. Ed

Quote:
mark_ngp wrote in message
news:1170098514.405938.288330 (AT) v45g2000cwv (DOT) 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.
Back to top
Guest






PostPosted: Tue Jan 30, 2007 5:01 am    Post subject: Re: help building, using static library Reply with quote

On Jan 29, 5:12 pm, "Ed Mulroy" <dont_email...@bitbuc.ket> wrote:

Quote:
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.
Back to top
wasknijper
Guest





PostPosted: Wed Jan 31, 2007 12:40 am    Post subject: Re: help building, using static library Reply with quote

mark_ngp (AT) yahoo (DOT) com wrote:

Quote:
#include <iostream

Could it be that the commandline compiler only knows <iostream.h>?

w.
Back to top
Ed Mulroy
Guest





PostPosted: Wed Jan 31, 2007 1:24 am    Post subject: Re: help building, using static library Reply with quote

Quote:
#include <iostream

Could it be that the commandline compiler only knows <iostream.h>?

As you can see from the screen capture below, C++ Builder 5.5 does
understand it.

.. Ed

----------------------------
C:\Documents and Settings\Edward\My Documents\lookat\q203
Quote:
build55

C:\Documents and Settings\Edward\My Documents\lookat\q203
Quote:
\borland\bcc55\bin\bcc32 -v -c -WCR hello.cpp
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland

hello.cpp:

C:\Documents and Settings\Edward\My Documents\lookat\q203
Quote:
\borland\bcc55\bin\tlib /C Hello.lib -+hello.obj
TLIB 4.5 Copyright (c) 1987, 1999 Inprise Corporation

Warning: 'hello' not found in library

C:\Documents and Settings\Edward\My Documents\lookat\q203
Quote:
\borland\bcc55\bin\bcc32 -v -c -WCR main.cpp
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland

main.cpp:

C:\Documents and Settings\Edward\My Documents\lookat\q203
Quote:
\borland\bcc55\bin\ilink32 /Tpe/ap/Gn/x/c/v c0x32 main.obj,
myprog.exe, ,Hello.lib \borland\bcc55\lib\import32.lib

\borland\bcc55\lib\cw32i.lib
Turbo Incremental Link 5.66 Copyright (c) 1997-2002 Borland

C:\Documents and Settings\Edward\My Documents\lookat\q203
Quote:
myprog
Begin program...

Hello there!
End program...

C:\Documents and Settings\Edward\My Documents\lookat\q203
Quote:

----------------------------


Quote:
wasknijper wrote in message
news:45bf90d8$1 (AT) newsgroups (DOT) borland.com...
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Command Line Tools) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.