MinGW gcc, undefined reference to __chstk_ms? - c

So I've just got a brand new laptop (Windows 10) and have been installing everything I need.
I downloaded MinGW and installed gcc, added it the PATH etc. I thought I would compile a completely standard, basic HelloWorld C program just to check that it works. (This file has been copied straight across from my old laptop where it compiles perfectly). This is what I got:
C:\...\Documents\C>gcc prog1.c -o prog1
/mingw/lib/libmingw32.a(setargv.o):(.text+0x30): undefined reference to `__chkstk_ms'
/mingw/lib/libmingwex.a(glob.o):(.text+0x673): undefined reference to `__chkstk_ms'
/mingw/lib/libmingwex.a(glob.o):(.text+0x7e0): undefined reference to `__chkstk_ms'
/mingw/lib/libmingwex.a(glob.o):(.text+0x81d): undefined reference to `__chkstk_ms'
/mingw/lib/libmingwex.a(glob.o):(.text+0x934): undefined reference to `__chkstk_ms'
/mingw/lib/libmingwex.a(glob.o):(.text+0xb78): more undefined references to `__chkstk_ms' follow
collect2: ld returned 1 exit status
Previous questions similar to this have been the result of version conflicts, which, as far as I can tell, I don't have. And since the laptop is brand new I don't have any previously installed things that I've forgotten about which could be conflicting.
Any help on fixing this would be much appreciated.

Related

MingGw error while trying to complie C code

I tried to compile my C code (using mingw) into a EXE file but it just says the following error:
/mingw/lib/libmingw32.a(setargv.o):(.text+0x33): undefined reference to `__chkstk_ms' /mingw/lib/libmingwex.a(glob.o):(.text+0x6d2): undefined reference to `__chkstk_ms' /mingw/lib/libmingwex.a(glob.o):(.text+0x8b8): undefined reference to `__chkstk_ms' /mingw/lib/libmingwex.a(glob.o):(.text+0x900): undefined reference to `__chkstk_ms' /mingw/lib/libmingwex.a(glob.o):(.text+0xa25): undefined reference to `__chkstk_ms' /mingw/lib/libmingwex.a(glob.o):(.text+0xc15): more undefined references to `__chkstk_ms' follow collect2: ld returned 1 exit status
i ran the command
mingw-get upgrade "mingwer=3.20.*"
and
mingw-get upgrade "mingwer=3.18.*"
but didn't solve the issue
Edit: Command ran
gcc compvisia.c init.c bitboards.c hashkeys.c board.c -o compvisia
Code:
#include "stdio.h"
#include "stdlib.h"
int main() {
printf("hello world");
return 0;
}
Looks like the errors are related to stack protection.
Maybe your system has a mix of different MinGW versions installed, causing linking with mismatching libraries.
MinGW 3 is old, you should really consider moving to MinGW-w64.
You can get a standalone build of MinGW-w64 from https://winlibs.com/ that you can extract somewhere without installing to test if it makes a difference for your source code.
Make sure to use the full path to gcc.exe so you are in fact using the one you think you are using.

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

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.

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

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

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.

Resources