undefined reference to 'gnutls_...' functions - c

So for an assignment I need to use GnuTLS. I have downloaded gnutls by following this guide http://www.bauer-power.net/2014/06/how-to-install-gnutls-3123-from-source.html
However, using any of the gnutls functions, similar to how they are used in the official gnutls documentation (http://www.gnutls.org/manual/html_node/Client-examples.html), displays several errors after building. All errors follow this format:
...pathtofile:line#/..undefined reference to 'gnutls_...'
I understand that this might be a linking problem, however I am quite new to this type of environment. What should I do? I have tried to install gnutls again several times.
I am using Ubuntu 14.04, gnutls-3.1.23 and eclipse Luna.
Thanks in advance.

You probably have an error on your link line.
Add the flag -lgnutls to the ld command (or, if just one C file, the compile line).

Related

Why linker error when trying to compile SDL?

I am watching a seminar on writing 2D games in C, on YouTube here:
https://www.youtube.com/watch?v=yFLa3ln16w0&t=654s
The instructor says to install the SDL software packages, using apt-get install. I already have these files. I checked, and they are in the C search path, in the directory /usr/include/SDL2. The instructor has a GitHub with example code that demonstrates the basics of SDL. Here is the GitHub repository:
https://github.com/tlively/sdl_seminar
Here is SDL's website:
https://www.libsdl.org/
The problem is, when I try to compile the file hello1_sdl.c (in the GitHub repoistory) using gcc -o hello1_sdl hello1_sdl.c, it gives me an error. I looked up what it meant, and it's a linker error. I don't understand why this is happening, as the header files are in the appropriate place.enter image description here
How do I fix this?
The include files for the C/C++ compilers are only half the story. You also need to tell the linker to use the library! If you have everything set up properly, all you should need to do is add -lSDL2 to your final command line (the one with -o that does the linking.)
See more examples at: Lazy Foo' Productions

How to link Libb64 libraries at compiling?

I need to use Base64 encoding/decoding in my C program and I tried to use some functions of Libb64 library. When I compile the code, it gives the error below:
... undefined reference to 'base64_init_encodestate'
... undefined reference to 'base64_encode_block'
... undefined reference to 'base64_encode_blockend'
collect2: error: ld returned 1 exit status
I tried to compile code with parameters like -libb64, -llibb64, -lbase64 but it didn't work.
What is the link parameter should I add when compiling? Or are there any ways solve this problem?
You can try -lb64. It is a guess and may not work. Try it and if it does not work I will actually install and answer with accuracy.
Edit 1: Although it solved your problem but this is not real answer. Whenever you install a library on Linux(it is an assumption that you are using Linux) then it gets installed by the name of libxyz.so and your switch to compiler/linker should be -lxyz. In case you do not know the name of library then check with something like Synaptic to know what files are installed by that package. If you are installing by source then look at the libraries generated in the source directory from where you are installing. I do not know exact commands for yum, apt-get or pacman or emerge which are package managers for different distributions but you can read the man page and know that as well.

error: unknown type name 'CURL'

I wrote a C library that utilizes the libcurl library to interact with a REST API. I wrote this on a debian based system, but am now attempting to use it on an Arduino, which runs an OpenWRT distribution. When trying to use it, I noticed there was an issue when the compiler attempts to use the libcurl library, so I wrote a super simple program to test it.
#include <curl/curl.h>
void main() {
CURL *curl;
}
I then compiled it like so...
gcc -lcurl test.c -o test
and got back the following.
test.c: In function 'main':
test.c:4:2: error: unknown type name 'CURL'
libcurl was already installed on the device.
Package libcurl (7.29.0-1) installed in root is up to date.
Here's what displays when I run opkg files libcurl
Package libcurl (7.29.0-1) is installed on root and has the following files:
/usr/lib/libcurl.so.4
/usr/lib/libcurl.so.4.3.0
Having the hardest time trying to figure out what the problem is. This link was the only thing I found remotely close to being similar to my problem, but the solutions didn't work for me. Does anyone have any suggestions?
Thanks.
EDIT: So I think I found some more information about the problem. I think I'm missing a lot of the libcurl development packages as well because I looked at the opkg.conf file and saw that the only package list was the following.
http://downloads.arduino.cc/openwrtyun/1/packages
Maybe I need to find an OpenWRT package list having the extra libcurl packages I need? I can't seem to find them though.
So I was able to solve my problem, but I guess not "properly".
Apparently, the OpenWRT distribution I'm running uses a completely different libcurl library, and when I tried to uninstall it, the opkg package manager warned me that because it too also utilizes the currently installed libcurl library, it might break if I remove it.
Therefore, I manually installed the version of libcurl I needed from Github, and then made the proper references in my code to use this other version instead.
Thanks everyone for helping me get in the right direction.

Linker cannot find existing Static Library File

I have a Eclipse project using C programming language. I have been stuck with a problem related to linker error since two days now. I have checked various forums to find a solution. Tried a lot of the suggestions but could not resolve it. So as a last resort, i am asking question here. My main program MotorRun.c has code which calls functions in the static library FtMscLib_Static_LIBCMT_Release.Lib which is in Libs folder in the path C:\FT-Project\Common\Libs. I am using MinGW gcc compiler.
When i run the makefile, it generates an error:
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.9.1/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lC:\FT-Project\Common\Libs\FtMscLib_Static_LIBCMT_Release.Lib
collect2.exe: error: ld returned 1 exit status
The code run by the makefile is
gcc "-LC:\\FT-Project\\Common\\Libs" -shared -o libRoboCopMinGW.exe "src\\MotorRun.o" "-lC:\\FT-Project\\Common\\Libs\\FtMscLib_Static_LIBCMT_Release.Lib"
By looking at the execution code, we can see that the paths and library name has been set correctly, but the linker just cannot find it so that it can link the library with my MotorRun.o object file. Hope someone can help me in finding a solution.
The program MotorRun.c is a very simple one, so i am not posting it here. But if necessary i can update it later. Thanks in advance!
The correct linker syntax is typically something like:
-Lpath_to_library_directory -lname
where the library filename (for a Windows static library) would be name.lib. So your above linker line needs to lose the .lib part. You may also need to prefix the -l argument with another argument -static, to instruct the linker to search for the static library FtMscLib_Static_LIBCMT_Release.Lib otherwise it might try to find the DLL instead.
By the way, there are heaps of posts on StackOverflow regarding the issue of static and dynamic linking with MinGW, so feel free to search for these also. The MinGW web pages also have numerous tips on the same topic.

Source file not compiled Dev C++

I just installed Dev C++ and I am learning C programming.
the code i used was
#include <stdio.h>
int main()
{
printf("Hello world");
getch();
}
I saved it as a .c file. When I compile it works fine, but when I compile and run it says source file not compiled. So I googled buncha things and came across this video on youtube which shows you how to fix it. I also saw other forums on google which suggest the same thing... However, after doing whats asked, Now I can't even compile my code. I get this error
Compiler: Default compiler
Executing C:\Dev-Cpp\bin\gcc.exe...
C:\Dev-Cpp\bin\gcc.exe "C:\Users\ubaid\Documents\C\Untitled1.c" -o "C:\Users\ubaid\Documents\C\Untitled1.exe" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
gcc.exe: Internal error: Aborted (program collect2)
Please submit a full bug report.
See <URL:http://www.mingw.org/bugs.shtml> for instructions.
Execution terminated
I have also used what is asked on this link, and still no luck..
http://learntogeek.com/miscellaneous/solved-source-file-not-compiled-error-in-dev-cpp/
I am using windows 8
I was having this issue and fixed it by going to:
C:\Dev-Cpp\libexec\gcc\mingw32\3.4.2
, then deleting collect2.exe
Install new version of Dev c++. It works fine in Windows 8. It also supports 64 bit version.
Download link is http://sourceforge.net/projects/orwelldevcpp/ .
I guess you're using windows 7 with the Orwell Dev CPP
This version of Dev CPP is good for windows 8 only. However on Windows 7 you need the older version of it which is devcpp-4.9.9.2_setup.exe
Download it from the link and use it.
(Don't forget to uninstall any other version already installed on your pc)
Also note that the older version does not work with windows 8.
This maybe because the c compiler is designed to work in linux.I had this problem too and to fix it go to tools and select compiler options.In the box click on programs
Now you will see a tab with gcc and make and the respective path to it.Edit the gcc and make path to use mingw32-c++.exe and mingw32-make.exe respectively.Now it will work.
The reason was that you were using compilers built for linux.
You can always try doing it manually from the command prompt. Navigate to the path of the file and type:
gcc filename.c -o filename
I found a solution. Please follow the following steps:
Right Click the My comp. Icon
Click Advanced Setting.
CLick Environment Variable. On the top part of Environment Variable Click New
Set Variable name as: PATH then
Set Variable Value as: (" the location of g++ .exe" )
For ex. C:\Program Files (x86)\Dev-Cpp\MinGW64\bin
Click OK
This error occurred because your settings are not correct.
For example I receive
cannot open output file Project1.exe: Permission denied
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe: *** [Project1.exe] Error 1
Because I have no permission to write on my exe file.
After some investigation, and with Dr.Topaz's help, I have learned that you will want to confirm that the program set for g++ in the Compiler Options really does compile the source code. In my case, the C:\Dev-Cpp\bin\g++.exe program did not create an exe, but the C:\Dev-Cpp\bin\c++.exe program did. Either program appears to be intended to take the same arguments and options as GNU g++. I would love to find an actual doc on the Dev-C++ compiler programs, but I have not so far.
You can test the compiler program with a simple example like this:
C:\Dev-Cpp\bin\c++.exe hello.cpp -o hello.exe
Currently in 2021, the Dev-C++ site invites you to download either original Dev-C++ or a newer fork by a group named Embarcadero.
I decided to try the Embarcadero version and the experience was slightly better. The UI is still a tad dated, but the g++.exe program it came with was able to compile programs without issue. Again, take note of where the program is being installed, but in my case, the Embarcadero compiler programs were in C:\Program Files (x86)\Embarcadero\Dev-Cpp\TDM-GCC-64\bin.
Both original Dev-C++ and Embarcadero come with mingw-32 versions of the compiler programs that from what I see do work in a Git Bash console, with slight differences such as not recognizing a default locale when using the command std::cout.imbue(std::locale("")).
I faced this similar error, and none of the solutions worked.
so I tried to download the latest version from here, https://www.bloodshed.net/
I rerun the program.
and everything is now working correctly.
I was facing the same issue as described above.
It can be resolved by creating a new project and creating a new file in that project.
Save the file and then try to build and run.
Hope that helps. :)

Resources