Linking libraries with a MinGW project in VS code - c

I am using MinGW version 4.5.2 on windows 10. I am trying to link multiple libraries to a project in VS code. When I try run this command: g++ main.c -o main.exe -I"C:\\Users\\USER\\Programming\\OPenGL Library\\glfw\\include\\glfw3.h" -L"C:\\Users\\USER\\Programming\\OpenGL Library\\glfw\\lib-mingw-w64\\". I get a compile error: main.c:2:24: fatal error: GLFW\glfw3.h: No such file or directory What is wrong with the command above that gives this linking error. As far as I can tell I have pointed MinGW to the library and specified the header file. I am not sure what else I need to add to the command for link the GLFW library as well as other libraries such as GLEW or glm.

If your include directive looks like
#include <GLFW/glfw3.h>
you need to supply a path to a directory which itself contains a directory named GLFW.

Related

Compilation of Raylib function fails on Visual Studio Code

I'm getting an error in the compilation of a C file that heavily uses Raylib function.
Environment
OS: Windows 10
IDE: Visual Studio Code
Raylib version: 4.2.0 (win64, mingw)
Sanity check of Raylib installation
Following the discussions in How to add Raylib to VS code?, I successfully compiled an example code: main.c in this link. That means, the Raylib function is correctly installed, and the path to the source libraries is also set correctly.
Compilation of my code
Using the set of JSON files (c_cpp_properties.json, launch.json, settings.json, tasks.json) used in the example code, I'm trying to compile my code. There are several ways to compile code on VS code.
Compilation by F5 key
In this case, I get the following messages on my terminal:
Executing task: C:\MinGW\bin\mingw32-make.exe RAYLIB_PATH=C:/raylib/raylib PROJECT_NAME=MyCode OBJS=MyCode.c BUILD_MODE=DEBUG
mingw32-make: *** No targets specified and no makefile found. Stop.
It seems like I need to make a Makefile to configure the compilation but I have no idea how to write it. I tried using the Makefile in link but it caused an error. I probably need to make a code-specific Makefile but I have no clue.
Compilation by command #1
I also tried to compile my code by running the following command on VS code terminal:
gcc MyCode.c lib/librarylib.a -o MyCode
but I got the following error message:
fatal error: raylib.h: No such file or directory
The header file raylib.h is not recognized even though I used the same header in the example code I compiled earlier. The path to the header is also set properly.
Compilation by command #2
To set the path to the file location of raylib.h more explicitly, I used the following command instead:
gcc -Wall -IC:\raylib\raylib\src MyCode.c MyCode.exe -l/librarylib -o a.out
Note that the C:\raylib\raylib\src is the path to a folder that contains raylib.h. This time I got the following error:
gcc.exe: error: MyCode.c: No such file or directory
gcc.exe: error: MyCode.exe: No such file or directory
Some clues ...
I got this code from another guy. The code was originally developed on M1 mac, and it was compiled successfully by the following command:
clang -framework CoreVideo -framework IOKit -framework Cocoa -framework GLUT -framework OpenGL lib/libraylib.a MyCode.c -o MyCode

Why gcc under Windows O.S. produces a .o instead of a .lib file when compiling static libraries?

I am using gcc 8.1.0 on Windows. To install it I set up Code::Blocks on my computer and updated the environment variable list by adding the path to the gcc.exe program within the installation folder of CodeBlocks. The file editor I used was the built-in editor in Visual Studio. The terminal to compile was the power shell from Visual Studio as well.
In the library development folder I have the files mul.c and mul.h. Their content is irrelevant.
To compile the library I use the command:
gcc -c mul.c
When I run it, it creates a file object mul.o and not mul.lib. I needed to use the option -o mul.lib to successfully create the desired extension file. After placing the header, the .lib file and the main.c in the same parent folder I am obvioudly able to build the executable by running.
gcc main.c -I./include -L/static -lmul -o my_program.exe
I have two questions:
Why does gcc produces a .o if I am in a Windows environment?
I followed a tutorial that compile the static library under Linux and it names it libmul.o, in this way the -lmul option is able to retrieve the library. But if I call my generated static library libul.lib it generates the error:
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-ingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmul
collect2.exe: error: ld returned 1 exit status
Are these a normal behaviours by gcc, or is it side effect of making gcc available just by updating the Windows environmental variables list?
Thank you to the community in advance.
GCC comes from the *nix world where libraries have the .a extension. When using GCC+MinGW this remains the case.
Shared libraries in MinGW are .dll files but their libraries for linking are .dll.a files.
The advantage of .a files is that a lot of sources build out of the box on Windows with MinGW, especially when using MSYS2 shell.
If you use -l it will look for .a (or .dll.a for shared build) file adding the lib prefix and the extension automatically.
So -lmul will look for libmul.a (static, e.g. when --static linker flag is given) or libmul.dll.a (shared).
By the way, you are using quite an old GCC 8.1.0.
As I write this current version is 12.2.0. Check https://winlibs.com/ for a standalone download (instructions on how to configure in Code::Blocks are on the site) or use MSYS2's package manager pacman.

