LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Where do I put my .c files? (https://www.linuxquestions.org/questions/programming-9/where-do-i-put-my-c-files-4175501551/)

eatup 04-13-2014 12:15 PM

Where do I put my .c files?
 
May seem trivial, but where do I put my "hello world" .c file in order for the compiler to find it?

eatup 04-13-2014 12:40 PM

nvm I figured it out. I put it in Documents and use the cd command...

Next question, I'm trying to compile a simple helloworld.c in a USB Linux Mint live and get the following error:

stdio.h: No such file or directory

What do I need to do next?

John VV 04-13-2014 12:45 PM

you keep it in the folder FOR YOUR PROJECT

The folder needs to be writable by a normal user
a lot of people use there HOME folder
/home/YourUserName/ProjectName

Quote:

stdio.h: No such file or directory
add that " #include "




WHY !!! the bleep would you move it to the "documents" folder ???????????????

NevemTeve 04-13-2014 11:23 PM

> What do I need to do next?

Install package libc-devel (or similar name, eg libc6-devel, glibc-devel etc).

theNbomr 04-14-2014 11:57 AM

Assuming gcc, you can compile any C source module by simply telling the compiler where the source files is:
Code:

gcc -c /the/path/to/your/file.c
This will compile the C source code, creating the resulting object code in the present working directory. Conventionally, one runs the compiler from the directory where the C source files are, and the object code is then left in that same directory.

Your question, therefore, should be more about what makes sense to your project organization than about getting the C compiler to find the source file(s). Putting C source code in a directory clearly intended for documentation doesn't seem at all appropriate to me (unless you subscribe to the notion that the best documentation is that which is written in C).

That your C compiler cannot find headers from the standard C library makes me think the compiler installation is either broken or incomplete. When gcc is built, it gets a default list of places to look for header files and these are fairly consistent across most builds. If the C header actually exists on your build host, you can always point the compiler to it, by using the -I (minus eye) option with the directory containing the C headers as an argument:
Code:

gcc -c -I /the/path/to/header/files /the/path/to/your/file.c


All times are GMT -5. The time now is 04:13 AM.