LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-29-2004, 10:39 PM   #1
santiagom5
LQ Newbie
 
Registered: Jan 2004
Posts: 5

Rep: Reputation: 0
compiling header files with anjuta


hi, i'm new to linux. i''m using redhat 9 and have installed anjuta to create c++ programs. i'm trying to compile the header files i'm using for one of my proects, but when trying to compile, i get the error msg:

"No compile command has been specified for this type of file."

what do i need to do to compile my header files.
 
Old 01-29-2004, 10:48 PM   #2
UltimaGuy
Member
 
Registered: Aug 2003
Location: Chennai, India
Distribution: PCLinuxOS .92, FC4
Posts: 840

Rep: Reputation: 31
Header files are not compiled. Compilers will give out an error if you try to compile header files. After creating an header, just call it from your program, and see how it works. An other way is to just create declarations in the header file and put all the definitions in another file and create an object or shared object of that definition file.
 
Old 01-29-2004, 10:51 PM   #3
santiagom5
LQ Newbie
 
Registered: Jan 2004
Posts: 5

Original Poster
Rep: Reputation: 0
i see..thks for the info...much appreciated...
 
Old 01-30-2004, 12:31 AM   #4
santiagom5
LQ Newbie
 
Registered: Jan 2004
Posts: 5

Original Poster
Rep: Reputation: 0
hi ultima guy,
i tried what you suggested, but got the following error when i created 3 main files for my program (1 containing the header, 1 containinng the implementation, and the main.cc)

undefined reference to "the class object i'm trying to create in main.cpp"
here is the header file:
#include<iostream.h>
typedef int ListItemType;



class List
{
public:

List();
List(const List &aList);
~List();

bool isEmpty() const;
int getLength() const;
void insert(int index, ListItemType newItem);
void remove(int index);
void retreive(int index, ListItemType& dataItem) const;


private:
struct ListNode
{
ListItemType item;
ListNode *next;
};

int size;
ListNode *head;

ListNode *find(int index) const;

};

here is the implementation:
#include<iostream.h>
#include "/home/cipher/Projects/mjtest/src/headerfile.h"

List::List(): size(0), head(NULL)
{
}



List::~List()
{
while(!isEmpty())
remove(1);

}

bool List::isEmpty() const
{
return bool(size == 0);
}

int List::getLength() const
{
return size;
}

List::ListNode *List::find(int index) const
{
if((index < 1) || (index > getLength()))
return NULL;

else
{
ListNode *cur = head;
for(int skip = 1; skip < index; ++skip)
cur = cur->next;
return cur;
}
}

void List::retreive(int index, ListItemType& dataItem) const
{
if((index < 1) || (index > getLength()))
;
else
{
ListNode *cur = find(index);
dataItem = cur->item;
}

}

void List::insert(int index, ListItemType newItem)
{
int newLength = getLength() + 1;

if((index < 1) || (index > newLength))
;
else
{
ListNode *newPtr = new ListNode;
if(newPtr == NULL)
;
else
{

size = newLength;
newPtr->item = newItem;

if(index == 1)
{
newPtr->next = head;
head = newPtr;
}

else
{
ListNode *prev = find(index - 1);
newPtr->next = prev->next;
prev->next = newPtr;
}
}
}
}

void List::remove(int index)
{
ListNode *cur;

if((index < 1) || (index > getLength()))
;
else
{
--size;
if(index == 1)
{
cur = head;
head = head->next;
}
else
{
ListNode *prev = find(index - 1);
cur = prev->next;
prev->next = cur->next;
}
cur->next = NULL;
delete cur;
cur = NULL;
}
}

here is the main file:

#include <iostream.h>
#include "/home/cipher/Projects/mjtest/src/headerfile.h"

int main()

{
List aList;
ListItemType dataItem;

aList.insert(1,20);
aList.retreive(1, dataItem);
return 0;
}


i'm getting the following error:
undefined reference to 'List::List[in-charge]()'

i tried doing the same thing in Visual C++ and didn't experience this problem
any help would be appreciated....
 
Old 01-30-2004, 12:40 AM   #5
UltimaGuy
Member
 
Registered: Aug 2003
Location: Chennai, India
Distribution: PCLinuxOS .92, FC4
Posts: 840

Rep: Reputation: 31
Hi santiagom5,

I said that ou don't have to compile the header file. But you have to compile the implementation file. Compile it as an object by 'g++ -c implfile.cpp'

You'll get a file called 'implfile.o'

Now compile the main prog, by giving 'g++ main.cpp implfile.o'.

If you use the implfile regularly, then you can just add it to the standard headers.
 
Old 01-30-2004, 12:44 AM   #6
santiagom5
LQ Newbie
 
Registered: Jan 2004
Posts: 5

Original Poster
Rep: Reputation: 0
hey again,
i'm not compiling the header file. the compile works for both the implementation and the main file, but when i try to build it, is when i get the error message..i'm using anjuta 1.2.0 as my IDE
 
Old 01-30-2004, 12:57 AM   #7
UltimaGuy
Member
 
Registered: Aug 2003
Location: Chennai, India
Distribution: PCLinuxOS .92, FC4
Posts: 840

Rep: Reputation: 31
Hey again,

I don't use anjuta, so I don't know about it.

But you have to specify the object file also when compiling, like 'g++ main.cpp objectfile.o -o main'. I don't know how to do this in anjuta. Try this in a shell, and if it works, try to find for similar options in anjuta!
 
Old 01-30-2004, 12:59 AM   #8
santiagom5
LQ Newbie
 
Registered: Jan 2004
Posts: 5

Original Poster
Rep: Reputation: 0
i'll try it out..tks again
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
problem about compiling anjuta 2.0.1 in SLES 9 hongxing SUSE / openSUSE 7 10-19-2005 08:19 AM
problem about compiling anjuta hongxing SUSE / openSUSE 1 10-12-2005 01:09 AM
Compiling C++ Header Files ?? JinBaba Programming 3 07-20-2005 03:23 AM
c header files in linux in place of header files in windows? harun_acs Programming 1 03-17-2004 02:24 AM
problem in compiling anjuta freeindy Programming 1 01-21-2004 04:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration