LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   compiling header files with anjuta (https://www.linuxquestions.org/questions/linux-software-2/compiling-header-files-with-anjuta-140217/)

santiagom5 01-29-2004 10:39 PM

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.

UltimaGuy 01-29-2004 10:48 PM

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.

santiagom5 01-29-2004 10:51 PM

i see..thks for the info...much appreciated...

santiagom5 01-30-2004 12:31 AM

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

UltimaGuy 01-30-2004 12:40 AM

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.

santiagom5 01-30-2004 12:44 AM

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

UltimaGuy 01-30-2004 12:57 AM

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!

santiagom5 01-30-2004 12:59 AM

i'll try it out..tks again


All times are GMT -5. The time now is 07:28 PM.