Compilation of Raylib function fails on Visual Studio Code - c

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

Related

Linking libraries with a MinGW project in VS code

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.

Error building program using gcc plugin from linux kernel source tree

I am trying to use a grsecurity gcc plugin that I found on their unofficial linux kernel source tree (the respectre_plugin/ one).
My GCC version is 4.7, I modified scripts/gcc-plugins/Makefile to make it compile the plugin, and I built it with the root Makefile using make gcc-plugins, that shows no error.
Then, when I try to compile a C file that has a Spectre-like flaw, I got the following build error:
file.c:36:31: error: array_index_mask_nospec is not defined
This function is defined in respectre_plugin/respectre_plugin.c, and I have no idea why I've got this strange build error, if anyone knows about it...
My build invocation is the following:
gcc -Wall -Wextra -std=c99 -fplugin=/path/to/respectre_plugin.so -c file.c -o file.o
Thanks for any help !

CMake compilation failing on MSYS2

I'm trying to set up CMake for a project I'm working on, and I'm first trying to compile a simple Hello World program in C. I'm using Windows 10 with MSYS2. If I invoke the compiler (GCC) directly in Bash, it compiles fine without warnings or errors and gives an executable as output which prints "Hello, world!" exactly as expected. My problem comes in when I try to use CMake to compile my project. When I run cmake -G Ninja .. to compile my project, it throws this error:
CMake Error at C:/msys64/mingw64/share/cmake-3.15/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"C:/msys64/mingw64/bin/cc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/dylanweber/Documents/C-Projects/webapp/build/CMakeFiles/CMakeTmp
Run Build Command(s):C:/msys64/usr/bin/ninja.exe cmTC_45340 && [1/2] Building C object CMakeFiles/cmTC_45340.dir/testCCompiler.c.obj
FAILED: CMakeFiles/cmTC_45340.dir/testCCompiler.c.obj
C:\msys64\mingw64\bin\cc.exe -o CMakeFiles/cmTC_45340.dir/testCCompiler.c.obj -c testCCompiler.c
/bin/sh: C:msys64mingw64bincc.exe: command not found
ninja: build stopped: subcommand failed.
Notice how it mentions C:msys64mingw64bingcc.exe... there must be some kind of path delineation problem but I've tried setting the CC environmental variable to C:\\msys64\\mingw64\\bin\\gcc.exe and C:/msys64/mingw64/bin/gcc.exe. I have been clearing the CMake caches between runs.
Here is my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.15)
project(webapp)
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
file(GLOB SOURCES "main/*.c")
add_executable(webapp ${SOURCES})
My code is in a "main" folder which is currently just one "main.c" file, in addition to a build directory used to keep all the temporary files in. The most frustrating part is that CMake was just working an hour ago, and I didn't change anything. What can I do to fix this problem?
The solution was not only installing the MinGW64 version of CMake, but also the MinGW64 version of Ninja as well. Since they have different pathing schemes compared to MSYS, they didn't play well together until they were both on the same POSIX-like platform.

Linking with gcc on Windows:

I'm trying to link a c-file (cvode.c) towards a set of .dll files. I run the following two lines in a cmd:
>>> gcc -c -I C:\sundials\inst2\include cvode.c
>>> gcc -shared -o cvode_lib.dll cvode.o -L. C:\sundials\inst2\lib\sundials_cvode.dll -L. C:\sundials\inst2\lib\sundials_nvecserial.dll
The first command does not give any errors but the second one gives the following error message:
C:\sundials\inst2\lib\sundials_cvode.dll: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
If I try to import the dll-files with ipython it works perfect, and the same two lines (with the same source files) works perfectly on my second computer running the same OS (windows 10 64bit) with the same version of gcc (installed with the latest Mingw64-installer). I've also tried to install cygwin64 and compile with its gcc-version, without success. The file compiles perfectly fine on an Ubuntu computer as well.
I have also tried to link vs the corresponding <sundials>.lib-files but that is not working either.
Googling for solutions has not been successful, maybe because I am not too familiar with c or gcc. However since it runs perfect on my other Win10 PC I fear it might be something deeper...

GCC weird error at header file when using linter-gcc at atom editor

I'm getting a weird error at C header files when linting with linter-gcc at atom. The error is this:
cc1: error: output filename specified twice
This error is generated by: gcc 5.2.1, ubuntu 15.10.
The same error is generated by gcc 5.3.0 at my linux arch system 4.5.0-1 ARCH.
When I checked with clang 3.7.1 all went fine.
Note that I can compile the program normally. The error is generated only inside atom editor or when I run this command at my terminal:
/usr/bin/gcc -Wall -fsyntax-only -c -fmax-errors=0 /path/to/headerfile.h
But when I run:
clang -Wall -fsyntax-only -c /path/to/headerfile.h
Nothing was printed.
EDIT: It seems that it's not linter-gcc's bug as I contacted the package's creator via his github account.
So my question is: What's is the source of this error? Is there a way to solve it? What's causing it?

Resources