Undefined reference to (Quickmail) - c

I am looking for how to install quickmail.
I put quickmail.h here: C:\Program Files\CodeBlocks\MinGW\include, the .a and .la here: C:\Program Files\CodeBlocks\MinGW\lib.
I linked these .a files by adding them in the linker settings. I also did include the library like this: #include <quickmail.h>, but the functions are not recognized.
What should I do ?
The 4 files in the bin folder are in the project folder and I downloaded files from here : quickmail - Sourceforge.
EDIT : I get \main.c|9|undefined reference to '__imp_quickmail_initialize'| \main.c|10|undefined reference to '__imp_quickmail_create'| \main.c|11|undefined reference to '__imp_quickmail_set_body' and I put C:\Program Files\CodeBlocks\MinGW\include in search directories.
This is the code :
#include <stdio.h>
#include <stdlib.h>
#include <quickmail.h>
int main()
{
const char* error;
quickmail_initialize();
quickmail mailobj = quickmail_create("aaa#gmail.com", "libquickmail test e-mail");
quickmail_set_body(mailobj, "This is a test e-mail.\nThis mail was sent using libquickmail.");
quickmail_add_attachment_file(mailobj, "words.txt", NULL);
if ((error = quickmail_send(mailobj, "smtp.gmail.com", 587, "aaa#gmail.com", "MAGA2020")) != NULL)
fprintf(stderr, "Error sending e-mail: %s\n", error);
quickmail_destroy(mailobj);
return 0;
}
Sorry, the site gave me the wrong version.

To use a library you need to include the header in the code (in this case #include <quickmail.h>) and if needed tell the compiler where to find this file (the full path to the lib folder) with the -I compiler flag.
Next you need to tell the linker to link with the library (in this case -lquickmail or -lquickmaillight) and if needed where to find this file (the full path to the lib folder) with the -L linker flag.
Your errors are linker errors, so it seems the second step wasn't properly done.
In Code::Blocks it looks like this (though unlike the screenshots you should set it at the top-level instead of just for Debug builds):

Related

Codeblocks undefined reference to functions error. Already tried add include directory to project build options

I recently inherited a console application that I do not have the project file for. I only have the executable file, the main.c and a bunch of .h header files. I need to edit the main.c and produce an exe file with my edits.
I created a new C console application project on Codeblocks then pasted the main.c contents from the "hand me down" file onto the new project's main.c.
I just edited a fieldname on the main.c file. A very minor edit.
I pasted the .h files to C:\Program Files\CodeBlocks\MinGW\include.
I go to Project >> Build Options >> Search directories >> Compiler >> Add the above include path (saw this step on codeblocks forum and on stackoverflow)
Now the problem is; I'm getting errors, there are multiple undefined reference to 'functionNames'.
These function names are inside the .h files.
I also included the path not just on Compiler but on Linker and Resource compiler to no avail, still getting the same error.
Some of the include .h on main.c also references other .h files which are also pasted on the CodeBlocks\MinGW\include folder.
The include calls are <> and not "" since they are pasted on mingw\include. These .h files are from an api package.
#include <stdio.h>
#include <windows.h>
#include <global.h>
#include <osfile.h>
#include <mail.h>
.. etc
What am I missing? Thanks!

Eclipse C problems with including .h files

I am trying to compile a code. I have the following Structure
RLW/RLW.c (inside a folder)
RLW/RLW.h
main.c
In the main.c if I have the following line
#include "RLW.h"
It does NOT COMPILE and the line has the error RLW.h no such file or directory
if I put the following line in main.c
#include "RLW/RLW.h"
The code COMPILES but there is still the error RLW.h no such file or directory.
I have added the path to the RLW Folder in
Properties->C/C++ General -> Paths and Symbols -> Includes -> GNU C
Any help on how to fix the error?
You have mentioned that inside folder RLW, RLW.h file is available. main.c is present in current working directory(CWD). So to include the folders present in CWD you need to give path as "./folder/xyz.c".Hence giving the include line as #include "./RLW/RLW.h" will solve your problem

How to include libssh to my project

I've installed libssh following the instructions and even though everything seems to be OK my compiler still returns the error "file not found" in the line "#include ". I guess it has something to do with directories or links (I have "make install" in the same folder where I downloaded it) but I don't know where should I put it so I can #include it in any project.
This is how I installed it:
I downloaded it and unzip it into the folder "libssh" on my Desktop (Mac).
Then I did
cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug ..
make
and finally:
sudo make install
Then in my program I have:
#include <libssh/sftp.h>
And XCode returns: "libssh/sftp.h file not found". I tried adding the libssh folder in the Desktop to the project, but I still have similar problems.
I guess I should install it (somehow) to the /usr/include folder, so that any project can use it (like pthread or many others), but I don't know how to do this.
If I include any other file in /usr/include it works fine (like ) but when I #include it returns file not found, even though if I cd to /usr/include/libssh the file libssh.h does exist.
This is the very simple sample code:
#include <stdio.h>
#include <pthread.h> //OK
#include <libssh/libssh.h> //Not OK, file not found.
int main(int argc, const char * argv[])
{
printf("Hello World!");
return 0;
}
In the tutorial is described how you have to link the library
You have two possibilities here:
As described you have to add those two lines to your code
#define LIBSSH_STATIC 1
#include <libssh/libssh.h>
You compile your code with the LIBSSH_STATIC flag.
gcc -DLIBSSH_STATIC test.c -o test.o
I thought that if you have the library in /usr/include the compiler will automatically link it. For instance, the pthread.h file is included properly without doing anything.
This is a system library which gets linked automatically most of the time. libssh is not. Thats why you have to be more specific on how to compile/link it.
Ive had a very similar problem several times and I have solved it by removing the ≤ ≥ symbols from around my header files and using ""s and the absolute path to the header file you're including. Now this doesn't solve your libssh install problems but it will allow you to compile just the way you have it as long as you know the absolute path of your header file and all of your header's dependencies are in the respective locations that they were inteded to look for them in. Hope this helps.

fatal error: sdl.h: No such file or directory

I'm having some issues getting a CHIP-8 interpreter to compile.
Upon pressing ctrl+f9 to compile I am met by a message saying "Build ended with errors. Continue?".
Checking the build log reveals the following error: C:/Workspace/****/****/main.c:4:17: fatal error: sdl.h: No such file or directory
I have tried copying SDL.h into the source directory, that did not work.
I tried making a directory in source called "SDL" (src/SDL/SDL.h), did not work.
I also tried making a folder next to src, (SDL/SDL.h). That did not work either.
After that I tried #include <.SDL.h>, #include <.sdl.h>, #include <.SDL.dll> and #include <.sdl.dll> (ignore the period after the "<" symbol)
I have also tried copying over the files for SDL version 1.2.15 and SDL version 2.0.3. That did work either.
Am I doing something fundamentally wrong?
How do I get this to compile?
You have to say your compiler where sdl.h lives, with -I/path/to/sdl switch on gcc or filling Include Path in msvc
(don't move it, as it (sdl.h) will probably needs other header files)
Here's a step-by-step on how to get SDL1.2.5 working with codelite:
Download the "Development Libraries" from here
Extract the tar.gz file contents to a directory. For eg: C:\mysdl
In codelite, right-click over the project's name in the "Workspace View"
From the context menu, select "Settings..."
The 'Project Settings' dialog will appear.
In the "configuration Type" choose "Debug" or "Release", based on your requirements. You can also, do the following steps for both Debug and Release.
Go to "Compiler" tab
In "Additional Search Path", add the path where all the sdl include files are. For eg: C:\mysdl\include
Go to "Linker" tab
In "Library Path", add you lib path eg: C:\mysdl\lib\
In the "Options" append -lSDL -lSDLmain -lmingw32 -mwindows(case-matters)
Copy C:\mysdl\bin\SDL.dll to C:\WINDOWS\SYSTEM32 or if 64-bit C:\Windows\SysWOW64
When including headers you must use #include "SDL\SDL.h" or #include "SDL.h" depending on how you configure your directory structure.

Undefined references when compiling gSOAP client

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.

Resources