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. "undefined reference " error - what am I missing ?

"undefined reference " error - what am I missing ?

Scheduled Pinned Locked Moved C / C++ / MFC
c++visual-studiodebugginghelpquestion
11 Posts 4 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.
  • V Offline
    V Offline
    Vaclav_
    wrote on last edited by
    #1

    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 1

    Can I get a second opinion ? Cheers Vaclav

    L L J 3 Replies Last reply
    0
    • V 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 1

      Can I get a second opinion ? Cheers Vaclav

      L Offline
      L Offline
      leon de boer
      wrote on last edited by
      #2

      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

      V 1 Reply Last reply
      0
      • L leon de boer

        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

        V Offline
        V Offline
        Vaclav_
        wrote on last edited by
        #3

        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" {
        #endif

        I'll take a look what else can be "fixed" to make it go.

        1 Reply Last reply
        0
        • V 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 1

          Can I get a second opinion ? Cheers Vaclav

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

          Did you forget to include a .lib file in your build?

          1 Reply Last reply
          0
          • V 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 1

            Can I get a second opinion ? Cheers Vaclav

            J Offline
            J Offline
            Joe Woodbury
            wrote on last edited by
            #5

            You're not actually linking in the bluetooth library.

            V 1 Reply Last reply
            0
            • J Joe Woodbury

              You're not actually linking in the bluetooth library.

              V Offline
              V Offline
              Vaclav_
              wrote on last edited by
              #6

              I was not trying to use any library - just source.

              J L 2 Replies Last reply
              0
              • V Vaclav_

                I was not trying to use any library - just source.

                J Offline
                J Offline
                Joe Woodbury
                wrote on last edited by
                #7

                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.)

                V 1 Reply Last reply
                0
                • J Joe Woodbury

                  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.)

                  V Offline
                  V Offline
                  Vaclav_
                  wrote on last edited by
                  #8

                  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.

                  J 1 Reply Last reply
                  0
                  • V Vaclav_

                    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.

                    J Offline
                    J Offline
                    Joe Woodbury
                    wrote on last edited by
                    #9

                    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.

                    V 1 Reply Last reply
                    0
                    • V Vaclav_

                      I was not trying to use any library - just source.

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

                      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.

                      1 Reply Last reply
                      0
                      • J Joe Woodbury

                        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.

                        V Offline
                        V Offline
                        Vaclav_
                        wrote on last edited by
                        #11

                        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

                        1. Copy and paste the extracted folder (named something like bluez-5.31) to the usr\include folder.
                        2. The path to usr\include folder may look something like this C:\Intel\iotdk-ide-win\devkit-x86\sysroots\i586-poky-linux\usr\include
                        3. 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.

                        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