driver in globus toolkit - c

I have been trying to run an example driver program given in the globus toolkit website. This is the program:
#include "globus_xio.h"
int main(int argc,char *argv[])
{
globus_result_t res;
char * driver_name;
globus_xio_driver_t driver;
globus_xio_stack_t stack;
globus_xio_handle_t handle;
globus_size_t nbytes;
char * contact_string = NULL;
char buf[256];
contact_string = argv[1];
driver_name = argv[2];
globus_module_activate(GLOBUS_XIO_MODULE);
res = globus_xio_driver_load(driver_name,&driver);
assert(res == GLOBUS_SUCCESS);
res = globus_xio_stack_init(&stack, NULL);
assert(res == GLOBUS_SUCCESS);
res = globus_xio_stack_push_driver(stack, driver);
assert(res == GLOBUS_SUCCESS);
res = globus_xio_handle_create(&handle, stack);
assert(res == GLOBUS_SUCCESS);
res = globus_xio_open(handle, contact_string, NULL);
assert(res == GLOBUS_SUCCESS);
do
{
res = globus_xio_read(handle, buf, sizeof(buf) - 1, 1, &nbytes, NULL);
if(nbytes > 0)
{
buf[nbytes] = '\0';
fprintf(stderr, "%s", buf);
}
} while(res == GLOBUS_SUCCESS);
globus_xio_close(handle, NULL);
globus_module_deactivate(GLOBUS_XIO_MODULE);
return 0;
}
When I compile this using the command
cc -I /usr/include/globus globus_xio_example.c
I get the following errors
/tmp/ccLMLlIi.o: In function `main':
globus_xio_example.c:(.text+0x57): undefined reference to `globus_i_xio_module'
globus_xio_example.c:(.text+0x5c): undefined reference to `globus_module_activate'
globus_xio_example.c:(.text+0x75): undefined reference to `globus_xio_driver_load'
globus_xio_example.c:(.text+0xb1): undefined reference to `globus_xio_stack_init'
globus_xio_example.c:(.text+0xf2): undefined reference to `globus_xio_stack_push_driver'
globus_xio_example.c:(.text+0x133): undefined reference to `globus_xio_handle_create'
globus_xio_example.c:(.text+0x179): undefined reference to `globus_xio_open'
globus_xio_example.c:(.text+0x1d1): undefined reference to `globus_xio_read'
globus_xio_example.c:(.text+0x22b): undefined reference to `globus_xio_close'
globus_xio_example.c:(.text+0x230): undefined reference to `globus_i_xio_module'
globus_xio_example.c:(.text+0x235): undefined reference to `globus_module_deactivate'
collect2: ld returned 1 exit status

It appears that the command used to compile is insufficient:
cc -I /usr/include/globus globus_xio_example.c
Specifically, the linker process indicates that there are a number of symbols that could not be resolved. I suspect that the command used to compile is lacking directives as to which library(s) needs to be linked to resolve the undefined symbols.
HINT:
Use 'globus-makefile-header' to help determine library dependencies.
% globus-makefile-header -flavor=gcc32dbg globus_xio > header
Examine the contents of 'header' for appropriate makefile macros.
Include header in your makefile and use the needed makefile macros.

Try this gcc -I /usr/include/globus globus_xio_example.c -lglobus_xio -lglobus_common

Related

Probleme to link my stub with newlib with arm-none-eabi-gcc

