Community
cancel
Showing results for 
Search instead for 
Did you mean: 
CWong12
New Contributor I
2,229 Views

undefined reference to `ba2str'

Hi,

I am trying to run the code below using eclipse but to end up with the above error. Is the bluetooth library supported in eclipse? Please advise.

# include

# include

# include

# include

# include

int main(int argc, char **argv)

{

struct sockaddr_rc loc_addr = { 0 }, rem_addr = { 0 };

char buf[1024] = { 0 };

int s, client, bytes_read;

socklen_t opt = sizeof(rem_addr);

// allocate socket

s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);

// bind socket to port 1 of the first available

// local bluetooth adapter

loc_addr.rc_family = AF_BLUETOOTH;

loc_addr.rc_bdaddr = *BDADDR_ANY;

loc_addr.rc_channel = (uint8_t) 1;

bind(s, (struct sockaddr *)&loc_addr, sizeof(loc_addr));

// put socket into listening mode

listen(s, 1);

// accept one connection

client = accept(s, (struct sockaddr *)&rem_addr, &opt);

ba2str( &rem_addr.rc_bdaddr, buf );

fprintf(stderr, "accepted connection from %s\n", buf);

memset(buf, 0, sizeof(buf));

// read data from the client

bytes_read = read(client, buf, sizeof(buf));

if( bytes_read > 0 ) {

printf("received [%s]\n", buf);

}

// close connection

close(client);

close(s);

return 0;

}

7 Replies
Sergio_A_Intel
Employee
464 Views

Hi,

Is "undefined reference to `ba2str'" the full error log you received? If it's not, please post the full log. What Eclipse and image version are you using, make sure you're using the latest in both cases.

Other users have used the ba2str function successfully in other threads in the community. Maybe your issue is because you need update or add the library in Eclipse before you use it.

Take a look at where I explain the steps to add a bluez library to Eclipse. These steps will give you an idea on how to add libraries to Eclipse in case that's what you need to do to get your code running.

Sergio

CWong12
New Contributor I
464 Views

Followed your method below. Solved the above problem but returned with this error "i586-poky-linux-gcc: error: unrecognized command line option '-bluez-3.1'" Please advise.

Try using these steps to add the bluez-5.31 library to Eclipse and build a project:

  1. Download and extract the bluez.tar.xz file http://www.bluez.org/release-of-bluez-5-31/ http://www.bluez.org/release-of-bluez-5-31/
  2. 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
  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.

CWong12
New Contributor I
464 Views

Hi Sergio,

How can I proceed from here? Been stuck for quite a while.

Sergio_A_Intel
Employee
464 Views

Did you follow steps 4 and 5 of the link we sent you previously? You need to include the bluez libraries as shown in step 4. Again, please send us the full error log and the Eclipse version you're using after following all the steps previously mentioned.

Sergio

CWong12
New Contributor I
464 Views

Yses, I did follow step 4 and step5 to modify the header file path in my include. The error prompted is "i586-poky-linux-gcc: error: unrecognized command line option '-bluez-3.1'". It seems like my step 3 didnt do correctly. But i did add the flag accordingly.

Sergio_A_Intel
Employee
464 Views

What Eclipse version and image version are you using? Additionally, take a look at this reply from the user of

In step 3, I added the character "l" (as in "link", lower case) to the flag in the linker's "Miscellaneous" menu between the hyphen ("-") and the folder name, e.g., : "-lBluez-5.31" rather than "-Bluez-5.31".

Have you tried this approach?

Sergio

CWong12
New Contributor I
464 Views

Hi Sergio,

Manage to get it work by using -lbluetooth as linker flag.

Reply