OpenSSL ON WINDOWS!! - ld.exe cannot find -lcrypto/-leay32 [duplicate] - c

This question already has answers here:
Cannot find libcrypto library error
(2 answers)
Closed 9 years ago.
I am trying to build a C file using OpenSSL on (64-bit) Windows 7. I have downloaded the latest full binary from the official OpenSSL site, and am using MinGW, and have added the respective bin directories to PATH. However I am getting the following error :
c:\Workspace\OSAccess\c>gcc -I%JAVA_HOME%\include -I%JAVA_HOME%\include\win32 -Ic:\OpenSSL-Win64\include -std=c99 -lm -lcrypto -o libosaccess.dll osaccess.c
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lcrypto
collect2.exe: error: ld returned 1 exit status
I cannot find any file called libcrypto.dll or cryptolib.dll, so I tried to build my own OpenSSL from source, using the install notes supplied, as I can see that the static libraries for crypto and ssl do not seem to be shipped with the Windows install. I have seen references in other posts to a couple of other libraries, libeay32 and ssleay32, but these return the same error.
If I remove the -lcrypto (or other) then I get Undefined reference errors:
c:\Workspace\OSAccess\c>gcc -I%java_home%\include -I%java_home%\include\win32 -Ic:\OpenSSL-Win64\include -std=c99 -lm -o libosaccess.dll osaccess.c
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x383): undefined reference to 'Netbios#4'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x3d1): undefined reference to 'Netbios#4'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x445): undefined reference to 'Netbios#4'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x73d): undefined reference to 'EVP_CIPHER_CTX_init'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x742): undefined reference to 'EVP_aes_256_cbc'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x76a): undefined reference to 'EVP_EncryptInit_ex'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x794): undefined reference to 'EVP_EncryptUpdate'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x7d2): undefined reference to 'EVP_EncryptFinal_ex'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x81c): undefined reference to 'EVP_CIPHER_CTX_cleanup'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x865): undefined reference to 'EVP_CIPHER_CTX_init'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x86a): undefined reference to 'EVP_aes_256_cbc'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x892): undefined reference to 'EVP_DecryptInit_ex'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x8bc): undefined reference to 'EVP_DecryptUpdate'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x8fa): undefined reference to 'EVP_DecryptFinal_ex'
C:\Users\xxxx\AppData\Local\Temp\ccbi3e1T.o:osaccess.c:(.text+0x930): undefined reference to 'EVP_CIPHER_CTX_cleanup'

If libcrypto.dll or cryptolib.dll are not there , i will recommend you to try and copy it from any other system . I had similar problem with , luckily found it on another system and copying worked well too.
Regards,
Jain

Related

