Undefined reference to svc_create - c

My problem is the following: I'm trying to implement a C RPC example and I keep running into the following compiler error:
remote_exec.c: In function ‘main’:
remote_exec.c:13:3: warning: implicit declaration of function ‘svc_create’
remote_exec.o: In function `main':
remote_exec.c:(.text+0x31): undefined reference to `svc_create'
collect2: ld returned 1 exit status
My code:
#include <stdio.h>
#include <rpc/rpc.h>
#include "rls.h"
int main(int argc, char* argv[])
{
extern void execute();
const char* nettype = "tcp";
int no_of_handles;
no_of_handles = svc_create(execute, EXECPROG, EXECVERS, nettype);
svc_run();
return 0;
}
I really don't know how to solve this. The man page and all the examples I've studied just say to include rpc/rpc.h, however it doesn't seem to work. I am compiling with
gcc -Wall -c

There is no such function as svc_create on linux in libc. See the manpage for rpc. Your guide is using the transport independent(ti) RPC library of Solaris and other unixes. See this question for RPC guides for linux.
The RPC library in linux is based on a slightly different RPC library than the ti-RPC library from Sun, though there is a ti-RPC library here: http://nfsv4.bullopensource.org/doc/tirpc_rpcbind.php , if you use that library, you link with -ltirpc
You probably need svctcp_create or svcudp_create if you're using the standard RPC library included in glibc.

You probably have to link against the library when you create your program. If the library is called rpc, for example, this would be done by adding -lrpc to the compiler command line that creates the final executable.

Related

Undefined reference ld error when using Windows <bluetoothapis.h>

I am new to programming and want to work with the Windows BluetoothApi.h library in C. I've written smaller programs that reference header files I've created, but none of the APIs given by windows.
I am attempting to return information from a local bluetooth speaker to a terminal session on my PC. I've been referencing the BluetoothFindFirstRadio and BLUETOOTH_FIND_RADIO_PARAM documentation, as well as some posts on Stack to see some viable examples. I believe I'm close to being able to compile but I keep getting an error about an undefined reference to the functions I'm calling that I do believe are in the BluetoothAPI.h header file.
From what I've seen, again on Stack, it seems that it's possible that "there is not enough space left at \user\tmp"?
or
Looking at the documentation for ld, it may be possible I need to try to compile using a different command altogther?
PS C:\scripts\C_Lang\Bluetooth> gcc bluetest.c -o test
C:\Users\Ryan\AppData\Local\Temp\cce0FxKH.o:bluetest.c:(.text+0x2b): undefined reference to `BluetoothFindFirstRadio#8'
C:\Users\Ryan\AppData\Local\Temp\cce0FxKH.o:bluetest.c:(.text+0x48): undefined reference to `BluetoothFindRadioClose#4'
collect2.exe: error: ld returned 1 exit status
Code is below:
#include <stdio.h>
#include <string.h>
#include <Windows.h> //not sure if needed
#include <Ws2bth.h> //not sure if needed
#include <bthsdpdef.h>
#include bluetoothapis.h>
//#include <bluetoothleapis.h>
#pragma comment(lib, "Bthprops.lib");
int main(void)
{
BLUETOOTH_FIND_RADIO_PARAMS btfrp; // structure
btfrp.dwSize = sizeof(btfrp); // creating space in memory for parameters?
HANDLE hRadio; // not sure what a handle is, something similar to a pointer?
HBLUETOOTH_RADIO_FIND hFind = BluetoothFindFirstRadio(&btfrp, &hRadio);
// BluetoothGetDeviceInfo(hRadio, &pbtdi);
printf("Bluetooth test!");
BluetoothFindRadioClose(hFind);
return 0;
}
It seems that my issue was not 100% my code, but about how I was attempting to compile my code. After looking further into the documentation I read the line, "Link only to Bthproprs.lib, and avoid linking to Ilprops.lib." So, I don't fully understand why I would need to link, when I have a #pragma comment(lib, "Bthprops.lib"); but that is most likely due to my own ignorance. I did notice the answer on this post which helped clear up my ignorance of HOW to link the Bthproprs.lib library. So, my code didn't change, but my compile did, gcc bluetest.c -o test -lbthprops.
Now, to return something actually useful.

MicroFocus cobol commands cobinit,cobcall and cobtidy are throwing errors in my C program

