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. g++ Compiler not including header file

g++ Compiler not including header file

Scheduled Pinned Locked Moved C / C++ / MFC
c++hardwarequestion
5 Posts 3 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.
  • P Offline
    P Offline
    PaulS_UK
    wrote on last edited by
    #1

    Hi I am using g++ to compile on a raspberry pi. using the following the project compiles:

    g++ -c file1.cpp file2.ccp .....filen.cpp

    however using the following I get numerous messages as follows: filen.cpp: (.text+0xb73c): undefined reference to `******* etc etc etc these functions are defined in a header file in each of the file*.cpp files thus:

    #include "funcdefs.h"

    this header file is located in the same directory as the *.cpp files the header file was originally entitled FUNCDEFS.H but I changed the name to lower case funcdefs.h to stop the compiler complaining. the funcdefs file contains the following code:

    //#if !defined(FUNCDEFS_H)
    //#define FUNCDEFS_H

    #if !defined(funcdefs_h)
    #define funcdefs_h

    extern double func1 ( double f ) ;
    extern void func2 ( double *input ) ;
    //etc etc etc

    #endif

    I have tried making the preprocessor directive in the funcdefs.h file lower case (didn't make any difference) and have checked the include path using -H and it seems to find the file but cannot get it to link. Any ideas? Thanks

    J 1 Reply Last reply
    0
    • P PaulS_UK

      Hi I am using g++ to compile on a raspberry pi. using the following the project compiles:

      g++ -c file1.cpp file2.ccp .....filen.cpp

      however using the following I get numerous messages as follows: filen.cpp: (.text+0xb73c): undefined reference to `******* etc etc etc these functions are defined in a header file in each of the file*.cpp files thus:

      #include "funcdefs.h"

      this header file is located in the same directory as the *.cpp files the header file was originally entitled FUNCDEFS.H but I changed the name to lower case funcdefs.h to stop the compiler complaining. the funcdefs file contains the following code:

      //#if !defined(FUNCDEFS_H)
      //#define FUNCDEFS_H

      #if !defined(funcdefs_h)
      #define funcdefs_h

      extern double func1 ( double f ) ;
      extern void func2 ( double *input ) ;
      //etc etc etc

      #endif

      I have tried making the preprocessor directive in the funcdefs.h file lower case (didn't make any difference) and have checked the include path using -H and it seems to find the file but cannot get it to link. Any ideas? Thanks

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      The error does not occur during compiling but during linking. It tells you that the final program did not contain the functions in one of the compiled files. You must also add the source files with those functions to your project. So copy the source file(s) (e.g. funcdefs.cpp) to your directory and add them to the g++ build command.

      P 1 Reply Last reply
      0
      • J Jochen Arndt

        The error does not occur during compiling but during linking. It tells you that the final program did not contain the functions in one of the compiled files. You must also add the source files with those functions to your project. So copy the source file(s) (e.g. funcdefs.cpp) to your directory and add them to the g++ build command.

        P Offline
        P Offline
        PaulS_UK
        wrote on last edited by
        #3

        Thanks Jochen I might not have given you enough information. The actual text of the linking error message is: In function `process(int, char*, ControlData*, char*, char*)': PROCESS.CPP: (.text+0x788): undefined reference to `readsig(MiscParams*, char*)' PROCESS.CPP: (.text+0xaac): undefined reference to `sig_save(Signal*, char*)' PROCESS.CPP: (.text+0xdd4): undefined reference to `display(Signal*, MiscParams*, int)'............. ......etc etc etc so there are many undefined references to functions from within the function 'process' contained in PROCESS.CPP however; all these functions are defined in funcdefs.h as follows:

        extern int readsig ( MiscParams *misc , char *namelist , int *nsigs ,
        Signal ***signals , char *error ) ;

        etc etc etc as I understand it, the various individual *.cpp files are referring to functions that are defined within funcdefs.h shouldn't these definitions be included from this file by the pre processor instruction and therefore be defined references? Or are you saying that it is the function 'process' in PROCESS.CPP that is calling other undefined references? The very first such call is 'readsig' which is defined in functions.h Or are you saying that I should just call functions.h functions.cpp? This is driving me nuts so thanks for your help! ++++++++++EDIT+++++++++++ Jochen - I think I'm beginning to get your drift! The fundefs.h file only contains function prototypes not definitions :)

        L J 2 Replies Last reply
        0
        • P PaulS_UK

          Thanks Jochen I might not have given you enough information. The actual text of the linking error message is: In function `process(int, char*, ControlData*, char*, char*)': PROCESS.CPP: (.text+0x788): undefined reference to `readsig(MiscParams*, char*)' PROCESS.CPP: (.text+0xaac): undefined reference to `sig_save(Signal*, char*)' PROCESS.CPP: (.text+0xdd4): undefined reference to `display(Signal*, MiscParams*, int)'............. ......etc etc etc so there are many undefined references to functions from within the function 'process' contained in PROCESS.CPP however; all these functions are defined in funcdefs.h as follows:

          extern int readsig ( MiscParams *misc , char *namelist , int *nsigs ,
          Signal ***signals , char *error ) ;

          etc etc etc as I understand it, the various individual *.cpp files are referring to functions that are defined within funcdefs.h shouldn't these definitions be included from this file by the pre processor instruction and therefore be defined references? Or are you saying that it is the function 'process' in PROCESS.CPP that is calling other undefined references? The very first such call is 'readsig' which is defined in functions.h Or are you saying that I should just call functions.h functions.cpp? This is driving me nuts so thanks for your help! ++++++++++EDIT+++++++++++ Jochen - I think I'm beginning to get your drift! The fundefs.h file only contains function prototypes not definitions :)

          J Offline
          J Offline
          Jochen Arndt
          wrote on last edited by
          #4

          I just saw you edited your post and got it. But I will answer anyhow (I had already written this but the CP servers where unavailable for some minutes): I suggest to read about definitions and declarations in C/C++ because these are often mixed up. See the first answer of this Stackoverflow thread: http://stackoverflow.com/questions/1410563/what-is-the-difference-between-a-definition-and-a-declaration[^] You have declarations for the functions in your header files. So the sources will compile. But you don't have definitions for the functions in any of your source files. So the linkage will fail. You must add the source files containing the definitions. For the readsig function this must be a source file containing:

          int readsig ( MiscParams *misc , char *namelist , int *nsigs ,
          Signal ***signals , char *error )
          {
          /* function implementation*/
          }

          1 Reply Last reply
          0
          • P PaulS_UK

            Thanks Jochen I might not have given you enough information. The actual text of the linking error message is: In function `process(int, char*, ControlData*, char*, char*)': PROCESS.CPP: (.text+0x788): undefined reference to `readsig(MiscParams*, char*)' PROCESS.CPP: (.text+0xaac): undefined reference to `sig_save(Signal*, char*)' PROCESS.CPP: (.text+0xdd4): undefined reference to `display(Signal*, MiscParams*, int)'............. ......etc etc etc so there are many undefined references to functions from within the function 'process' contained in PROCESS.CPP however; all these functions are defined in funcdefs.h as follows:

            extern int readsig ( MiscParams *misc , char *namelist , int *nsigs ,
            Signal ***signals , char *error ) ;

            etc etc etc as I understand it, the various individual *.cpp files are referring to functions that are defined within funcdefs.h shouldn't these definitions be included from this file by the pre processor instruction and therefore be defined references? Or are you saying that it is the function 'process' in PROCESS.CPP that is calling other undefined references? The very first such call is 'readsig' which is defined in functions.h Or are you saying that I should just call functions.h functions.cpp? This is driving me nuts so thanks for your help! ++++++++++EDIT+++++++++++ Jochen - I think I'm beginning to get your drift! The fundefs.h file only contains function prototypes not definitions :)

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

            You must include the library or object modules that contains the actual code of the missing functions. As Jochen already mentioned, these are linker errors, nothing to do with compiling or header files.

            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