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. ATL / WTL / STL
  4. hello i have a question about #include

hello i have a question about #include

Scheduled Pinned Locked Moved ATL / WTL / STL
c++question
4 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.
  • L Offline
    L Offline
    lxlenovostar
    wrote on last edited by
    #1

    these code is :

    //In.h
    int sum(int a, int b);

    //In.cpp

    #include "In.h"

    int sum(int a, int b)
    {
    return (a+b);
    }

    //test05.cpp

    #include "iostream"
    #include "In.h"
    using namespace std;

    int main()
    {
    int a = sum(1, 2);
    cout << a << endl;
    }

    when i complier test05.cpp, it will have a question : ~/cpp/test$ g++ -o test05 test05.cpp /tmp/ccW55H4p.o: In function `main': test05.cpp:(.text+0x19): undefined reference to `sum(int, int)' collect2: ld returned 1 exit status give me some advides thank you

    L 1 Reply Last reply
    0
    • L lxlenovostar

      these code is :

      //In.h
      int sum(int a, int b);

      //In.cpp

      #include "In.h"

      int sum(int a, int b)
      {
      return (a+b);
      }

      //test05.cpp

      #include "iostream"
      #include "In.h"
      using namespace std;

      int main()
      {
      int a = sum(1, 2);
      cout << a << endl;
      }

      when i complier test05.cpp, it will have a question : ~/cpp/test$ g++ -o test05 test05.cpp /tmp/ccW55H4p.o: In function `main': test05.cpp:(.text+0x19): undefined reference to `sum(int, int)' collect2: ld returned 1 exit status give me some advides thank you

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You need to include In.cpp in your build thus:

      ~/cpp/test$ g++ -o test05 test05.cpp In.cpp

      Just say 'NO' to evaluated arguments for diadic functions! Ash

      L 1 Reply Last reply
      0
      • L Lost User

        You need to include In.cpp in your build thus:

        ~/cpp/test$ g++ -o test05 test05.cpp In.cpp

        Just say 'NO' to evaluated arguments for diadic functions! Ash

        L Offline
        L Offline
        lxlenovostar
        wrote on last edited by
        #3

        thank you very much

        L 1 Reply Last reply
        0
        • L lxlenovostar

          thank you very much

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          You're welcome. If you get bored some dark night you might want to read some of the documentation on g++, I think g++ --help gives you quite a lot of information.

          Just say 'NO' to evaluated arguments for diadic functions! Ash

          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