I'm trying to compile a small proof of work tath run lua code on the rasperry pi zero bare-metal.
All my object file and lua's have been compiled with similar options. I tried with and without the -nostdlib and -lc -lgcc but the output is the same.
Commande:
arm-none-eabi-gcc \
-mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s \
-g -O0 \
-Wl,-z,max-page-size=0x04,-T,linker.ld \
-nostdlib \
./lua/lua-5.4.4/src/lapi.o ./lua/lua-5.4.4/src/lauxlib.o ./lua/lua-5.4.4/src/lbaselib.o ./lua/lua-5.4.4/src/lcode.o ./lua/lua-5.4.4/src/lcorolib.o ./lua/lua-5.4.4/src/lctype.o ./lua/lua-5.4.4/src/ldblib.o ./lua/lua-5.4.4/src/ldebug.o ./lua/lua-5.4.4/src/ldo.o ./lua/lua-5.4.4/src/ldump.o ./lua/lua-5.4.4/src/lfunc.o ./lua/lua-5.4.4/src/lgc.o ./lua/lua-5.4.4/src/linit.o ./lua/lua-5.4.4/src/liolib.o ./lua/lua-5.4.4/src/llex.o ./lua/lua-5.4.4/src/lmathlib.o ./lua/lua-5.4.4/src/lmem.o ./lua/lua-5.4.4/src/loadlib.o ./lua/lua-5.4.4/src/lobject.o ./lua/lua-5.4.4/src/lopcodes.o ./lua/lua-5.4.4/src/loslib.o ./lua/lua-5.4.4/src/lparser.o ./lua/lua-5.4.4/src/lstate.o ./lua/lua-5.4.4/src/lstring.o ./lua/lua-5.4.4/src/lstrlib.o ./lua/lua-5.4.4/src/ltable.o ./lua/lua-5.4.4/src/ltablib.o ./lua/lua-5.4.4/src/ltm.o ./lua/lua-5.4.4/src/lundump.o ./lua/lua-5.4.4/src/lutf8lib.o ./lua/lua-5.4.4/src/lvm.o ./lua/lua-5.4.4/src/lzio.o \
./.build/startup.o ./.build/start.o ./.build/main.o ./.build/bootstrap.lua.o ./.build/0stubs.o \
-lc \
-lgcc \
-lm
Output:
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-fstatr.o): in function `_fstat_r':
/build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/fstatr.c:55: undefined reference to `_fstat'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-openr.o): in function `_open_r':
/build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/openr.c:50: undefined reference to `_open'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-timesr.o): in function `_times_r':
/build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/timesr.c:52: undefined reference to `_times'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-unlinkr.o): in function `_unlink_r':
/build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/unlinkr.c:47: undefined reference to `_unlink'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-writer.o): in function `_write_r':
/build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/writer.c:49: undefined reference to `_write'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-closer.o): in function `_close_r':
/build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/closer.c:47: undefined reference to `_close'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-gettimeofdayr.o): in function `_gettimeofday_r':
/build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/gettimeofdayr.c:62: undefined reference to `_gettimeofday'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-isattyr.o): in function `_isatty_r':
/build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/isattyr.c:52: undefined reference to `_isatty'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-linkr.o): in function `_link_r':
/build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/linkr.c:53: undefined reference to `_link'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-lseekr.o): in function `_lseek_r':
/build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/lseekr.c:49: undefined reference to `_lseek'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-readr.o): in function `_read_r':
/build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/readr.c:49: undefined reference to `_read'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-signalr.o): in function `_kill_r':
/build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/signalr.c:53: undefined reference to `_kill'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/arm/v5te/hard/libc.a(lib_a-signalr.o): in function `_getpid_r':
/build/newlib-wFsRXh/newlib-3.3.0/build/arm-none-eabi/arm/v5te/hard/newlib/libc/reent/../../../../../../../../newlib/libc/reent/signalr.c:83: undefined reference to `_getpid'
My 0stubs.c file:
#include <sys/stat.h>
/* A helper function written in assembler to aid us in allocating memory */
extern caddr_t _get_stack_pointer(void);
/* Increase program data space. As malloc and related functions depend on this,
it is useful to have a working implementation. The following suffices for a
standalone system; it exploits the symbol _end automatically defined by the
GNU linker. */
caddr_t _sbrk( int incr )
{
extern char _end;
static char* heap_end = 0;
char* prev_heap_end;
if( heap_end == 0 )
heap_end = &_end;
prev_heap_end = heap_end;
heap_end += incr;
return (caddr_t)prev_heap_end;
}
int close(int file) {
return -1;
}
char *__env[1] = { 0 };
char **environ = __env;
#include <errno.h>
#undef errno
extern int errno;
int execve(char *name, char **argv, char **env) {
errno = ENOMEM;
return -1;
}
int fork(void) {
errno = EAGAIN;
return -1;
}
int kill(int pid, int sig) {
errno = EINVAL;
return -1;
}
int link(char *old, char *new) {
errno = EMLINK;
return -1;
}
int fstat(int file, struct stat *st) {
st->st_mode = S_IFCHR;
return 0;
}
int getpid(void) {
return 1;
}
int isatty(int file) {
return 1;
}
int lseek(int file, int ptr, int dir) {
return 0;
}
int open(const char *name, int flags, int mode) {
return -1;
}
int read(int file, char *ptr, int len) {
return 0;
}
int times(struct tms *buf) {
return -1;
}
int unlink(char *name) {
errno = ENOENT;
return -1;
}
int wait(int *status) {
errno = ECHILD;
return -1;
}
int write(int file, char *ptr, int len) {
int todo;
for (todo = 0; todo < len; todo++) {
//outbyte (*ptr++);
}
return len;
}
void abort(void){
while(1){}
}
void exit(int status){
while(1){}
}

Failed to compile with secp256k1 library

So I was following this tutorial: https://nickfarrow.com/Cryptography-in-Bitcoin-with-C/ I installed libsecp256k1 from https://www.howtoinstall.me/ubuntu/18-04/libsecp256k1-dev/ but while compiling my program:
#include <secp256k1.h>
#include <stdio.h>
static secp256k1_context *ctx = NULL;
int main()
{
ctx = secp256k1_context_create(
SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
/* Declare the private variable as a 32 byte unsigned char */
unsigned char seckey[32];
/* Load private key (seckey) from random bytes */
FILE *frand = fopen("/dev/urandom", "r");
/* Read 32 bytes from frand */
fread(seckey, 32, 1, frand);
/* Close the file */
fclose(frand);
/* Loop through and print each byte of the private key, */
printf("Private Key: ");
for (int i = 0; i < 32; i++)
{
printf("%02X", seckey[i]);
}
printf("\n");
}
i get:
josh#pc:~/Code$ gcc prvkey.c -o exec
/tmp/cc5OVPMJ.o: In function `main':
prvkey.c:(.text+0x1d): undefined reference to `secp256k1_context_create'
collect2: error: ld returned 1 exit status
Thanks in advance!
Try:
gcc prvkey.c -o exec -lcrypto -lsecp256k1
gcc -l links with a library file.
Let me know if that works or any questions let me know.

Undefined symbols for architecture x86_64: What could be responsible [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 4 years ago.
Compiling c code using cmake. What is likely causing this error in one of my objects file despite including the sqlite3.h file:
Undefined symbols for architecture x86_64:
"_sqlite3_close", referenced from:
_prv_temperature_read in object_temperature.c.o
"_sqlite3_column_double", referenced from:
_prv_temperature_read in object_temperature.c.o
"_sqlite3_errmsg", referenced from:
_prv_temperature_read in object_temperature.c.o
"_sqlite3_finalize", referenced from:
_prv_temperature_read in object_temperature.c.o
"_sqlite3_open", referenced from:
_prv_temperature_read in object_temperature.c.o
"_sqlite3_prepare_v2", referenced from:
_prv_temperature_read in object_temperature.c.o
"_sqlite3_step", referenced from:
_prv_temperature_read in object_temperature.c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
EDIT:
Here's the complete object_temperature.c object, invoked by lwm2mclient.c main class.
#include "liblwm2m.h"
#include "lwm2mclient.h"
//..#include <sqlite3.0.tbd>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <sqlite3.h>
//...#include <libsqlite3.dylib>
//Resource Id's
#define RES_SENSOR_VALUE 5700
#define RES_SENSOR_UNITS 5701
typedef struct _prv_instance_
{
struct _prv_instance_ * next;
uint16_t shortID;
double temp;
char unit[10];
} prv_instance_t;
static uint8_t prv_temperature_read(uint16_t instanceId,
int * numDataP,
lwm2m_data_t ** dataArrayP,
lwm2m_object_t * objectP)
{
prv_instance_t * targetP;
int i;
sqlite3 *db;
sqlite3_stmt *res;
int timer = 0;
targetP = (prv_instance_t *)lwm2m_list_find(objectP->instanceList, instanceId);
if (NULL == targetP) return COAP_404_NOT_FOUND;
fprintf(stderr, "----------------- Entering in oprv_temperature ----------------\n");
// connect to the backend
timer = time(NULL);
if (time(NULL) - timer > 60)
{
int rc = sqlite3_open("test.sqlite3", &db);
if (rc != SQLITE_OK) {
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
return 1;
} else {
fprintf(stdout, "DB Connection Successful..\n");
}
rc = sqlite3_prepare_v2(db, "SELECT temperature_data FROM environment ORDER BY ID DESC LIMIT 1", -1, &res, 0);
if (rc != SQLITE_OK) {
fprintf(stderr, "Failed to fetch data: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
return 1;
}
rc = sqlite3_step(res);
if (rc == SQLITE_ROW) {
double t;
fprintf(stdout, "Yeah, rc == SQLITE_ROW \n");
t = sqlite3_column_double(res, 0);
targetP->temp = t;
}
sqlite3_finalize(res);
sqlite3_close(db);
timer = time(NULL);
}
if(*numDataP == 0)
{
*dataArrayP = lwm2m_data_new(1);
if (*dataArrayP == NULL) return COAP_500_INTERNAL_SERVER_ERROR;
*numDataP = 1;
(*dataArrayP)[0].id = RES_SENSOR_VALUE;
(*dataArrayP)[1].id = RES_SENSOR_UNITS;
}
for (i = 0; i < *numDataP; i++)
{
switch((*dataArrayP)[i].id)
{
case RES_SENSOR_VALUE:
lwm2m_data_encode_float(targetP->temp, *dataArrayP +1);
break;
case RES_SENSOR_UNITS:
return COAP_405_METHOD_NOT_ALLOWED;;
default:
return COAP_404_NOT_FOUND;
}
}
return COAP_205_CONTENT;
}
lwm2m_object_t * get_object_temperature()
{
/*
* The get_object_temperature function create the object itself and return a pointer to the structure that represent it.
*/
lwm2m_object_t * temperatureObj;
temperatureObj = (lwm2m_object_t *)lwm2m_malloc(sizeof(lwm2m_object_t));
if (NULL != temperatureObj)
{
memset(temperatureObj, 0, sizeof(lwm2m_object_t));
/*
* Assigns it's unique ID 3303
*/
temperatureObj->objID = LWM2M_TEMPERATURE_OBJECT_ID;
/*
* and its unique instance
*
*/
temperatureObj->instanceList = (lwm2m_list_t *)lwm2m_malloc(sizeof(lwm2m_list_t));
if (NULL != temperatureObj->instanceList)
{
memset(temperatureObj->instanceList, 0, sizeof(lwm2m_list_t));
}
else
{
lwm2m_free(temperatureObj);
return NULL;
}
/*
* And the private function that will access the object.
* Those function will be called when a read/write/execute query is made by the server. In fact the library don't need to
* know the resources of the object, only the server does.
*/
temperatureObj->readFunc = prv_temperature_read;
//deviceObj->discoverFunc = prv_device_discover;
//deviceObj->writeFunc = prv_device_write;
//deviceObj->executeFunc = prv_device_execute;
//temperatureObj->userData = lwm2m_malloc(sizeof(prv_instance_t));
}
return temperatureObj;
}
void free_object_temperature(lwm2m_object_t * objectP)
{
if (NULL != objectP->userData)
{
lwm2m_free(objectP->userData);
objectP->instanceList = NULL;
}
if(NULL != objectP->instanceList)
{
lwm2m_free(objectP->instanceList);
objectP->instanceList = NULL;
}
lwm2m_free(objectP);
}
It is not enough to just include the sqlite3.h header file. You need to either
link against the sqlite3 library - using -lsqlite3 in your compiler/linker command, or
include the 'amalgamated' SQLite source file, sqlite3.c, amongst the source files you compile.
Regarding the second option, see https://sqlite.org/amalgamation.html .

Asterisk:undefined reference to `SQLAllocHandle'

