Re: [Dev-C++] doubts about creating static libs and using them
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <sol...@ya...> - 2003-07-16 16:56:51
|
You don't have to type class when declaring an object.
You must include the header file in the program you're building.
See below and at the end.
Dark Kernel (InacioW-) wrote:
> Hi.
> I´ve created the lib called libTest, wich contains
>the following:
>
>#include <iostream.h>
>
>class Test
>{
>public:
> Test();
>};
>
>Test::Test()
>{
> cout << " this is a test";
>}
>
>the file was well-compiled and generated a file called
>libTest.a, wich I can add to the linker and use in
>other program, but I have no Idea about how make a
>reference of the methods.
>
>I tried
>
>
>#include <iostream>
>#include <stdlib.h>
>
>using namespace std;
>
>
>
>class Test; <----- This line has not to be there. And you shall
#include the header where that class is defined
>class Teste * test1; <-----First you say Teste, when you haven''t any
class named Teste, you have the class named Test.
>extern Teste::Teste();
>
>int main(int argc, char *argv[])
>{
> teste1 = new Teste(); // <- the compiler points me
>an error here ... :(
>
> system("PAUSE");
> return 0;
>}
>
>so, what´s goind wrong?
>someone can help me?
>
>thanks anyway,
>
>__________________________________________________________________
>
>Gesendet von Yahoo! Mail - http://mail.yahoo.de
>Logos und Klingeltöne fürs Handy bei http://sms.yahoo.de
>
>
>-------------------------------------------------------
>This SF.net email is sponsored by: VM Ware
>With VMware you can run multiple operating systems on a single machine.
>WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the
>same time. Free trial click here: http://www.vmware.com/wl/offer/345/0
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
>
You should do:
File 1: header of test library, test.h
#ifndef TEST_H
#define TEST_H
class Test{
Test();
};
#endif
File 2: source file of test: library, test.cpp
#include <iostream>
#include <test.h>
Test::Test(){
std::cout << "This is a test" << endl;
}
Then you select both files into a static library project and compile it.
You build the library libtest.a.
After that you write your test program, test_program.cpp:
#include <test.h>
#include <stdlib.h>
int main(){
Test *test_object = new Test();
system("PAUSE");
return 0;
}
Then you compile it with the option -ltest for linker.
|