fatal error: sodium.h: No such file or directory - c

Thank you #stark I was unaware you had to link the directory as part of #include. This part is now working though when I include.
(sodium_init() < 0)
{
printf("Sodium could not be initialized");
return 1;
}
I now receive the error "undefined reference to 'sodium_init'.
I have tried adding -lsodium to the compile command (gcc -g -lsodium file1.c file2.c file1.h -o file1.c.exe) which gives the error.
"cannot find -lsodium collect2.exe: error: ld returned 1 exit status"
Through further searching I believe I need to tell the compiler where to find -lsodium though cannot find out how.
-- below has been solved using #stark advice --
I have been trying to get the sodium library working for the last 3 days. I have followed the instillation instructions here(https://libsodium.gitbook.io/doc/installation) which all appear to have completed successfully, but still receive the error.
I then found information suggesting I have not linked Visual Studio (community edition) to the library location.
I have attempted to follow the instructions here(https://www.learncpp.com/cpp-tutorial/a2-using-libraries-with-visual-studio-2005-express/) but cannot see "VC++ Directories". I have tried several other sets of directions with the same outcome.
Is anyone able to help getting the sodium library working so I can get access to the RtlGenRandom() function?

Related

gprbuild fails to include a file needed for gnatcoll

I tried to build something with GnatColl from GPS Community 2021 on Fedora 35. The linker failed, saying
ld: /path/to/common/Ada/Quoter/obj/gnatcoll-refcount.o: in function `gnatcoll__refcount__sync_bool_compare_and_swap':
gnatcoll-refcount.adb:(.text+0x622): undefined reference to `gnatcoll_sync_bool_compare_and_swap_access'
collect2: error: ld returned 1 exit status
This also fails if I try to run the project using gprbuild -P Quoter.gpr.
I can fix this from the command line by copying the failed command (gcc ...) and adding ~/opt/GNAT/2021/include/gnatcoll/gnatcoll_support.c to the list of files to compile, as that's the included file with the desired function. That's awfully inconvenient, though.
I guess I have something configured slightly wrong. Might anyone here have an idea?
I found the answer, and it's a bit embarrassing, but looking in the gnatcoll examples would have done it: add with "gnatcoll"; to the beginning of the gpr file.

Cannot Find Libraries [error: ld returned 1 exit status]

As the title suggests, I am having a problem linking some libraries to my code. Minuit2 is in
/home/christian/root/include
and when I compile I run the following:
g++ -I/home/christian/root/include niminimzationExample.cpp -o niminimzationExample -L/Minuit2/lib -lMinuit2
which gives me the following error
/usr/bin/ld: cannot find -lMinuit2
collect2: error: ld returned 1 exit status
Being a newbie, I am not even sure what the error exactly means or how to fix it. I run Minuit2 on another machine, which the same command, and everything works fine. Any help would be greatly appreciated.
Thanks,
Christian
I am not even sure what the error exactly means
The error means: linker searched for a file named libMinuit2.so and libMinuit2.a in /Minuit2/lib/ and then standard directories (usually /usr/lib and /lib), and didn't find it anywhere.
or how to fix it.
You need to find the directory in which one or both of libMinuit2.{so,a} are located, and then use -L/that/directory at link time to tell the linker where to find the library.

get_peer_certificate error when using wolfSSL

I'm new to using wolfSSL. I am trying to compile a set of codes using gcc.
gcc -o main main.c -lwolfssl
I encounter an error of main.c:(.text+0x47b): undefined reference to 'wolfSSL_get_peer_certificate'
collect2: error: ld returned 1 exit status upon entering the statement.
A snippet of the code shows the error location:
fprintf(stderr, "ERROR: failed to connect to wolfSSL\n");
return -1;
}
ret = certverify(CERT_FILE,verifyCert);
WOLFSSL_X509* webCert = wolfSSL_get_peer_certificate(ssl);
I have tried modifying the WOLFSSL_X509* webCert = wolfSSL_get_peer_certificate(ssl); command but it seems to be correct.
I am not too sure why this error is occuring. Can someone please help me with this?
I am using Kali Linux 2019.4 to compile this set of codes.
#wolfSSL_new,
It sounds like the application is failing to link the library so while the right headers are in place to locate the function definitions the final step to link the function is what is failing. Where is libwolfssl.so or libwolfssl.a located on your system? Is it in /usr/local/lib/libwolfssl.so or /usr/local/lib/libwolfssl.a?
(.a is a static library, .so is a shared object library it can be either or)
Once you located where it is try this build command instead (For the sake of an example I am going to assume it is in /usr/local/lib):
gcc main.c -o main -I/usr/local/include -L/usr/local/lib -lwolfssl
Let me know if that resolves the linker error you are seeing.
[UPDATE]
This was resolved by adding the configure setting --enable-opensslextra
[END UPDATE]
Regards,
K

arm toolchain does not seem to have C libraries

I am trying to cross compile a simple program with the arm toolchain. And stdio library points to another library, which results in the following error:
/home/sansari/tools/arm-eabi-4.7/bin/arm-eabi-gcc hello.c -o hello
In file included from hello.c:3:0:
/home/sansari/tools/arm-eabi-4.7/bin/../lib/gcc/arm-eabi/4.7/include-fixed/stdio.h:50:23: fatal error: sys/cdefs.h: No such file or directory
compilation terminated.
make: *** [hello] Error 1
At first, I thought this file is in some subdirectory of the toolchain, and I need to include the folder for this library in my makefile. But a quick tree output says that it is not. So given that I have used this toolchain successfully for a larger project, I know it is copied from somewhere. So my question is how do I add it to this project please? And what is the appropriate place to copy it from? I am trying to understand why it is not in the toolchain folders that I have, and how I should add it to my project please.
#Olaf - You have been very helpful; I however have a little more learning curve. But I do understand what you are instructing. I know I have the libraries in my build system since have built for this platform successfully. I even know that it is in my WORKING_DIRECTORY. What I do not know is if I can copy a folder and address the issue entirely or do I need to keep compiling and see what errors I get. That is do it incrementally. For example, one of the files, which was missing was cdefs.h. And I was able to find it in the folder:
/home/sansari/ndk/android-ndk-r10d/platforms/android-19/arch-arm/usr/include/sys/cdefs_elf.h
So I copied it over and the build process proceeded to the next stage. I do like to know if I should perhaps have copied the entire /sys or /include directory or compared the /include directory of my source and make sure all the files are also in the destination directory also. And that way I can avoid having to compile a number of times.
But nevertheless, I proceeded with copying one file at a time. The last error I got is:
/home/sansari/tbt/tools/arm-eabi-4.7/bin/../lib/gcc/arm-eabi/4.7/include/stdint.h:3:26: fatal error: stdint.h: No such file or directory
And I look in the include directory; I see a file call stdint.h
What do you make of that? Does that make sense to you? I am confused by this error. How can I get this error when the file is in the directory. Basically it seems make is saying this file does not exist when it does.
I did find This post also, which seems to say what you are saying. I just need to know what is the best way to address it.
#Olaf - I really appreciate all your help. I was able to get through all the library errors by putting an include statement in my makefile. Now the linker is giving me errors as follows:
/home/sansari/tbt/tools/arm-eabi-4.7/bin/arm-eabi-gcc -I../../ndk/android-ndk-r10d/platforms/android-19/arch-arm/usr/include hello.c -o hello
/home/sansari/tbt/tools/arm-eabi-4.7/bin/../lib/gcc/arm-eabi/4.7/../../../../arm-eabi/bin/ld: cannot find crt0.o: No such file or directory
/home/sansari/tbt/tools/arm-eabi-4.7/bin/../lib/gcc/arm-eabi/4.7/../../../../arm-eabi/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
make: *** [hello] Error 1
update - I searched for a solution for the above errors. The first error is discussed here and -nostartfiles switch seems to work for me for now. I found this link that talks about libc.a being the fix for the error about not finding -lc. So I found an appropriate copy of libc.a and passed the location to the linker. The program compiles, but I get one last warning as follows:
warning: cannot find entry symbol _start; defaulting to 00000000000080dc
For which this link suggested using --entery-main switch. So now I have an executable. I want to thank you again. If you do see any problem in what I have done, please post something for me. it is gonna take a while for me to get this executable on my device.

Mingw and Eclipse unable to find library - 2

I am faced with the exact same situation as the question raised by Gustavo in the following Link. Also, I have tried all the solutions posted in that link and other tags (such as changing library names from opus.a to libopus.a, change '\' to '/' and so on) but none of these have solved my problem. By opening the properties of the library file, these are the following things displayed:
Path: /demo/opusfile/libopusfile.a
Type: File (Static Library)
Location: U:\data\Jag\eclipse\wrksp\demo\opusfile\libopusfile.a
The error message displayed by Mingw is as follows:
15:56:57 **** Incremental Build of configuration Debug for project demo ****
Info: Internal Builder is used for build
gcc -o demo.exe "src\\demo.o" -lU:/data/Jag/eclipse/wrksp/demo/opusfile/libopusfile.a
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lU:/data/Jag/eclipse/wrksp/demo/opusfile/libopusfile.a
collect2.exe: error: ld returned 1 exit status
collect2.exe: error: ld returned 1 exit status
Could someone please let me know what am I missing ? I am not able to resolve this issue
I think I found the solution, thanks to the answer posted in this Link. So basically to summarize the solution, I had to remove the 'lib' prefix, the '.a' suffix and the library path when I specified the libraries (-l parameters). The library path has to be specified in the -L parameter . This resolved the above problem but led to another hurdle by Mingw:
libopusfile.dll.a: could not read symbols: Archive has no index; run ranlib to add one.
I executed the 'ranlib' command in the command prompt
cmd_path> ranlib libopusfile.dll.a
, as suggested by the compiler, and this solved all my issues!

Resources