g++ Compiler not including header file
-
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_hextern 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
-
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_hextern 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
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.
-
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.
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 :)
-
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 :)
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*/
} -
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 :)