Can't install SDL on MinGW, getting `undefined reference to WinMain#16` - c

I'm trying to install SDL on MinGW.
I've downloaded SDL from here (the SDL2-devel-2.0.0-mingw.tar.gz link), then copied the contents of SDL2-2.0.0/x86_64-w64-mingw32/{bin,include,lib} into the matching directories in my MinGW installation.
When I try to compile any file that contains #include ‹SDL2/SDL.h› using gcc test.c -lmingw32 -lSDL2main -lSDL2 -mwindows, GCC complains about undefined reference to WinMain#16 and undefined reference to some SDL functions.

SDL2-devel-2.0.0-mingw.tar.gz contains both 32-bit libraries (i686-w64-mingw32 directory) and 64-bit libraries (x86_64-w64-mingw32 directory).
The error was caused by using a 64-bit version of the library with a 32-bit compiler.

Related

Compiling SDL on Windows with Mingw gcc

I downloaded SDL for MinGW here : https://www.libsdl.org/download-2.0.php.
But when I try to compile with gcc it can't find the libraries.
It says it cannot find "SDL2/SDL.h".
I tried running GCC with the parameters to include the path after moving the folder containing
SDL2 to the same directory of the project.
I used this command:
gcc main.c render.c sprite.c logic.c menu.c level.c -o release -l:SDL2\x86_64-w64-mingw32\lib\libSDL2main.a -l:SDL2\x86_64-w64-mingw32\lib\libSDL2.a -ISDL2
If you want the compiler to find the libraries, you need to include the directory it is in using -I/dir/

Debian linux mingw compile Windows dll including openssl library

I am on a Debian linux build environment and cannot change this. We build our apps using mingw and would like to use the openssl suite of tools in one of our applications. The linux version contains the includes openssl/md5.h and compiles gcc with the -lcrypto flag and works great.
What do I need to do to build the Windows dll using mingw and include openssl?
My build command looks like this
x86_64-w64-mingw32-gcc -shared -s FILE.c FILE.def -lcrypto -lws2_32 -o OUT.dll
This produces the error fatal error openssl/md5.h no such file or directory.
I have tried to add the -I /path/to/openssl/includes
Then get the ld error cannot find -lcrypto. I have the libssl-dev libraries.
I have the source for openssl and have tried to compile it using mingw as some other articles have suggested. "cannot find -lcrypto -lssl" with OpenSSL on Windows with MinGW
But the build always fails with multiple files missing the include bits/libc-header-start.h. My thinking was if I can get the windows dlls on the linux system maybe that was what mingw needed.
I have tried to install gcc-multilib as suggested in this post "fatal error: bits/libc-header-start.h: No such file or directory" while compiling HTK but that leads to a basket of missing dependencies.
Is it even possible to build a Windows dll including openssl dependencies from a Debian dev environment?
Thanks for any assistance.

Linker error with FFmpeg on Windows

I'm trying to link FFmpeg libraries to a C program on Windows, but I can't successfully link the libraries. I downloaded the Dev archive from Zeranoe and put it into my project folder. (EDIT: The 64-bits version). The compilation works well but when I'm trying to link libraries, I get some undefined reference errors. Here is the command I'm trying:
gcc -o .\metadata.exe .\metadata.o -L .\ffmpeg-20170628-c1d1274-win64-dev\lib\ -lavutil -lavformat -lavdevice -lavfilter -lavcodec -lswresample -lswscale -lm
It then outputs me:
.\metadata.o:metadata.c:(.text+0x44): undefined reference to 'av_register_all'
.\metadata.o:metadata.c:(.text+0x6c): undefined reference to 'avformat_open_input'
.\metadata.o:metadata.c:(.text+0xc8): undefined reference to 'av_dict_get'
.\metadata.o:metadata.c:(.text+0xdf): undefined reference to 'avformat_close_input'
Paths are good because if I change the -libs parameters or the -L parameter I get files not found errors. Finally, I took those libraries from the Makefile in the examples' folder.
What is the source of the error? Thanks in advance, have a nice day!
EDIT: Okay so I found what was the problem. As I'm using MinGW, it includes a 32-bits compiler. So as I downloaded the 64-bits, something was off. I tried downloading the 32-bits builds and it built and linked successfully with only -lavformat and -lavutil parameters. And to run the program I needed the DLL which can be found in the Shared build (and 32-bits of course) on Zeranoe's website. Thanks!

Compile GLFW cannot find -lglfw3

I want to learn OpenGL programming with GLFW library. But I have problem when compiling the program. I followed tutorial on http://www.glfw.org/docs/latest/quick.html and copied the full program. I download the 64-bit version library on http://www.glfw.org/download.html.
I changed the first line from include <GLFW/glfw3.h> to include "GLFW/glfw3.h". I've put the GLFW folder inside the folder along with glfw3.dll, glfw3dll, and libglfw3.a
I'm running on Windows 7. This is my gcc version
gcc --version
gcc (tdm64-1) 5.1.0
I use this command for compiling
gcc test.c -Llib-mingw/ -lglfw3 -lopengl32 -lgdi32
But I got this error
cannot find -lglfw3
What should I do to make it work?
If you are still having problems with this compilation/linking problem, try set the glfw full lib folder path in gcc or g++ lib path with -L parameter, as simplified below. Double quotes and non-relative paths should work.
g++ "-L<path_to_glfw>\\glfw\\lib-mingw" -o <executable>.exe <.o files list> -lopengl32 -lglfw3 -lgdi32
Two notes:
There is no need to pass .a extension. MinGW g++/gcc compiler will automatically understand filename.
If you are using the 64-bit version of glfw, switch -L parameter to \glfw\lib-mingw64 (or respective 64-bit library location folder)

How can I link against glut32 in cygwin?

I am trying to run someone else's (4 year old) code from sourceforge. I downloaded cygwin and checked out the project with CVS.
Here is the compile line which is failing:
gcc ../block_display/block_display.c -o block_display -lopengl32 -lglut32 -lm
Here is the relevant include statement in block_display.c:
#include <GL/glut.h>
When I try to run the above compile line, I get this compile error:
$ gcc ../block_display/block_display.c -o block_display -lopengl32 -lglut32 -lm
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld: cannot find -lglut32
collect2: ld returned 1 exit status
I admit I am new/rusty with cygwin. I tried a few things to get to this point, but since I don't entirely know where to put files, I am stuck on this error. Here is what I have tried:
Downloading all results for 'glut' in cygwin setup: libglut-devel, freeglut, libglut3
Downloading glut 3.7.6, copying glut32.dll to C:\Windows\SysWOW64, and copying glut.h to C:\cygwin\usr\include. I still have glut.def and glut32.lib sitting around, but I do not know exactly where to place them. I tried following this install guide, but since I am not running VC++, I do not know what the cygwin equivalent of VC++ path is.
Any idea what I could do to get this code to compile successfully? I am running Windows 7 64-bit.
You should use freeglut instead. The original glut is far outdated. Freeglut on the other hand is binary and source compatible with the original glut, and it's also open source.
Since glut32.dll is a windows DLL and cygwin is for emulating a unix environment on windows, you can't easily use the original glut with cygwin without recompiling from source.

Resources