At 14.11 09/25/02 -0400, "Santiago" <sa...@ho...> wrote:
>Does anyone know how to link an implementation file (ie: Myclass.C) with a
>client code (ie: usingClasses.C) so they can use my own Myclass.h header file?
>This is weird, I tried doing it in a G++ compiler on a solaris unix
>terminal at school and it worked. However, the same exact code didn't work
>in Dev-cpp. I know there are other options like console application or
>empty project and I don't know how to use those.
>Please let me know the correct way to link an implementation and a client
>code so they can use my own defined class.
>
>Thank you very much.
>
>Santiago
Hello Santiago,
It looks to me that your problem is the following.
You have a program whose code is in the files (allow me not to use
uppercase in filenames, my Win98SE being case insensitive):
- myclass.h = class interface
- myclass.c = class implementation
- usingclasses.c = client
and wish to make the executable file usingclasses.exe.
A solution could be using the command line (I have MinGW gcc 3.2):
c++ usingclasses.c myclass.c -o usingclasses.exe
I find the above feasible if a very small amount of files, all placed in
one directory, is involved. When one has many files, typing all the names
may become tedious and error prone. So here is where one uses a Dev-C++
"project". I'll give instructions to create a simple console application
project (with Dev-C++ 4.9.5.0), assuming you have already edited the 3 unit
files.
-1- start Dev-C++
-2- File->New->Project: choose console application and give it a name (say
"mytest")
-3- Project->Remove from Project: select "main.cpp" and click on "OK". You
do not need the default "main.cpp" file
since you already have your "main" function in usingclasses.c
-4- Project->Add to Project: select the file usingclasses.c and click on
"open", do the same for myclass.c. There
is no point in adding the header file myclass.h to the project (other
than willing to quickly open it by
clicking on its name in the project window)
-5- Execute->Compile: after compiling is over (and there is no error) you
should see "mytest.exe".
As you see adding many files to a project is easy if they are all placed in
the same directory, looking for a not so small amount of files, chasing
them in many directories is something I tend to avoid. Since I personally
keep my source files in many directories, I don't use Dev-C++ projects that
much, rather I use an approach which many term "obsolete" (I prefer to call
it "traidtional" :).
Here is what I do:
- write a makefile (a bit different from the one Dev-C++ generates), for
this I use a "home-made" makefile
generator
- use the command line to compile the file; of course having the makefile
this is as easy as typing: "make".
I attempted to write the makefile generator as portable as I could and
generally use it on my Linux box (together with GNU tools) I've also used
it on Windows with both GNU tools and Borland tools. Some small changes to
the code were required, to cope with differen "make" syntax. I would be
pleased if you could spend a little of your time trying it on the Solaris
machine at your disposal and let me knowing if it works.
In case you are interested I'll send you the code.
Regards
--
gisan
|