Newly downloaded gcc throws undefined reference to `__chkstk_ms' error

I recently downloaded gcc and g++ compiler using MinGW and tried a simple hello world printing file in c. Whenever I run the code using visual studio code(using the code-runner extension made by jun han), I run into the following error:
C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libmingw32.a(setargv.o):(.text+0x33): undefined reference to `__chkstk_ms'
C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libmingwex.a(glob.o):(.text+0x6d2): undefined reference to `__chkstk_ms'
C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libmingwex.a(glob.o):(.text+0x8b8): undefined reference to `__chkstk_ms'
C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libmingwex.a(glob.o):(.text+0x900): undefined reference to `__chkstk_ms'
C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libmingwex.a(glob.o):(.text+0xa25): undefined reference to `__chkstk_ms'
C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libmingwex.a(glob.o):(.text+0xc15): more undefined references to `__chkstk_ms' follow
collect2: ld returned 1 exit status
NOTE: I HAVE SEEN THE POST BY YUNUS
3.4.5, is that the version? That's very old!
Which MinGW were you using exactly?
I recommend using MinGW-w64 as it's more up to date.
You can get a standalone build from https://winlibs.com/
As for your errors, they are related to stack protection settings. Make sure you don't have different MinGW's in your system or referred to by environment variables like PATH.
add gcc path to you envionment variables

How to fix "undefined reference to 'something'" although all required files are already included? [duplicate]

This question already has answers here:
Why does the order in which libraries are linked sometimes cause errors in GCC?
(9 answers)
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 3 years ago.
Github :: https://github.com/mmgaggle/sslsqueeze
I am trying to build from source a code from github called "sslsqueeze". I have installed all required libraries but "make" command is still unable to link them for some reason. I am sure there is a very simple point/step I am missing here, but after hours of debugging, I am turning to you.
sslsqueeze.c file contains the line:
**sslsqueeze** needs to be linked with -levent_core from libevent2 library.
Accordingly I have installed libevent-dev library. And I run this command:
make
This is my list of errors :
sslsqueeze.o: In function `new_connection':
sslsqueeze.c:(.text+0x57): undefined reference to `bufferevent_socket_new'
sslsqueeze.c:(.text+0x68): undefined reference to `bufferevent_set_timeouts'
sslsqueeze.c:(.text+0x88): undefined reference to `bufferevent_setcb'
sslsqueeze.c:(.text+0x9d): undefined reference to `bufferevent_socket_connect'
sslsqueeze.o: In function `read_cb':
sslsqueeze.c:(.text+0x161): undefined reference to `bufferevent_read'
sslsqueeze.c:(.text+0x20d): undefined reference to `bufferevent_free'
sslsqueeze.c:(.text+0x25d): undefined reference to `bufferevent_write'
sslsqueeze.c:(.text+0x288): undefined reference to `bufferevent_write'
sslsqueeze.c:(.text+0x2b3): undefined reference to `bufferevent_write'
sslsqueeze.o: In function `event_cb':
sslsqueeze.c:(.text+0x2ed): undefined reference to `bufferevent_free'
sslsqueeze.o: In function `write_cb':
sslsqueeze.c:(.text+0x136): undefined reference to `bufferevent_enable'
sslsqueeze.o: In function `event_cb':
sslsqueeze.c:(.text+0x32c): undefined reference to `bufferevent_write'
sslsqueeze.o: In function `main':
sslsqueeze.c:(.text.startup+0x1f9): undefined reference to `event_base_new'
sslsqueeze.c:(.text.startup+0x229): undefined reference to `event_base_dispatch'
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'sslsqueeze' failed
make: *** [sslsqueeze] Error 1
After some research I tried the following commands ALL to the same result :
make -levent_core
gcc -levent_core sslsqueeze.c -o take6
gcc -L/usr/lib/x86_64-linux-gnu sslsqueeze.c -o take8
The following were also not successful. They gave "file not found" errors.
gcc -L/usr/lib/x86_64-linux-gnu -libevent_core.so sslsqueeze.c -o take7
gcc -L/usr/lib/x86_64-linux-gnu -libevent_core.a sslsqueeze.c -o take7
Final piece of information.
Header files are in /usr/include/event2
libevent_core files are in /usr/lib/x86_64-linux-gnu/(2 files, one with .so extension and the other with .a)
Any help would be appreciated!

Issue with linking libraries built with gnat

When trying to build some test cases (just programs written in Ada), I get the following error:
gcc -c -shared decimaltests.adb
gnatbind -x decimaltests.ali
gnatlink decimaltests.ali -lGenerics -lNumerics -lTesting
/usr/bin/ld: decimaltests: hidden symbol `_Unwind_Resume' in
/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.1/libgcc_eh.a(unwind-dw2.o) is referenced by DSO
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
gnatlink: error when calling /usr/bin/gcc
gnatmake: *** link failed.
I'm building them with gnatmake -shared *.ad{b,s} -largs -lGenerics -lNumerics -lTesting Clearly this isn't a problem with building the sources, but just to further confirm that, I copied the sources into this directory and built using gnatmake -shared *.ad{b,s} which built the tests just fine.
The dependent libraries are built and installed into a path gnat searches through. It doesn't seem to be an issue of not finding those. Not sure what's going on here.
All the libraries are built with gnatmake -O2 -fPIC -shared *.ad{b,s} as well as any relevant library dependencies. All libraries that depend on these can still be built. It's only even programs that depend on the libraries that throw this error, and always the same error.
Update: Building the libraries using gprbuild and then installing them with gprinstall seems to work similarly, except now the error is as follows:
decimaltests.o: In function `_ada_decimaltests':
decimaltests.adb:(.text+0x43): undefined reference to `testing__start'
decimaltests.adb:(.text+0x4a): undefined reference to
`generics__testing__default_tolerance'
decimaltests.adb:(.text+0x9e): undefined reference to
`generics__testing__default_tolerance'
decimaltests.adb:(.text+0x108): undefined reference to
`generics__testing__default_tolerance'
decimaltests.adb:(.text+0x172): undefined reference to
`generics__testing__default_tolerance'
decimaltests.adb:(.text+0x1dc): undefined reference to
`generics__testing__default_tolerance'
decimaltests.o:decimaltests.adb:(.text+0x23f): more undefined references to
`generics__testing__default_tolerance' follow
decimaltests.o: In function `_ada_decimaltests':
decimaltests.adb:(.text+0x14f5): undefined reference to `testing__stop'
/usr/lib/numerics//libNumerics.so: undefined reference to
`generics__testing__not_started#SYMS'
/usr/lib/numerics//libNumerics.so: undefined reference to
`generics__testing__pass#SYMS'
/usr/lib/numerics//libNumerics.so: undefined reference to
`generics__testing__fail#SYMS'
collect2: error: ld returned 1 exit status
gprbuild: link of decimaltests.adb failed
So I looked through the symbols table for both build methods and noticed, in both cases, the symbol most definitely exists, but the reference to it seems to be the wrong location. I'll try building on different platforms/compilers and update again if anything relevant comes up.
Both processes correctly build the libraries and test programs, and the test programs run properly, on different platforms. To further confirm that this is a bug, I've installed a different GCC toolchain and repeated the builds under the original platform, and this problem did not arise. I'll be filing a bug report.

libcurl curl/curl.h No such file or Directory Win xp 32 MinGW

I have been searching for a couple of hours and found several threads with the same problem and tried all their suggestions.
My curl.h is in C:\MinGW\msys\1.0\curl-7.29.0\include\curl and I've included it at compile time but for some reason gcc claims it can't find it:
gcc -o curl.exe curl.c -IC:/MinGW/msys/1.0/local/ -IC:/MinGW/msys/1.0/curl-7.29.0/lib/.libs/ -IC:/MinGW/msys/1.0/curl-7.29.0/include/curl -IC:/MinGW/msys/1.0/OpenSSL-Win32/ -lcurl -lws2_32
and the result:
curl.c:4:32: fatal error: curl/curl.h: No such file or directory
UPDATE: (With the suggestion from H2CO3)
$ gcc -o curl.exe curl.c -IC:/MinGW/msys/1.0/local -IC:/MinGW/msys/1.0/curl-7.29.0/lib/.libs/ -IC:/MinGW/msys/1.0/curl-7.29.0/include/ -IC:/MinGW/msys/1.0/OpenSSL-Win32/include/ -lws2_32
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0xa8): undefined reference to `_imp__curl_global_init'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0xe6): undefined reference to `_imp__curl_formadd'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0x124): undefined reference to `_imp__curl_formadd'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0x162): undefined reference to `_imp__curl_formadd'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0x169): undefined reference to `_imp__curl_easy_init'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0x183): undefined reference to `_imp__curl_slist_append'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0x1b8): undefined reference to `_imp__curl_easy_setopt'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0x211): undefined reference to `_imp__curl_easy_setopt'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0x237): undefined reference to `_imp__curl_easy_setopt'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0x245): undefined reference to `_imp__curl_easy_perform'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0x25e): undefined reference to `_imp__curl_easy_strerror'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0x288): undefined reference to `_imp__curl_easy_cleanup'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0x296): undefined reference to `_imp__curl_formfree'
C:\DOCUME~1\J10441\LOCALS~1\Temp\ccHP6WWt.o:curl.c:(.text+0x2a4): undefined reference to `_imp__curl_slist_free_all'
collect2: ld returned 1 exit status
If I try to compile with -lcurl it says ..... ld.exe: cannot find -lcurl is this because it can't find the dll?
You're including <curl/curl.h>, and not <curl.h>. So you have to tell the compiler to look for header files in the include directory, and not in include/curl:
gcc -IC:\MinGW\msys\1.0\curl-7.29.0\include etc. etc.
This might be beyond the scope of what you're doing, but, I found it best to install a version of cURL(libcurl) into the MinGW/MSYS environment. After installed, any program can be compiled to use it with the typical <curl/curl.h> and -lcurl conventions since it's installed where GCC would expect it. I documented my process here.

Lua C API: undefined reference errors in liblua.a [duplicate]

This question already has answers here:
Undefined reference to `pow' and `floor'
(6 answers)
Closed 9 years ago.
I'm trying to compile a simple example of C code that includes Lua(5.2) libraries. I'm using the following command:
gcc graph.c -o graph -I/usr/local/include -L/usr/local/lib -llua
And getting the following errors:
/usr/local/lib/liblua.a(lobject.o): In function `luaO_arith':
lobject.c:(.text+0x15c): undefined reference to `floor'
lobject.c:(.text+0x111): undefined reference to `pow'
/usr/local/lib/liblua.a(lvm.o): In function `luaV_execute':
lvm.c:(.text+0x24e9): undefined reference to `floor'
lvm.c:(.text+0x25fe): undefined reference to `pow'
...
Looks like the math library is not linked, but not sure how to fix it... Any suggestions? I installed Lua following instructions from the Readme with make linux and install linux (have Ubuntu 12.04). Thanks!
Very simple: you just need to add -lm to the end of the line.
(The man pages for all the functions that require it will mention this.)

Resources