Gcc/G++: "No Such File or Directory"

gcc/g++: No such file or directory

Your compiler just tried to compile the file named foo.cc. Upon hitting line number line, the compiler finds:

#include "bar"

or

#include <bar>

The compiler then tries to find that file. For this, it uses a set of directories to look into, but within this set, there is no file bar. For an explanation of the difference between the versions of the include statement look here.

How to tell the compiler where to find it

g++ has an option -I. It lets you add include search paths to the command line. Imagine that your file bar is in a folder named frobnicate, relative to foo.cc (assume you are compiling from the directory where foo.cc is located):

g++ -Ifrobnicate foo.cc

You can add more include-paths; each you give is relative to the current directory. Microsoft's compiler has a correlating option /I that works in the same way, or in Visual Studio, the folders can be set in the Property Pages of the Project, under Configuration Properties->C/C++->General->Additional Include Directories.

Now imagine you have multiple version of bar in different folders, given:


// A/bar
#include<string>
std::string which() { return "A/bar"; }

// B/bar
#include<string>
std::string which() { return "B/bar"; }

// C/bar
#include<string>
std::string which() { return "C/bar"; }

// foo.cc
#include "bar"
#include <iostream>

int main () {
std::cout << which() << std::endl;
}

The priority with #include "bar" is leftmost:

$ g++ -IA -IB -IC foo.cc
$ ./a.out
A/bar

As you see, when the compiler started looking through A/, B/ and C/, it stopped at the first or leftmost hit.

This is true of both forms, include <> and incude "".

Difference between #include <bar> and #include "bar"

Usually, the #include <xxx> makes it look into system folders first, the #include "xxx" makes it look into the current or custom folders first.

E.g.:

Imagine you have the following files in your project folder:

list
main.cc

with main.cc:

#include "list"
....

For this, your compiler will #include the file list in your project folder, because it currently compiles main.cc and there is that file list in the current folder.

But with main.cc:

#include <list>
....

and then g++ main.cc, your compiler will look into the system folders first, and because <list> is a standard header, it will #include the file named list that comes with your C++ platform as part of the standard library.

This is all a bit simplified, but should give you the basic idea.

Details on <>/""-priorities and -I

According to the gcc-documentation, the priority for include <> is, on a "normal Unix system", as follows:

 /usr/local/include
libdir/gcc/target/version/include
/usr/target/include
/usr/include

For C++ programs, it will also look in /usr/include/c++/version, first. In the above, target is the canonical name of the system GCC was configured to compile code for; [...].

The documentation also states:

You can add to this list with the -Idir command line option. All the directories named by -I are searched, in left-to-right order, before the default directories. The only exception is when dir is already searched by default. In this case, the option is ignored and the search order for system directories remains unchanged.

To continue our #include<list> / #include"list" example (same code):

g++ -I. main.cc

and

#include<list>
int main () { std::list<int> l; }

and indeed, the -I. prioritizes the folder . over the system includes and we get a compiler error.

GCC error No such file or directory when including a separate file

First, -I expects a path to a directory. Secondly, your path contains spaces, so you should enclose it in quotes to make sure it's not wrongly treated as two different arguments:

gcc -std=c99 -Wall -o Ou1 ou1.c -I "C:\Users\NAME\Documents\C programmering\DOA"

gcc errors “No such file or directory”

Make sure that you are running gcc goodbye.c -o goodbye while you are in the C:\Users\Chris\Documents\prog\c\learn\ directory.

If the c file is named GOODBYE.c then you should run gcc GOODBYE.c -o goodbye

gcc: No such file or directory

CC := gcc
CFLAGS := -Wall -Werror -g
LDFLAGS :=
LIBS := -L. -lamqp
SRCS := amqp_consommateur.c amqp_producteur.c

OBJS := $(SRCS:c=o)
PROGS := $(SRCS:.c=)

.PHONY: all
all: $(PROGS)
@echo "$(MAKE) : Tout est généré"

$(PROGS) : % : %.o Makefile
$(CC) $< -o $@

%.o: %.c Makefile
$(CC) $(CFLAGS) -c $<

clean:
rm -f $(PROGS) $(OBJS)

Issue compiling C++: gcc: error: CreateProcess: No such file or directory

You did not install the required component mingw32-gcc-g++. You want to run the MinGW Installation Manager and select the required option on the Basic Setup pan.

Sample Image

gcc: error: libhello.so: No such file or directory

BTW, a shared library should contain position independent code. So compile it with

gcc  -Wall -fPIC -shared -O -g hello.c -o libhello.so

See also this and that answers.

And a shared object should (nearly) never have a main function.

PS. Order of arguments to gcc matters a lot!

gcc no such file or directory error

It's

gcc -ansi -Wall -pedantic

You're using one of those dashes: Dash (specifically, you are using en-dash U+2013). You need to use minus sign - instead

CreateProcess: No such file or directory

Its specifically told that you need to reboot after you set the environmental variables in windows for migwin.



Related Topics



Leave a reply



Submit