Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

New Member
Posts: 1
Registered: ‎03-15-2012
My Device: Playbook

Compiler error: socket(), sendto()

I can't compile the simple example below.

What can be the reason ?


// Native SDK 2.0

// with the include of <arpa/inet.h> the compiler generate errors:


//..\src\main.c: In function 'main':

//..\src\main.c:33: warning: implicit declaration of function 'inet_addr'

//qcc -o TestSocket src\main.o -lbps -lpps -lscreen -lm -V4.4.2,gcc_ntoarmv7le -w1 -g -Wl,-z,relro -Wl,-z,now -LD:/bbndk-2.0.0/target/qnx6/../target-override/armle-v7/lib -LD:/bbndk-2.0.0/target/qnx6/../target-override/armle-v7/usr/lib

//src\main.o: In function `main':

//T:\ndk-2.0.0-workspace\TestSocket\Device-Debug/..\src/main.c:35: undefined reference to `socket'

//T:\ndk-2.0.0-workspace\TestSocket\Device-Debug/..\src/main.c:37: undefined reference to `sendto'

//cc: D:/bbndk-2.0.0/host/win32/x86/usr/bin/ntoarm-ld caught signal 1

//Build error occurred, build is stopped

//Time consumed: 232 ms.



#include <stdio.h>

#include <string.h>

#include <sys/socket.h>

#include <netinet/in.h>

#include <arpa/inet.h>


const char * text = "Hello";


int main (int argc, char**argv)


struct sockaddr_in sin;

int s;


sin.sin_family= AF_INET;

sin.sin_port= 9221;

sin.sin_addr.s_addr = inet_addr ("");


s = socket (PF_INET, SOCK_DGRAM, 0); // error: "undefined reference to `socket'"

sendto (s, (constvoid *)text, strlen(text), 0, (conststruct sockaddr *)&sin, sizeof(sin)); // error: "undefined reference to `sendto'"




Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook

Re: Compiler error: socket(), sendto()

apparently you are missing socket library, try adding -lsocket