Like Tree2Likes
  • 1 Post By Salem
  • 1 Post By grumpy

Compile C file from command line - to a different path.

This is a discussion on Compile C file from command line - to a different path. within the C Programming forums, part of the General Programming Boards category; Hi, I'm working on windows and I'd like to know how to compile the C file to a different path. ...

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    58

    Compile C file from command line - to a different path.

    Hi,

    I'm working on windows and I'd like to know how to compile the C file to a different path.

    What I mean is :
    the basic compile command is :gcc Hello.c -o Hello_E

    I'd like to create the "hello_E" in a different path.
    Something like this:
    gcc Hello.c -o C:\Program Files\PellesC\C_programs\Exe_files\Hello_E

    thanks in advanced

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    Use a makefile

    Normally, you have two steps

    make build
    to compile the source code, and produce an executable in the build directory.

    make install
    to copy the executable to it's final place (along with anything else that needs doing).

    Presumably, you tried
    gcc Hello.c -o C:\Program Files\PellesC\C_programs\Exe_files\Hello_E
    and it didn't work, in which case you should post your error messages.

    Or maybe you haven't actually tried it yet....
    whiteflags likes this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,436
    Quote Originally Posted by ilans11il View Post
    I'd like to create the "hello_E" in a different path.
    Something like this:
    gcc Hello.c -o C:\Program Files\PellesC\C_programs\Exe_files\Hello_E
    Try turning the backslashes into forward slashes. gcc was originally designed as a compiler for unix-type systems, which separate path elements with forward slashes rather than backslashes. Windows (or, more accurately, the win32 API) treats backslashes as (largely) requirement for forward slashes in paths anyway, even though programs targeting windows rarely use them overtly.

    If you're providing that string in a C program (for example, calling system("gcc Hello.c -o C:\Program Files\PellesC\C_programs\Exe_files\Hello_E")) bear in mind that backslash is an escape character in string literals. The solution there is either to (again) turn the backslashes into forward slashes, or to prefix the backslashes with another backslash (for example, system("gcc Hello.c -o C:/Program Files/PellesC/C_programs/Exe_files/Hello_E"))

    Either way, gcc does not create directories for output files to go into. So if the directory C:\Program Files\PellesC\C_programs\Exe_files does not exist, creation of a file named C:\Program Files\PellesC\C_programs\Exe_files\Hello_E will fail.
    stahta01 likes this.
    Right 98% of the time, and don't care about the other 3%.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Command line compile include libraries
    By Ducky in forum C++ Programming
    Replies: 2
    Last Post: 11-29-2011, 10:44 AM
  2. How to configure MSVC# for command line compile?
    By thetinman in forum C# Programming
    Replies: 2
    Last Post: 12-02-2008, 10:11 AM
  3. how to compile on the command line
    By majoub in forum C Programming
    Replies: 2
    Last Post: 04-23-2005, 07:40 AM
  4. Command Line path
    By snakattak in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 06-27-2002, 10:31 PM
  5. Replies: 4
    Last Post: 11-14-2001, 09:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21