Trouble using hash function from libsodium library - c

I have a question related to using hash function available in the libsodium library. https://libsodium.gitbook.io/doc/hashing/generic_hashing
The problem is when I try to use it I get an error message: undefined reference to crypt_generichash()
I am also confused about the installation procedure mentioned in here:
https://libsodium.gitbook.io/doc/installation
I just download the folder and place it in my code folder so I guess maybe the error is because of the reason that I didn't follow the configuration because I couldn't understand how to do it. Do I need to go to the path and then execute the commands mentioned like (./configure) but when I do it still gives me an error. As I am a beginner so I do not know how should I do it.
I am using:
Contiki (ver 3.0)
Language C
Ubuntu (16.04)

Related

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.

undefined reference to 'gnutls_...' functions

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).

Compiling specific apache module in VS2010

Over the last few days I've been tinkering with mod_pLua on Windows (https://sourceforge.net/projects/modplua/ or https://github.com/Humbedooh/mod_pLua).
The pre-built Windows binary works a treat, except it doesn't seem to have been compiled with mod_dbd support for database connectivity. The documentation suggests that to enable this feature you must compile with a certain tag, so I've been trying to compile the module in VS2010 - hoping that I'll be able to get mod_dbd support working at some point - but I've run in to a snag. It just will not compile.
What I've done so far:
Included apache/include and apache/lib, which got rid of a lot of
errors
Included lauxlib.h, lua.h, luaconf.h and lualib.h from Lua 5.2, which got rid of a lot of errors
Compiled a .lib file from Lua 5.2 sources and included it, which fixed a few errors
The errors I'm getting at the moment are:
error LNK2019: unresolved external symbol _luaL_openlib referenced in function _lua_dbopen C:\Users\Michael\Desktop\Projects\C\mod_plua\mod_plua.obj
And a plethora like this:
IntelliSense: a value of type "const char ()(cmd_parms *cmd, void *cfg, const char *arg)" cannot be used to initialize an entity of type "cmd_func" c:\users\michael\desktop\projects\c\mod_plua\mod_plua.h 394 5
As I'm not a C/C++ native, I only have a vague idea of what's wrong, and have likely done something wrong in my attempts to fix the issue. If someone could guide me in the right direction (or better yet, write a little instructional on how to compile the module from start to finish) I would be so happy.
I've uploaded my VS2010 project files and source here: https://dl.dropboxusercontent.com/u/51243175/mod_plua_vs2010.7z
Self-answer:
The primary reason for the failure to compile was the Lua .lib file. The Microsoft compiler does strange things when dealing with C code, so I got an appropriately compiled version of the .lib from the LuaBinaries SourceForge repository (http://sourceforge.net/projects/luabinaries/) - specifically, 5.2.3/Windows Libraries/Dynamic/lua-5.2.3_Win32_dll10_lib.zip (which is compiled for VS2010).
This didn't enable mod_dbd support, which requires headers and sources from the Apache APR project, but it did allow successful compilation.
You should not be using mod_pLua really, I haven't worked on that for nearly 3 years ;) You should use mod_lua instead, which comes bundled with httpd and works pretty much the same way (although it does not support the php-like scripting that mod_pLua does)
For DBD specific setups (especially how to use it on Windows), see http://modlua.org/api/database

How to use CUDA 6.0 with XCODE 5

My question may completely be a noob. Sorry, for that but I have been trying to compile my first Cuda code in Xcode and I'm lost where and how I could set up the IDE to invoke NVCC.
I installed the latest CUDA toolkit CUDA 6.0 and have even installed GCC 4.8 using brew. I have XCODE 5.5
When I run my code from XCODE all the directives like global are marked as unidentified.
I don't where and to change the settings to invoke NVCC. I will be really thankful, if anyone could help me with this.
Further, when I created the XCODE project, I created it as a C project. So, I placed the CUDA code in this C file, which is what is giving me the above mentioned errors. I tried to replace this .C file with a .cu file (just change the extension), which too failed badly - XCODE didn't even know what to do with the .cu files
COuld anyone please help me?
Thanks in Advance
I have given it a try. Although I have not completely succeeded I thought I'd post my progress here in hopes of helping others. The steps I took were inspired by this page.
Create a new Xcode project
Under Build Settings add a new user defined setting CC with the value /usr/local/cuda/bin/nvcc.
Add /usr/local/cuda/include to Header Search Paths under Build Settings.
Set Enable Modules (C and Objective-C) to No.
Add /usr/local/cuda/lib/libcuda.dylib to Link Binary With Libraries under Build Phases.
For any C files you create set their extension to .cu in the File Inspector, after you have done that you have to set the type of that file to C source to get syntax highlighting, by going to Editor->Syntax Coloring->C.
Problems with this setup:
- Xcode can't run the executable, at least nog if it is compiled for debugging. However you can make it copy the executable to some reasonable location and run it in the terminal.
- Whenever you try 'Build for running' sometimes Xcode magically destroys the whole project.

Waveform API linking error

I'm getting some kind of linking error with a program utilizing MS-s waveform API. The code I'm using can be found here: http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=4422&lngWId=3
It's the first bit of code on the page under the heading "Opening the Sound Device". I'm not getting any errors with the code, however my linker complains quite persistently. The output being the following:
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\crt2.o:crt1.c|| undefined reference to `SetUnhandledExceptionFilter#4'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\crt2.o:crt1.c|| undefined reference to `ExitProcess#4'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\crtbegin.o:cygming-crtbegin.c|| undefined reference to `GetModuleHandleA#4'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\crtbegin.o:cygming-crtbegin.c|| undefined reference to `GetProcAddress#8'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\libmingw32.a(pseudo-reloc.o):pseudo-reloc.c|| undefined reference to `VirtualQuery#12'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\libmingw32.a(pseudo-reloc.o):pseudo-reloc.c|| undefined reference to `VirtualProtect#16'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\libmingw32.a(pseudo-reloc.o):pseudo-reloc.c|| undefined reference to `VirtualProtect#16'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\libgcc.a(cygming-shared-data.o)||In function `cmshared_get_ptr_from_atom':|
c:\crossdev\b4.4.1-tdm-1\build-sjlj\mingw32\libgcc\..\..\..\..\gcc-4.4.1\libgcc\..\gcc\config\i386\cygming-shared-data.c|91|undefined reference to `GetAtomNameA#12'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\libgcc.a(cygming-shared-data.o)||In function `_cmshared_create_or_grab':|
c:\crossdev\b4.4.1-tdm-1\build-sjlj\mingw32\libgcc\..\..\..\..\gcc-4.4.1\libgcc\..\gcc\config\i386\cygming-shared-data.c|140|undefined reference to `FindAtomA#4'|
d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\libgcc.a(cygming-shared-data.o)||In function `cmshared_add_ptr_as_atom':|
c:\crossdev\b4.4.1-tdm-1\build-sjlj\mingw32\libgcc\..\..\..\..\gcc-4.4.1\libgcc\..\gcc\config\i386\cygming-shared-data.c|118|undefined reference to `AddAtomA#4'|
||=== Build finished: 10 errors, 0 warnings ===|
I can paste the build log here as well if need be. Could anybody let me know what I need to do to fix this? Or even better, how to troubleshoot it myself so I can fix future problems like this myself?
[EDIT]: Okay so I managed to solve this. While playing around in Project->Build Options->Linker Settings->Link Libraries I noticed that if I add something like kernel32.lib I get an error from ld saying "cannot find -lkernel32.lib". So I searched around till I found the libraries I required and I added absolute paths to them, and now my project compiles flawlessly! :D However this was kind of strange since I did add my library search path and it didn't seem to help. So I went over it again to see why it didn't seem to work and it seems like one has to add a trailing backslash to the path name, like if the libraries are located in "C:\SDK\Lib\" one has to add the trailing slash for Code::BLocks to search it correctly. Once that was fixed I changed the option in Linker Settings->Link Libraries to kernel32 as was recommended and now it works without a hitch.
Thanks to everybody who helped me out with this!!! ^_^
I got the same errors when I place a library into system32 and try to link to it with LIBS += L$$quote(C:/Windows/System32).
When I placed it into a normal directory and set the relative path to it, everything works alright.
Looks like you are not linking with Kernel32.lib Check your project properties.
I'd the same problem and after some time I figured out how to do it, the problem relies on the linker, it's trying to link some windows functions into the exe file, and the compiler cannot find those, this is how I solved this:
Install the Windows 7 SDK, you can download it from here: http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=3138
Add the library path to the search libraries on CodeBlocks
Project / Build Options (select The project if you want to link it to all the configurations you have) / Search Directories / Linker / Add and place the SDK Library path, which should be at: C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib
Add the references to the windows libraries on the linker settings:
Project / Build Options / Linker Settings / Add (at Link Libraries) and add kernel32, user32 and gdi32 (this last one should be added if you're using windows gui).
That's it... now rebuild your project and it should work flawlessly.
Note: You need to add this settings to the exe project, if you're creating libraries the error will be shown when try to link the exe file.

Resources