I added a test.c in asterisk/main directory to test ODBC. Unfortunately it shows like below when I run make.
test.o: In function `test_function':
/usr/src/asterisk-certified-13.8-cert3/main/libtest.c:10:
undefined reference to `SQLAllocHandle'
test.c like this:
#include "asterisk/res_odbc.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
int test_function(void){
int res;
SQLHANDLE output_handle;
res = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &output_handle);
if ( (res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO) ) {
ast_log(LOG_DEBUG, "AllocHandle Success!\n");
} else {
ast_log(LOG_WARNING, "Error AllocHandle");
}
return 0;
}
How can I fix this? Thanks!
You should change Makefile for include libs into your module.
But that is WRONG method when you working with asterisk.
Correct method is user REALTIME or func_odbc and make it care about connection.

called library procedure is running in infinity cycle on gnu/linux

I've got an library which must read data from sqlite database by calling
extern int read(char** argv, int argc); // from header
it must process:
int read(char** argv, int argc) {
char* lineborder1;
char* lineborder2;
char* spaces1;
char* spaces2;
int maxl2 = 0, maxl1 = 0;
int i, maxi1, maxi2;
if (prelude() == -1) return -1;
// etc...
where prelude is inner procedure for sqlite connection:
int prelude() {
timefile = 0;
f = NULL;
#ifndef WIN32
char* temp = (char*)calloc(200, sizeof(char));
#endif
queries = (char**)malloc(sizeof(char*) * q_cnt);
for (x = 0; x < q_cnt; x++) {
queries[x] = (char*)malloc(sizeof(char) * q_size);
}
#ifdef WIN32
retval = sqlite3_open("todo.db3", &handle);
#else
home = (char*)getenv("HOME");
strcpy(temp, home);
retval = sqlite3_open(strcat(temp, "/.todo.db3"), &handle);
free(temp);
#endif
if (retval) {
printf("Database connection failed\n\r");
return -1;
}
return 0;
}
whole source is here : bitbucket: ctodo.c
I call this read from my application:
else if ((strcmp(argv[1], "read") == 0) || (strcmp(argv[1], "r") == 0)) {
return read(argv, argc);
but getting infinity cycle of this read call:
>>./todo r
Database connection failed
Database connection failed
Database connection failed
.... etc
here is how do I build it:
gcc -I . -c -o todo.a ctodo.c -lsqlite3 -O3
gcc -I . -o todo cctodo.c -lsqlite3 -O3 todo.a
help or version calls wrok fine and read works fine on windows, something specific to my linux build is here but I can't find a bug so far. what could call this read to run in infinity cycle like that?
The read function is defined in libc.so, and used to, you know, read data.
It is exceedingly likely that sqlite3_open() calls it.
By introducing your own function called read(), you've made your program enter infinite loop. If you wait long enough, your program will run out of stack and crash.
Doctor, it hurts when I do that. Well, don't do that :-)

Resources