I'm trying to compile a program with gcc, but I keep getting an error that it can't find the files I've specified to include.
My code (a simplified version of what I'm trying to do which highlights the issue):
#include <gtk/gtk.h>
int main(int argc, char *argv[]) {
}
I'm compiling with gcc, using:
gcc test.c -I~/gtk/inst/include/gtk-2.0
which gives me
test.c:1:21: error: gtk/gtk.h: No such file or directory
However,
ls ~/gtk/inst/include/gtk-2.0/gtk | grep gtk.h
returns
gtk.h
gtkcheckbutton.h
gtkcheckmenuitem.h
gtkshow.h
so I'm not sure where I'm messing up.
My OS is Mac OSX 10.8.5, and GCC is version 4.2.1.
You should either:
Put a space in front of the tilde:
-I ~/gtk/inst/include/gtk-2.0
Use the absolute path:
-I /users/username/gtk/inst/include/gtk-2.0
or use $HOME:
-I $HOME/gtk/inst/include/gtk-2.0
Shell only does tilde expansion if the ~ is the first nonquoted character in a word. The way you've got it now, shell has no clue that this is trying to point to the users home directory.
Related
I’m trying to run a block of Ruby code inside a C program.
I have the following code:
#include <ruby.h>
int main(int argc, char* argv[])
{
/* Construct the VM */
ruby_init();
/* Ruby goes here */
/* Destruct the VM */
return ruby_cleanup(0);
}
But when I try to run the program, I get the following error:
fatal error: ruby.h: No such file or directory
#include <ruby.h>
I read that it is needed to tell the compiler about the include paths for the required headers with the following code in Ubuntu:
pkg-config --cflags --libs ruby-2.5
gcc -I/usr/include/ruby-2.5.0 -I/usr/include/ruby-2.5.0/x86_64-linux -lruby
I have already done that, but the problem isn’t solved.
Here is the link: https://silverhammermba.github.io/emberb/embed/
Follow the steps in How can I include a needed C library using GCC?.
I don't understand the difference between the two -l, but try to follow the following structure. If I'm right, your command will be like:
gcc -I/usr/include/ruby-2.5.0 -L/usr/include/ruby-2.5.0/x86_64-linux -lruby
Where:
-I <searchpath to include files>
-L <searchpath to the lib file>
-l <thelibname>
I don't know if the library is the first or the second parameter, but you can check it.
My OS is Windows 10. I'm using command prompt this time to compile.
according to the book that I am reading, to compile all the source files and make it an object files, (in the current directory) do it by typing this command:
gcc -c *.c
it says the operating system will replace *.c with all the C filenames
But why am I getting this error?
gcc: error: *.c: Invalid argument
gcc: fatal error: no input files
compilation terminated.
I'm in the right directory.
And when I compile my source files with their respective names, it's working properly. But the '*.c' is not working.
And the same error in linking the object files using '*.o'
Is that command not for windows OS? If not, what is for windows?
Newbie here.
On Unix systems and environments (like MSYS or Cygwin) , wildcards are expanded by the shell (depends), but in Windows CMD, wildcards are expanded and interpreted by the program that receives. This sounds strange, but cmd.exe does not support wildcard expansion (as an interpreter), but some of its built-in commands do, like COPY.
Use a simple program to verify it.
#include <stdio.h>
int main(int argc, char *argv[]){
int i;
for (i = 1; i < argc; i ++)
printf("%s\n", argv[i]);
return 0;
}
Sample output on Unix:
$ ./a.out /*
/bin
/boot
/dev
...
/usr
/var
$ ./a.out /\*
/*
$
Sample output on Windows:
C:\Windows\system32>a.exe C:\*
C:\*
C:\Windows\system32>
If you want to let something else expand the wildcard for your program, use MinGW (MSYS) or Windows Subsystem for Linux (Win 10 1607 and later).
In Windows, wildcards are not supported, thus the error you see.
In UNIX though, what you used, would be correct:
Georgioss-MacBook-Pro:~ gsamaras$ nano main.c
Georgioss-MacBook-Pro:~ gsamaras$ nano fun.h
Georgioss-MacBook-Pro:~ gsamaras$ nano fun.c
Georgioss-MacBook-Pro:~ gsamaras$ gcc -c *.c
Georgioss-MacBook-Pro:~ gsamaras$
I keep getting the error "undefined reference to WInMain#16" when I include SDL2/SDL.h in my C file. It's a simple "Hello" program with the SDL include, and if I remove the SDL include it compiles just fine (as expected).
The problem is I'm new with the compile flags for C (and SDL) and I'm not sure how I link(?) the files together (or if that's necessary). I'm coding using Sublime Text 3 so I'm not sure how you would link SDL as you would when using an IDE.
(D:\CODE\Privata Projekt\C\test.c)
#include <stdio.h>
#include "SDL2/SDL.h"
int main(int argc, char *argv[]) {
printf("hello\n");
return 0;
}
My paths to MinGW and SDL2 is:
C:\MinGW\include\SDL2 (all my sdl header files reside in here too)
C:\MinGW\include\SDL2\bin
C:\MinGW\include\SDL2\lib
C:\MinGW\include\SDL2\share
And I build the program with
gcc test.c -o test
EDIT:
What worked for me was to use these flags, in this exact same order
-lmingw32 -LC:\MinGW\include\SDL2\lib -lSDL2main -lSDL2
You need to link with the library as well. You can do it by passing the correct options on the command line: -L to tell the linker where to find the library, and -l (lowercase L) to tell the linker to link to the library.
Like
> gcc test.c -o test -LC:\MinGW\include\SDL2\lib -lSDL2
(I don't know the name of the library, so change SDL2 to the appropriate name.)
If there is problem running your program due to the loader not finding the SDL2 library, you may have to add another option which tells linker the place of the dynamic library:
> gcc test.c -o test -LC:\MinGW\include\SDL2\lib -Wl,-rpath=C:\MinGW\include\SDL2\lib -lSDL2
I don't know if it's needed or even used on Windows though. You might have to copy the DLL to the directory where the executable is.
I installed on windows curl 7.28.0 from curl-7.28.1-devel-mingw32.zip through minGW console to default directory like:
./config && make && make install
All needed headers (aka curl.h, types.h ...) I see in C:\MinGW\msys\1.0\local\include\curl
libcurl.pc placed in C:\MinGW\msys\1.0\local\lib\pkgconfig\
libcurl.a, libcurl.dll.a and libcurl.la placed in C:\MinGW\msys\1.0\local\lib.
My download_file.c file includes are:
...
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
...
I try to compile the C code with followed command through gcc:
$ gcc -IC:/MinGW/msys/1.0/include/
-IC:/MinGW/msys/1.0/local/include/curl
-IC:/MinGW/msys/1.0/local/lib/pkgconfig
-o download_file download_file.c -llibcurl -lcurl
with absolute path get the same error:
gcc -I/include/
-I/local/include/curl
-I/local/lib/pkgconfig
-o download_file download_file.c -llibcurl -lcurl
But I still get an error:
download_file.c:21:23: fatal error: curl/curl.h: No such file or directory compilation terminated.
row 21 is #include <curl/curl.h>
What I did wrong? Please help.
You have the curl/ directory in the source code, but also in the option.
It seems the option should point out the higher-level directory in which curl/ is, so it should be something like:
-I/local/include/
I think the problem is likely that you give your include paths on the command line in the Win32 path format. This is not the same as the one used by msys (or ultimately Cygwin).
Try these:
$ gcc -I/include/
-I/local/include/curl
-I/local/lib/pkgconfig
...
Hope I got the absolut paths right, but you can check in your msys shell.
What ticked me off was that you use ./config, which wouldn't work from the Command Prompt, but works from the msys shell. So you need to give paths that all the programs in MinGW understand.
Basically, most programs in MinGW only have the concept of a single file system root, like on any unixoid system, while Win32 has multiple (the drive letters). Since the MinGW programs are linked accordingly, you need to give paths that they understand.
Thank you very much to #0xC0000022L and #unwind. By your help I fixed my problem.
0xC0000022L you are right about absolute path
unwind you are right about -I/local/include/ instead -I/local/include/curl
I found other problem: -L/local/lib instead -I/local/lib.
So this is a working command:
gcc -I/include/
-I/local/include
-L/local/lib
-o download_file download_file.c -llibcurl -lcurl
I used to be able to compile C programs, but now I can't:
$ cat helloworld.c
#include <stdio.h>
int main(void)
{
printf("Hello, world!\n");
return 0;
}
$ gcc helloworld.c
helloworld.c:1:19: error: no include path in which to search for stdio.h
Yes, I do have /usr/include/stdio.h . Yes, build-essentials is installed.
This problem began after I modified my ~/.bashrc to run a program installed in my user directory. I know this is what's wrong because if I remove ~/.bashrc, it works.
What environment variable would be shadowing /usr/include as an include path?
The problem was that I had another GCC in my PATH:
$ which gcc
/home/joey/gcc4ti/bin/gcc
When I was trying to compile "Hello World", it was running a compiler for a 68000, not my system compiler :D
I had this in my ~/.bashrc:
export PATH="/home/joey/gcc4ti/bin:$PATH"
Because paths are scanned in order, the gcc in /home/joey/gcc4ti/bin is seen first. I changed it to:
export PATH="$PATH:/home/joey/gcc4ti/bin"