"undefined reference " error - what am I missing ?
-
I am getting
undefined reference
error. I have "included " relevant headers in souce files , I have "common path" in project includes (/usr/include /bluetooth ) , I can access "Open Declaration" in my IDE and it identifies function and its file... I have no errors indicating missing
bluetooth/hci_lib.h
in text file... What did I missed??
#ifndef MODULES_M_BT_H_
#define MODULES_M_BT_H_#include #include #include #include #include #include #include #include #include #include
C++ function
int C_BT::Scan(void) {
cout << "C_BT::Scan(void) " << endl;
// Get bluetooth device id
int device_id = hci_get_route(NULL); // Passing NULL argument will retrieve the id of first avalaibe device
if (device_id < 0) {
printf("Error: Bluetooth device not found");
exit(1);
}
return 0;
}Error
./src/MODULES/M_BLUETOOTH/CBT.o: In function `std::C_BT::Scan()':
/media/jim/DEV/eclipse-workspace/VNAR_1204/Debug/../src/MODULES/M_BLUETOOTH/CBT.cpp:42: undefined reference to `hci_get_route'
collect2: error: ld returned 1 exit status
makefile:75: recipe for target 'VNAR_1204' failed
make: *** [VNAR_1204] Error 1Can I get a second opinion ? Cheers Vaclav
-
I am getting
undefined reference
error. I have "included " relevant headers in souce files , I have "common path" in project includes (/usr/include /bluetooth ) , I can access "Open Declaration" in my IDE and it identifies function and its file... I have no errors indicating missing
bluetooth/hci_lib.h
in text file... What did I missed??
#ifndef MODULES_M_BT_H_
#define MODULES_M_BT_H_#include #include #include #include #include #include #include #include #include #include
C++ function
int C_BT::Scan(void) {
cout << "C_BT::Scan(void) " << endl;
// Get bluetooth device id
int device_id = hci_get_route(NULL); // Passing NULL argument will retrieve the id of first avalaibe device
if (device_id < 0) {
printf("Error: Bluetooth device not found");
exit(1);
}
return 0;
}Error
./src/MODULES/M_BLUETOOTH/CBT.o: In function `std::C_BT::Scan()':
/media/jim/DEV/eclipse-workspace/VNAR_1204/Debug/../src/MODULES/M_BLUETOOTH/CBT.cpp:42: undefined reference to `hci_get_route'
collect2: error: ld returned 1 exit status
makefile:75: recipe for target 'VNAR_1204' failed
make: *** [VNAR_1204] Error 1Can I get a second opinion ? Cheers Vaclav
At a guess it's a C file and you are dragging it into a C++ file and getting splattered by name mangling Name mangling - Wikipedia[^] The two solutions are in the above link under Handling of C symbols when linking from C++ Check are the bluetooth library files C or C++ :-) If C the easiest is probably include all the C header files like so
extern "C" {
#include
}In vino veritas
-
At a guess it's a C file and you are dragging it into a C++ file and getting splattered by name mangling Name mangling - Wikipedia[^] The two solutions are in the above link under Handling of C symbols when linking from C++ Check are the bluetooth library files C or C++ :-) If C the easiest is probably include all the C header files like so
extern "C" {
#include
}In vino veritas
Leon, you are close, it is C file , but... It has ( or SHOULD HAVE (?) ) __cplusplus defined and that should make it work in C++ So where do I check if __cplusplus id actually defined ?
#ifndef __HCI_LIB_H
#define __HCI_LIB_H#ifdef __cplusplus
extern "C" {
#endifI'll take a look what else can be "fixed" to make it go.
-
I am getting
undefined reference
error. I have "included " relevant headers in souce files , I have "common path" in project includes (/usr/include /bluetooth ) , I can access "Open Declaration" in my IDE and it identifies function and its file... I have no errors indicating missing
bluetooth/hci_lib.h
in text file... What did I missed??
#ifndef MODULES_M_BT_H_
#define MODULES_M_BT_H_#include #include #include #include #include #include #include #include #include #include
C++ function
int C_BT::Scan(void) {
cout << "C_BT::Scan(void) " << endl;
// Get bluetooth device id
int device_id = hci_get_route(NULL); // Passing NULL argument will retrieve the id of first avalaibe device
if (device_id < 0) {
printf("Error: Bluetooth device not found");
exit(1);
}
return 0;
}Error
./src/MODULES/M_BLUETOOTH/CBT.o: In function `std::C_BT::Scan()':
/media/jim/DEV/eclipse-workspace/VNAR_1204/Debug/../src/MODULES/M_BLUETOOTH/CBT.cpp:42: undefined reference to `hci_get_route'
collect2: error: ld returned 1 exit status
makefile:75: recipe for target 'VNAR_1204' failed
make: *** [VNAR_1204] Error 1Can I get a second opinion ? Cheers Vaclav
-
I am getting
undefined reference
error. I have "included " relevant headers in souce files , I have "common path" in project includes (/usr/include /bluetooth ) , I can access "Open Declaration" in my IDE and it identifies function and its file... I have no errors indicating missing
bluetooth/hci_lib.h
in text file... What did I missed??
#ifndef MODULES_M_BT_H_
#define MODULES_M_BT_H_#include #include #include #include #include #include #include #include #include #include
C++ function
int C_BT::Scan(void) {
cout << "C_BT::Scan(void) " << endl;
// Get bluetooth device id
int device_id = hci_get_route(NULL); // Passing NULL argument will retrieve the id of first avalaibe device
if (device_id < 0) {
printf("Error: Bluetooth device not found");
exit(1);
}
return 0;
}Error
./src/MODULES/M_BLUETOOTH/CBT.o: In function `std::C_BT::Scan()':
/media/jim/DEV/eclipse-workspace/VNAR_1204/Debug/../src/MODULES/M_BLUETOOTH/CBT.cpp:42: undefined reference to `hci_get_route'
collect2: error: ld returned 1 exit status
makefile:75: recipe for target 'VNAR_1204' failed
make: *** [VNAR_1204] Error 1Can I get a second opinion ? Cheers Vaclav
You're not actually linking in the bluetooth library.
-
You're not actually linking in the bluetooth library.
-
Perhaps this answer on SO is it: bluetooth - Linking with libbluetooth.so - Stack Overflow[^] (In the past, I got bit by the gcc link order thing several times.) Alternatively, you are missing some files. Search the source you have for hci_get_route. (The point is that the linker isn't seeing this symbol.)
-
Perhaps this answer on SO is it: bluetooth - Linking with libbluetooth.so - Stack Overflow[^] (In the past, I got bit by the gcc link order thing several times.) Alternatively, you are missing some files. Search the source you have for hci_get_route. (The point is that the linker isn't seeing this symbol.)
Here is an indirect answer "None of the function definitions are present in the header files: just the declarations. The definitions are in the library" Make sense. Somewhat. But "definitions are in library" ? (Perhaps some A..no affectionado wrote the "library" ) What does not make sense - the example code I am using which was already been refereed too said zilch about need to use the library nor does it even mention the name of the library. Perhaps it is obvious to experts that library has to be linked in. But what the dickens is " compiled against (library)" ? This nameless library (?) is probably different for each hardware too.
-
Here is an indirect answer "None of the function definitions are present in the header files: just the declarations. The definitions are in the library" Make sense. Somewhat. But "definitions are in library" ? (Perhaps some A..no affectionado wrote the "library" ) What does not make sense - the example code I am using which was already been refereed too said zilch about need to use the library nor does it even mention the name of the library. Perhaps it is obvious to experts that library has to be linked in. But what the dickens is " compiled against (library)" ? This nameless library (?) is probably different for each hardware too.
Vaclav_ wrote:
But what the dickens is " compiled against (library)" ?
It's a way of saying, build using that library. Based on this "apt-get install bluez libbluetooth-dev" (from tutorials:common:development:bluez_programming [CubieBoard Docs][^]) suggests it's part of the bluez package. Added: I checked the Debian repository and the package list and contents supports this.
-
As I have explained to you a number of times, header files are only used to compile your source code. That is, to convert source instructions to object code instructions. But the output of the compiler is not complete, it needs other object modules linked to it in order to execute. That is where the associated libraries come in. They need to be added to the link step so the final executable includes the code you wrote and the pre-built libraries that contain the functions that your code will be calling.
-
Vaclav_ wrote:
But what the dickens is " compiled against (library)" ?
It's a way of saying, build using that library. Based on this "apt-get install bluez libbluetooth-dev" (from tutorials:common:development:bluez_programming [CubieBoard Docs][^]) suggests it's part of the bluez package. Added: I checked the Debian repository and the package list and contents supports this.
Found this procedure , for Eclipse IDE, which puts difffernt spin onto the problem. To me it implies that linker can use "source" instead of library.
To use the latest Bluetooth kernel modules is one important thing, but without support from the user space these modules are useless. For the minimal functionality the bluez package is needed.
bluez-5.50.tar.xz
- Copy and paste the extracted folder (named something like bluez-5.31) to the usr\include folder.
- The path to usr\include folder may look something like this C:\Intel\iotdk-ide-win\devkit-x86\sysroots\i586-poky-linux\usr\include
- Now on Eclipse (assuming your project is open) add the linker flags for your project. On Eclipse's menus select Project>Properties>C/C++ Build>Settings>Tool Settings>Cross GCC Linker>Miscellaneous, add the flag "-bluez-3.1" and click OK.
Note: This flag is basically a "-" character concatenated with the name of the bluez folder.
4. Edit the header calls on your main file; add the path to where the header files needed are. In this case bluetooth.h, hci.h and hci_lib.h are inside bluez 5.31, header calls should look something like these:
#include "bluez-5.31/bluetooth.h"
#include "bluez-5.31/hci.h"
#include "bluez-5.31/hci_lib.h"
5. Proceed to save (Ctrl + S) and Build Project.
Unfortunately Linux / Eclipse (?) won't let me add the "extracted folder" into /usr/include - need permission. I added full path to my Bluez-5.50 and linker did not complain about that but the overall result was - now getting more errors. I am going to look into linker "miscellaneous " options to see what is missing. Note the /usr/include has folder "bluetooth" which contains the needed headers. That works fine. I have no idea how it got there.