linking two file in gcc
-
hello i tried to link this two file:
#include<list.h> template <class T>class hash{ public: list<int> *l; int m,n;//k is the entry and m is number of slots and n is the size of our array hash(){ l=new list<T>[n]; n=m=0; } hash(int n1,int m1){ n=n1; m=m1; l=new list<T>[n]; } int hashfunct(T k){ return k % m; } void print_hash (){ for(int i=0;i<n;i++) while(!l[i].empty()){ cout<<"l["<<i<<"]="<<l[i].front()<<" "; l[i].pop_front(); cout<<endl; } } list<T>* add_to_hash(T k){ int key=h.hashfunct(k); l[key].push_front(k); return l; } }; and the main program: #include<iostream> #include<stdlib.h> #include "/home/sajad/src/ds/test/hashfunctions/hash.h " using namespace std; int main(){ int n; int m; cout<<"please enter n(number of entries):"<<endl; cin>>n; cout<<"please enter m(the dividisor number,must be near n):"<<endl; cin>>m; int a[n]; for(int i=0;i<n;i++) a[i]=0; hash<int>h(n,m); cout<<"please enter n numbers:"<<endl; for(int i=0;i<n;i++){ cin>>a[i]; h.add_to_hash(a[i]); } cout<<"after hashing:"<<endl; h.print_hash(); return 0; }
the address of hash.h is completely true but i face this error: [sajad@sajad hashfunctions]$ g++ my\ hashing.cpp my hashing.cpp:4:57: error: /home/sajad/src/ds/test/hashfunctions/hash.h : No such file or directory my hashing.cpp: In function ‘int main()’: my hashing.cpp:16: error: ‘hash’ was not declared in this scope my hashing.cpp:16: error: expected primary-expression before ‘int’ my hashing.cpp:16: error: expected ‘;’ before ‘int’ my hashing.cpp:20: error: ‘h’ was not declared in this scope my hashing.cpp:23: error: ‘h’ was not declared in this scope [sajad@sajad hashfunctions]$ can anyine help me? thnx.
-
hello i tried to link this two file:
#include<list.h> template <class T>class hash{ public: list<int> *l; int m,n;//k is the entry and m is number of slots and n is the size of our array hash(){ l=new list<T>[n]; n=m=0; } hash(int n1,int m1){ n=n1; m=m1; l=new list<T>[n]; } int hashfunct(T k){ return k % m; } void print_hash (){ for(int i=0;i<n;i++) while(!l[i].empty()){ cout<<"l["<<i<<"]="<<l[i].front()<<" "; l[i].pop_front(); cout<<endl; } } list<T>* add_to_hash(T k){ int key=h.hashfunct(k); l[key].push_front(k); return l; } }; and the main program: #include<iostream> #include<stdlib.h> #include "/home/sajad/src/ds/test/hashfunctions/hash.h " using namespace std; int main(){ int n; int m; cout<<"please enter n(number of entries):"<<endl; cin>>n; cout<<"please enter m(the dividisor number,must be near n):"<<endl; cin>>m; int a[n]; for(int i=0;i<n;i++) a[i]=0; hash<int>h(n,m); cout<<"please enter n numbers:"<<endl; for(int i=0;i<n;i++){ cin>>a[i]; h.add_to_hash(a[i]); } cout<<"after hashing:"<<endl; h.print_hash(); return 0; }
the address of hash.h is completely true but i face this error: [sajad@sajad hashfunctions]$ g++ my\ hashing.cpp my hashing.cpp:4:57: error: /home/sajad/src/ds/test/hashfunctions/hash.h : No such file or directory my hashing.cpp: In function ‘int main()’: my hashing.cpp:16: error: ‘hash’ was not declared in this scope my hashing.cpp:16: error: expected primary-expression before ‘int’ my hashing.cpp:16: error: expected ‘;’ before ‘int’ my hashing.cpp:20: error: ‘h’ was not declared in this scope my hashing.cpp:23: error: ‘h’ was not declared in this scope [sajad@sajad hashfunctions]$ can anyine help me? thnx.
Well, the error message is actually very clear: the path
/home/sajad/src/ds/test/hashfunctions/hash.h
is wrong. BTW Why don't you use relative paths? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Well, the error message is actually very clear: the path
/home/sajad/src/ds/test/hashfunctions/hash.h
is wrong. BTW Why don't you use relative paths? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
i also used #include "hash.h" but yet this takes error!!!
modified on Friday, January 8, 2010 3:58 AM
If the path is wrong then it is wrong (and the preprocessor cannot include the header file). Go to the folder containing the header file and type
pwd
(I'm assuming you're developing for a Linux or Unix machine) to see the correct path. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
If the path is wrong then it is wrong (and the preprocessor cannot include the header file). Go to the folder containing the header file and type
pwd
(I'm assuming you're developing for a Linux or Unix machine) to see the correct path. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
[sajad@sajad hashfunctions]$ pwd /home/sajad/src/ds/test/hashfunctions that this is the last location in the file header.
khomeyni wrote:
#include "/home/sajad/src/ds/test/hashfunctions/hash.h "
I see an extra space at the end of the string... :rolleyes:
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
khomeyni wrote:
#include "/home/sajad/src/ds/test/hashfunctions/hash.h "
I see an extra space at the end of the string... :rolleyes:
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]