How to compile the LIBVLC example code on windows using gcc

I want to build the libvlc example (https://wiki.videolan.org/LibVLC_Tutorial) so i downloaded the sources and also copied libvlc.dll and libvlccore.dll (from my vlc installation) into the current directory. Then i try to compile it by issuing
gcc example.c -o example -I./include -L./lib -L./ -llibvlc
but get the error
example.c:3:22: fatal error: vlc/vlc.h: No such file or directory
#include <vlc/vlc.h>
^
I hope this is enough information, i controlled all paths and files twice. Thank you in advance.
you need vlc sdk, not just files from vlc source code ;
you need dll files for your already compiled application, but for build you need .lib files - also part of sdk;
for this you need to build them - for this step refer to https://medium.com/#tobias.strg/compiling-vlc-3-x-in-2020-a390c6a73c24;
no doubt you can use some nigthly builds of vlc (check for zip files with "debug" suffix) https://artifacts.videolan.org/vlc-3.0/nightly-win64/20220420-0220;
after you got sdk pack for your platform you can compile - pointing to headers files from sdk, and linking with libs from sdk;

Export C library to Windows dll

So I have source code written in C for the LibIdn2 library. I am looking to port it into C# but running in to some issues along the way and would appreciate some help.
Installed Cygwin along with Make and GCC G++ packages
Successfully able to run the./configure command on the source directory
After this, running the "make" command produces an .exe file.
I have been trying to get a .dll file created but cannot seem to do so using gcc compiler. The command I am running is:
gcc -shared -o idn2.dll src/idn2.c
but it complains that it cant find the header files referenced in the idn2.c source file.
I have checked that in the idn2.h file, dll_Export is defined.
Any ideas how should I proceed? I need to get a dll.

Eclipse + OpenCV + Cygwin --> cv.h: No such file or directory

Hi I'm having troubles in Eclipse including OpenCV Library. I Follow a lot of tutorials but i can't compile anything. Here is the output from the console.
Building file: ../hand.c
Invoking: Cygwin C Compiler
gcc -O2 -g -Wall -c -fmessage-length=0 -MMD -MP -MF"hand.d" -MT"hand.d" -o"hand.o" "../hand.c"
cygwin warning:
MS-DOS style path detected: D:\Eclipse_workspace_C++\HelloWorld\Default
Preferred POSIX equivalent is: /cygdrive/d/Eclipse_workspace_C++/HelloWorld/Default
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
../hand.c:3:16: fatal error: cv.h: No such file or directory
compilation terminated.
subdir.mk:18: recipe for target `hand.o' failed
make: *** [hand.o] Error 1
I'm using OpenCV2.0.
I configured in proyect properties the C/C++ Build -> Settings -> Tool Settings Tab -> Compiler and Linker to add library and headers of opencv but i can not compile it.
ScreenShoot of my eclipse project.
SOLVED!
Steps for configure Eclipse and OpenCV 2.4.5 in Windows
1) after installing Opencv include in environment path your directory where opencv is installed, mine is opencv\opencv2.4.5\build\include
2) I use Cygwin to compile c files. So configure your eclipse using CDT for Cygwin and in project setting put next configuration.
if you are using mingw put there in linker settings. For me it's only vc9.
3)My source file is like
#include <stdio.h>
#include <stdlib.h>
#include <cv.h>
int main(void) {
puts("Hello World!!!");
return EXIT_SUCCESS;
}

Resources