I am using a Meinberg GPS Card and trying to compile a program which should interact with the Card. The GPS Card is properly installed, I can use all the sample programs.
My programm basically is a .cc file.
When I try to compile I get an error message saying I "undefined reference". The so called undefined refernece is definde in a .c file which is included in the header file of my .cc program.
So the Meinberg Support told me I had to include the .c files too in my Makefile.
A friend of mine wrote me then this piece of code:
But I still get the same error. Then I got the tip that I should try and move all the reference GPS Card fils to the directory where my Makefile is and comile again.
I did and I got a different error regarding another library file from the card. I began to manually go through the error messages and set the paths of the files absolute and it worked but I will never finish this way^^
How do I have to change the code of the Makefile if I want it to check everywhere?
.c files should not be included in header files. The .c file should have its own header declaring its public contents. That header file should be included in your .cc file.
I will translate the exact answer from the support for you:
"You have to include the corresponding .c files (to the Header files I included in my .cc program) in the Makefile because We don't deliver libs as precompiled shared libraries at the moment."
And you are saying this is not possible? Or did I get it wrong?
Usually for C libraries you get from external vendors, they will supply a .h file so you know what are the function and arguments to call BUT the implementation come in the form of .a and .so suffixes to indicate static or dynamic libraries.
Then in your own program you #include the vendor .h file and then during linking you link their provided libraries in order to get your program to run 'talking' to their libraries.
This vendor is strange, they actually give you the source code implementation of their library hmmm... pretty generous for a vendor isn't it ? :)
1. #include header files
2. link with library/object(s)
The first part is how your application knows what to expect out of the library. The second part is what you need to do in your Makefile.
To make the problem easier to diagnose, post more specific information. We can't say the Makefile is fine without seeing what targets are available. Pasting the errors verbatim would be very helpful, as well.
When I type make now, it says "undefined reference to ....." This specific command is defined in a .c file which header is included in my .cc program.
Now, when I copy all the header files and the corresponding .c files to the directory where my .cc file is and run make again like Galik suggested, I get an error from another .c file which points to his corresponding .c file saying: "no such file or directory" for the corresponding .c file which is definitely in the same diretory. When I edit the path to the .c file in the .h file to /home/hilikus/.../file.c it finds the file but brings another errors. Now I can edit the paths manually into the .c and .h files whenever he brings that error and it seems to work but I did that this morning for over two hours and wasn't done. There are quiet a lot of .c and .h files it seems^^
The -I flag to the compiler tells it what folder to look for .h files.
The other thing you could try is modifying line 31 of the Makefile to say this:
gcc $(CXXFLAGS) -c $<
It might be failing to find something because it is compiling the C files using the C++ compiler. But that also might be what they intended so its worth a shot but it might make things worse too ;o)
Without being able to see the whole setup its difficult to diagnose.