GCC: No such file or directory - c

I made a fresh project and have been stuck in this specific issue for hours. I am using a shell script (.bat) file to compile and build the project. If I use no libraries, it compiles and runs fine. However, when I try to add SDL2 I get the issues described in the title. I was using Visual Studio Code, set up everything correctly in tasks.json and the issue persisted. I moved to 4code and the issue remains.
This is my build.bat
#echo off
if not exist build mkdir build
pushd build
gcc ..\source\main.c -o main.exe
gcc -L ..\external\SDL2\include
popd
I added the library in the "external" folder. It tells me it can't find the SDL.h file. I am confused because the file is in ..\external\SDL2\include
I never coded in C, so all this compiler business is new to me. I've searched the web for hours and can't find a solution. I'd appreciate any help.

Directory-adding options must be used with compilation command.
gcc ..\source\main.c -o main.exe is a compilation command without directory adding
and gcc -lSDL2 and gcc -L ..\external\SDL2\include are not compilation commands
because they don't include what to compile.
The 3 gcc invokations should be one invokation:
gcc -L ..\external\SDL2\include ..\source\main.c -o main.exe -lSDL2

Related

Build commands needed to run Wine programs from IDE

I’ve recently done a git clone of the wine repository at https://github.com/wine-mirror/wine and downloaded the folders to (~/repo/wine/). I'm trying to run Notepad, but don't know how. I am assuming that to build and compile it, I would need to run main.c from the notepad folder. I’m running GCC v 8.3.0 on Raspbian/Linux 10
With the repo downloaded as shown above, what build commands would I need to run notepad’s main.c from Geanie (or any, currently using Geanie) IDE? Can a single compile and/or build command let me run notepad from Geanie, or am I missing something?
Other details (not needed if what I thought I was going to do can't be done):
I wanted to try to run main.c at (~/repo/wine/programs/main.c), but don’t know how to get GCC to view all of the necessary header files. In my execution instructions window in Geanie, I have
gcc -Wall -c “%f” /home/pi/repo/wine/include
and my build instruction (it won't compile, so this isn't anything I've even gotten to work with yet...)
gcc -Wall -o “%e” “%f” /home/pi/repo/wine/include
When I attempt to compile, I get:
Stdio.h:11:10: fatal error: corecrt_wstdui.h: No such file or directory.
#include <corecrt_wstudio.h>
I went over to the stdio.h and attempted to add a build instruction here as well that also targets the include folder (which is the supposedly missing file), but it won’t compile.
Using cpp -v, I can see my include paths for GCC are as follows:
#include”...” paths:
#include<...> paths:
\usr\lib\gcc\arm-linux-gnueabihf\8\include
\usr\local\include
\usr\lib\gcc\arm-linux-gnueabihf\8\include-fixed
\usr\include\arm-linux-gnueabihf
\usr\include

Compiling Apache Lucy

I am trying to compile Apache Lucy. Here are the steps I followed:
Downloaded Lucy and Clownfish
Compiled Clownfish runtime and compiler
Configured Lucy
Started Lucy Make
The compilation of the files in the core directory works fine but when it gets to the modules it throws an error:
$ make
gcc -pedantic -Wall -Wextra -Wno-variadic-macros -std=gnu99 -D_GNU_SOURCE -D CFP_LUCY -D CFP_TESTLUCY -fvisibility=hidden -O2 -g -fno-strict-aliasing -fPIC -I . -I ../core -I autogen/include -I ../modules/analysis/snowstem/source/include -I ../modules/unicode/ucd -I ../modules/unicode/utf8proc -c ../modules/analysis/snowstem/source/libstemmer/libstemmer_utf8.c -o ../modules/analysis/snowstem/source/libstemmer/libstemmer_utf8.o
../modules/analysis/snowstem/source/libstemmer/libstemmer_utf8.c:4:35: fatal error: ../include/libstemmer.h: No such file or directory
#include "../include/libstemmer.h"
^
compilation terminated.
make: *** [../modules/analysis/snowstem/source/libstemmer/libstemmer_utf8.o] Error 1
The problem seems to be that the code files in the modules include the include files with a relative path like #include "../include/libstemmer.h". Even though the resulting directory is included in the include files directory i.e. -I ../modules/analysis/snowstem/source/include but it does not work
I started modifying the source files to remove the relative path but more started cropping up. I think there must be a better way. Any help on how I can fix this would be really helpful.
If you do only cpan Lucy::Simple it should be enough
It seems to me there is not a C library available yet.
Above link is old (2012) but explains why it is not obvious.
http://grokbase.com/t/lucy/user/12bp9rw0g7/lucy-user-using-lucy-directly-from-c
https://github.com/cancerberoSgx/lucy.js/blob/master/scripts/build-lucy-c.sh
that's a shell script that will clone lucy .git and dependencies, compile lucy c and clownfish C them and then compile and run one of the lucy/samples/c
It does it all locally in a folder, so you don't have to install anything globally as root. you need linux buildtools like gcc, make, configure, etc. Good luck

Eclipse IDE for C/C++, gcc can't find *.c document

I am working on a C project in Eclipse, the environment is windows X64,
When I tried to compile the program, it said:
11:54:29 **** Incremental Build of configuration Debug for project
TPCembarque **** Info: Internal Builder is used for build gcc
"-ID:\java workspace\TPCembarque\inc" "-ID:\java
workspace\TPCembarque\lib\" "-includeD:\java
workspace\TPCembarque\lib\libVirtualBoard.a" -O0 -g3 -Wall -c
-fmessage-length=0 -o "src\main.o" "..\src\main.c" gcc: error: workspace\TPCembarque\lib\libVirtualBoard.a -O0 -g3 -Wall -c
-fmessage-length=0 -o src\main.o ..\src\main.c : No such file or directory gcc: fatal error: no input files compilation terminated.
11:54:29 Build Finished (took 657ms)
so as a result it couldn't find main.c
All my data related to the project were saved in D:/systnum
and I created my project in D:/java workspace/TPCembarque.
I've already set the build environment as d:\systnum\MinGW\bin;d:\systnum\MSys\1.0\bin
I have already added the file main.c to the project 1
Could anybody tell me how to let the Compiler find main.c? thanks!
Is it possible to paste the makefile of your project?
I see a potential issue due to two different paths mentioned in your build log.
"src\main.o" -> src is a folder in current directory
"..\src\main.c" -> src is a folder in the directory one folder back.

Eclipse can't run my Makefile

I'm writing a C project in Eclipse and while trying to run it I get the following error message:
(Cannot run program "make": Launching failed)
My Makefile is:
all : GenericHashTable.o TableErrorHandle.o
gcc -Wall GenericHashTable.o TableErrorHandle.o -o all
GenericHashTable.o : GenericHashTable.c GenericHashTable.h TableErrorHandle.h
gcc -Wall -c GenericHashTable.c -o GenericHashTable.o
TableErrorHandle.o : TableErrorHandle.c TableErrorHandle.h
gcc -Wall -c TableErrorHandle.c -o TableErrorHandle.o
clean :
rm all *.
Is the formatting broken in your makefile or in your question? Commands on the line below the target & dependencies. Does this makefile work from the command line?
Assuming the makefile is correct check the obvious things such as ensuring Eclipse can see your toolchain. Perhaps it can't even find the make command or you haven't set it from preferences.
Also the CDT offers a managed makefile and a standard (manual) makefile. The managed means Eclipse will create the makefile for you. The standard makefile is a makefile you are responsible for writing. Perhaps if your project is simple you should use the managed makefile to save yourself the hassle of writing one.
You can try the internal builder from eclipse:
Project->Properties->C/C++ Build
There (in the top level of C/C++ Build) you find Builder Settings->Builder Type which you set to Internal Builder. This way CDT does not require an external make command.
Either use the internal builder as "Turbo J" already suggested or make shure 'make' is in your PATH.
You can set the PATH for the build process in the Project-Properties in 'C/C++ Build -> Environment' - click "Select..", choose PATH and then change it by adding the correct path for the 'make' command.
This way you can also set the PATH of your compiler - that may be necessary if you use the Internal Builder.

First C programm - need help with eclipse

I have install the C/C++ CDT Version of Eclipse. After making a HelloWorld.c file and get the code in there I get an error of "Launch failed. Binary not found".
I found in google that my Eclipse miss the compiler and I install MinGW on my computer and add the path to env variables (tested it with "gcc -v" in cmd and succeded).
1) I can build now, but have no idea how to make a MAKEFILE. - I Read 10 tutorials but don't understand it - ideas?
2) I can build, but not run, I get "Launch failed. Binary not found" - ideas?
Found the error: I never maked a ".c" file -.- after renaming it - works fine.
Revised answer: If you want to avoid writing a real makefile, you can write something like this:
all:
gcc *.c -o runme.exe
You need to specify the binary which gcc outputs (gcc [..] -o <this one>) in the run settings (in the previous example, it should point to runme.exe). Go to Run->Run Configurations, and under C/C++ Application browse and look for runme.exe.
I would, however, strongly advise you to seriously learn about makefile. The beauty of makefiles is that you can use very little features at first and use more and more as you go on (as you saw, writing a "dummy" file was very quick). At first I suggest you write something a bit more "clever" than what I gave you above. Here's a nice tutorial and an example:
all: hello
hello: main.o factorial.o hello.o
g++ main.o factorial.o hello.o -o hello
main.o: main.cpp
g++ -c main.cpp
factorial.o: factorial.cpp
g++ -c factorial.cpp
hello.o: hello.cpp
g++ -c hello.cpp
clean:
rm -rf *o hello
all is what compiles at default. What comes before the : are rule names and after it are the dependencies. i.e, to compile all you need to compile hello (though only if it's been updated), and so forth. the line below the rule is the command to compile. I hope this helps. Please read the tutorial, Makefiles are important.
Add the directory that gcc resides in (C:\MinGW\bin or whatever) to your PATH environment variable and restart Eclipse (important!). This is the process in XP: http://vlaurie.com/computers2/Articles/environment.htm. That should sort it out.
1 I suggest you to take a look at this:
http://www-scf.usc.edu/~csci410/handouts/make.pdf
It's a basic gmake tutorial and should be enough to get you started. But right now, for single file project, I suggest you to just skip creating Makefiles and doing in the command prompt:
gcc -o helloworld.exe helloworld.c
And running your executable in the prompt. You can worry about Makefiles later in your learning curve.
2 How did you setup your project?
Make sure you've got a binary parser selected when you bring up properties for the project. At least in my install, none were checked by default. I needed to check Mach-O 64 parser; you'll need to pick one based on what you're doing. I picked this up from http://www.thexploit.com/tools/os-x-10-6-64-bit-eclipse-cdt-missing-binaries/
I didn't have a binary parser selected, and that seems to mean that CDT can't find anything that it recognizes as a binary. It meant in my case that I just got the "Launch failed. Binary not found" message, even though I specified the exact binary, including a fully-qualified path, in the run/debug configurations.
This has nothing to do with builds, just running/debugging. If you're having a problem building, this probably is irrelevant.

Resources