Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. linking two file in gcc

linking two file in gcc

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++data-structurescryptography
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    khomeyni
    wrote on last edited by
    #1

    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.

    CPalliniC 1 Reply Last reply
    0
    • K khomeyni

      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.

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      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]

      In testa che avete, signor di Ceprano?

      K 1 Reply Last reply
      0
      • CPalliniC CPallini

        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]

        K Offline
        K Offline
        khomeyni
        wrote on last edited by
        #3

        i also used #include "hash.h" but yet this takes error!!!

        modified on Friday, January 8, 2010 3:58 AM

        CPalliniC 1 Reply Last reply
        0
        • K khomeyni

          i also used #include "hash.h" but yet this takes error!!!

          modified on Friday, January 8, 2010 3:58 AM

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          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]

          In testa che avete, signor di Ceprano?

          K 1 Reply Last reply
          0
          • CPalliniC CPallini

            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]

            K Offline
            K Offline
            khomeyni
            wrote on last edited by
            #5

            [sajad@sajad hashfunctions]$ pwd /home/sajad/src/ds/test/hashfunctions that this is the last location in the file header.

            CPalliniC 1 Reply Last reply
            0
            • K khomeyni

              [sajad@sajad hashfunctions]$ pwd /home/sajad/src/ds/test/hashfunctions that this is the last location in the file header.

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #6

              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]

              In testa che avete, signor di Ceprano?

              K 1 Reply Last reply
              0
              • CPalliniC CPallini

                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]

                K Offline
                K Offline
                khomeyni
                wrote on last edited by
                #7

                oh ... excuse me ,i test it with devcpp and it does not have any error with it!!! :-D thanx.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups