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
Related
I have a very old C program and want to compile to Windows. So I try doing this:
gcc -DNO_GLIBC=1 sakide.c -o sakide.exe
and this returns:
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0xa4): undefined reference to `ekiGetLibVersion'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0x6b6): undefined reference to `ekiGetLibVersion'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0x8ff): undefined reference to `ekiEncodeUrl'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0x954): undefined reference to `ekiDecodeUrl'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0x993): undefined reference to `ekiDecodeUrl'
\AppData\Local\Temp\ccx7khiy.o:sakide.c:(.text+0xa62): undefined reference to `ekiGetKeyInfo'
collect2.exe: error: ld returned 1 exit status
This ekiGetLibVersion is in a .h file:
INT EKIAPI ekiGetLibVersion(char *outBuffer, LPINT outBufferSize);
and I also have a .dll name of it.
Ive never compiled anything with C though
On windows you cannot link against directly with the .dll, you have to link the import library, name .lib. For more information, refer:
On dynamic linking:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682592(v=vs.85).aspx
On implicit linking:
https://msdn.microsoft.com/en-us/library/d14wsce5.aspx
You are getting linker errors.
You need to link the library (or object file) where those functions are defined.
Undefined reference usually means the compiler has not seen a proper declaration for this variable. Did you include the header file (which defines this variable) in your C program ?
#include "header_file.h"
I seem to be getting the rookie error where it says, undefined reference to 'check', as shown below:
This should not be a problem, as I have in fact made a check.h and included in hiker.c, as shown below:
Does anybody know the source of this problem? I have just started using MinGW(as I wanted to learn programming C on Windows).
Here is a picture of the main function. I can add the code too if necessary:
I guess that check function is implemented in a file check.c
You must link that file also, because of your check.h export the prototype to let the compiler know how the check function is structured, but the linker needs the check function code compiled and reachable.
What you need is to compile using a command like this:
gcc -Wall hiker.c check.c -o hiker.exe
Take also note that linker is giving you another error about WinMain#16
This means that you started a windows application project, I guess you must change your project to console project type.
While compiling code that uses the SCTP kernel header <sctp/chunk.h>I got a puzzling compiler error(with blue text instead of read) that was trigged by the calling of the kmalloc function whose prototype is defined in <linux/slob-def.h>. Here is the function that caused it:
/* Allocate and initialize datamsg. */
SCTP_STATIC struct sctp_datamsg *sctp_datamsg_new(gfp_t gfp)
{
struct sctp_datamsg *msg;
msg = kmalloc(sizeof(struct sctp_datamsg), gfp);
if (msg) {
sctp_datamsg_init(msg);
SCTP_DBG_OBJCNT_INC(datamsg);
}
return msg;
}
The gcc error message(compiling in native C):
/tmp/ccKDKVjf.o: In function `sctp_datamsg_new':
s.c:(.text+0x2215): undefined reference to `__kmalloc'
collect2: error: ld returned 1 exit status
So what I'm wondering is if the kmalloc function source code properly defined(or not actually implemented at all, or if code that calls this function can only be compiled in kernel mode. I was not actually trying to build an output file(yet), the compile command I issued in Emacs was: gcc s.c (where s.c is the .c file that contains the <sctp/chunk.h> header — just trying to make sure everything compiles properly before building an output file).
That's a linker error, the code compiled fine. Next time, specify -c to avoid linking.
If you are trying to build kernel source without including kernel headers and linking against other kernel modules and the kernel itself, you are going to get errors.
You cannot just use gcc to build kernel source code. There is a way to build them.
I'm trying to create a client for a web service in C. I was generated C files with the wsdl2h and soapcpp2. In netbeans I'm added the generated files and the gSOAP include dir to the project's include directories.
my main file looks like this:
#include <stdio.h>
#include <stdlib.h>
#include <soapH.h>
#include <webserviceSoap12.nsmap>
int main(int argc, char** argv) {
struct soap *soap1 = soap_new();
struct _ns1__getAllCustomer *quote;
struct _ns1__getAllCustomerResponse *quote2;
if (soap_call___ns2__getAllCustomer(soap1, NULL, NULL, quote, quote2) == SOAP_OK)
printf("asd\n");
else // an error occurred
soap_print_fault(soap1, stderr); // display the SOAP fault on the stderr stream
return (EXIT_SUCCESS);
}
I copied the most of this from the gSOAP website's getting started section.
When I try to compile i get the following error:
build/Debug/MinGW-Windows/main.o: In function `main':
\NetBeansProjects\WebServiceClient/main.c:19: undefined reference to `soap_new_LIBRARY_VERSION_REQUIRED_20808'
\NetBeansProjects\WebServiceClient/main.c:22: undefined reference to `soap_call___ns2__getAllCustomer'
\NetBeansProjects\WebServiceClient/main.c:25: undefined reference to `soap_print_fault'
If I add the "soapC.c" "soapClient.c" "soapClientLib.c" files to the project I get a bunch of more undefinied reference.
What am I doing wrong? I'm using Netbeans ide with MinGW compiler on Win7. What other libraries I need or what other files should I include?
I managed to solve the problem by adding the files "soapC.c" "soapClient.c" "stdsoap.c" to the project files and in the Project propertie - Include Directories adding the files generated by soapcpp2 and the gSOAP toolkit's gsoap directory
You will need to link in the proper libraries. You will need to add the appropriate libraries using the -l switch and you will optionally need to pass the path to where these libraries reside via -L. Also, note that the libraries ending with a ++ are typically the ones you should use if you're using C++. So, your command line shoulde include at least:
For C:
gcc ... -lgsoap -L/path/to/gsoap/binaries
For C++:
g++ ... -lgsoap++ -L/path/to/gsoap/binaries
Also, depending on whether you're using additional features such as SSL, cookies etc. you will need to link these libraries in too:
g++ ... -lgsoap++ -lgsoapssl++ -L/path/...
If you're using a different toolchain, lookup the documentation for the exact switches.
I had this problem in Debian BullsEye (11), -lgsoap++ is necessary and it was solved when I added /gsoap_library_path/libgsoap++.a to g++ compiler command line.
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.