As per the documentation in Micro-focus support site, to call a cobol program from a C program we just need to follow the given below steps.
main(int argv, char *argv)
{
cobinit(); /* Initialize COBOL environment */
cobcall("cobep", 0, NULL); /* Call a COBOL program */
cobtidy(); /* Close down COBOL environment */
return(0);
}
Based on this I have come up with a simple C program to call an already working Cobol program, but guess I am getting linking error.
C Program
cat call.c
#include<stdio.h>
#include "cobcall.h"
#include "cobmain.h"
int main()
{
int ret=0;
cobinit();
ret=cobcall("cobolprogram.gnt",1,NULL);
cobtidy();
return 0;
}
Error message receiving
gcc -Wall call.c -o call
call.c: In function 'main':
call.c:10: warning: pointer targets in passing argument 1 of 'cobcall' differ in signedness
/usr/ccs/bin/ld: Unsatisfied symbols:
cobtidy (first referenced in /tmp/ccQBPw6r.o) (code)
cobcall (first referenced in /tmp/ccQBPw6r.o) (code)
cobinit (first referenced in /tmp/ccQBPw6r.o) (code)
collect2: ld returned 1 exit status
If you use MF then you likely have access to a paid support. In any case here's what I can tell you from knowing something about gcc and libraries.
The C compiler compiles fine. It only complains about signedness of a char * or const char *, but this shouldn't matter.
To solve this check in the header for the actual defintion of cobcall, I assume changing it to one of these should fix the compiler warning:
ret=cobcall((char *)"cobolprogram.gnt",1,NULL);
ret=cobcall((const char *)"cobolprogram.gnt",1,NULL);
ret=cobcall((unsigned char *)"cobolprogram.gnt",1,NULL);
ret=cobcall((const unsigned char *)"cobolprogram.gnt",1,NULL);
Side note: as far as I know you don't pass the file extension to cobcall, therefore to make it work later you may need to remove the .gnt part.
The errors you get are from the linker as it has no possibility to resolve these mf specific functions. I've skimmed over different MF docs but did not found the library name you need. Maybe it is libcob or libcobmf or libmfcob or ...
Edit: I've found a reference in an old MF manual naming the library libcobol.
As soon as you know the library name use -lname (for example -lcobol/ -lcob/ -lcobmf/-lmfcob) to let the linker know that it can resolve them in this library. Add -L/path/to/library to let the linker know where it can find the library.
If compilation worked any your main program complains about "cannot find libcob.so" (or libcobmf.so or whatever it is named) set LD_LIBRARY_PATH to point to the library name.

How to solve the 'undefined reference to' in C program?

#include <stdio.h>
#include <stdlib.h>
#include <winscard.h>
#include <wintypes.h>
int main(void){
SCARDCONTEXT hContext;
SCARDHANDLE hCard;
DWORD dwActiveProtocol;
LONG rv;
rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM,NULL,NULL,&hContext);
rv = SCardConnect(hContext,"Reader X", SCARD_SHARE_SHARED,
SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol);
printf("Hello world!\n");
}
There are errors like this:
test.c:(.text+0x2e): undefined reference to `SCardEstablishContext'
test.c:(.text+0x5b): undefined reference to `SCardConnect'
xcollect2: error: ld returned 1 exit status
The functions are included in 'winscard.h' but it seems I cannot use them.
I don't know how to solve it.
Including a header file usually just informs your translation unit (your program in this case) that certain things exist, in order than the code can be compiled,
To actually use those things, you need to do more than just figure out that they exist, you need to actually incorporate the code for them within your executable.
This is generally the responsibility of the link stage and, as per the Microsoft documentation, the code for these functions are to be found in winscard.lib/.dll. You need to modify your project so that those libraries are included in your build.

Example MQTT Client Code not working C

I got the example code from here.
I have the header file MQTTClient.h as well.
However when I build I get the errors:
undefined reference to MQTTClient_create
undefined reference to MQTTClient_connect
undefined reference to MQTTClient_publishMessage
undefined reference to MQTTClient_waitForCompletion
undefined reference to MQTTClient_disconnect
In the header file these are set up as follows:
DLLExport int MQTTClient_create(MQTTClient* handle, const char* serverURI,
const char* clientId, int persistence_type, void* persistence_context);
I am using a Windows 8 machine with Eclipse C/C++ IDE
I also have some paho-mqtt.dll's I'm not sure how to get the example code up and running.
Thank you
It means paho library is not linked. In Linux for a c program example you can link paho library by this way:
gcc -L{complete path for output folder} {filename}.c -l paho-mqtt3c
In my case it looks like:
gcc -L/home/jaydev/MQTT/org.eclipse.paho.mqtt.c/build/output test2.c -lpaho-mqtt3c

libuv undefined reference to uv_loop_new

After compiling, I am trying to run libuv sample program:
#include <stdio.h>
#include <uv.h>
int main() {
uv_loop_t *loop = uv_loop_new();
printf("Now quitting.\n");
uv_run(loop, UV_RUN_DEFAULT);
return 0;
}
But, when try to run, I get the following error:
**/tmp/ccHTpspB.o: In function `main':
main.c:(.text+0x9): undefined reference to `uv_loop_new'
main.c:(.text+0x28): undefined reference to `uv_run'
collect2: error: ld returned 1 exit status**
Where did I go wrong ?
PS: It doesn't work with #include "uv.h"
You need to link the libuv.a with your compiled code and the linker doesn't know where to find the compiled libuv.
To give you a better answer I would need to see you compile command but in the meantime I would strongly recommend this video where Ryan builds a sample libuv project.
The actual code he uses is a little out of date as the API has changed but I think you will find the start where he puts a project together very enlightening.
http://vimeo.com/24713213
In ubuntu I have used following command with success:
gcc sample.c -luv

Resources